6.7-6.9 JLL--实习日志--googleAPI+Heat Map+update修改

Heat Map

Requirement :Google Map - 2nd Heat Map should indicate the Leasable Space - Tsubo
dashnboard 的函数的理解,修改的地方是很少的
1.定义两个热力图的列表,用于传到前端去

availability_heart_map1 = []
    availability_heart_map2 = []

2.获取所有的property的值,把所有的image_path 的属性设置为default_building_pic.jpg然后去f判断PropertyFile里面有(primary_image_flag=”1”)的,这边不会抱错吗?如果没有primary_image这个属性就把image_path,default_building_pic_path两个属性都写成默认的路径

 properties = Property.objects.filter(RecordEndDate="NULL").order_by('NameUnicode')
for item in properties:
        item.image_path = "default_building_pic.jpg"
        if not can_access(item, request):
            properties=properties.exclude(id=item.id)
        else:
            if PropertyFile.objects.filter(Q(Property=item) & Q(Property_File_Type = 'PHO') & Q(RecordEndDate="NULL") & Q(primary_image_flag="1")).first():
                item.image_path = PropertyFile.objects.filter(Q(Property=item) & Q(Property_File_Type = 'PHO') & Q(RecordEndDate="NULL") & Q(primary_image_flag="1")).first().Property_File_Path
            else:
                default_building_pic_path = "default_building_pic.jpg"
                item.image_path = default_building_pic_path

3.获取坐标,这边疑问的是为什么坐标是在avaavailability里面的呢
availability_set 是通过filter方式获得,并且是一个list,里面过滤得条件总是有Property__in=properties,然后是循环,把每一个item_latitude ,item_longitude 的值拿到,拿到之前要判断是不是float类型的,isinstance(a_item.Rent_Warehouse, float)如果是不是,统一变成0

 availability_set = Availability.objects.filter(Q(Property__in=properties)&Q(RecordEndDate='NULL'))
for a_item in availability_set:
        item_latitude = float(a_item.Property.Latitude)
        item_longitude = float(a_item.Property.Longitude)
        if total_setting.environment_setting =='0':
            if isinstance(a_item.Leasable_Space_Tsubo, float):
                item_Leasable_Space_Tsubo = float(a_item.Leasable_Space_Tsubo)
            else: 
                item_Leasable_Space_Tsubo = 0
            if isinstance(a_item.Rent_Warehouse, float): 
                item_Rent_Warehouse = float(a_item.Rent_Warehouse)
            else:
                item_Rent_Warehouse = 0
        else:
            if isinstance(a_item.Leasable_Space_Tsubo, float):
                item_Leasable_Space_Tsubo = float(a_item.Leasable_Space_Tsubo)
            else: 
                item_Leasable_Space_Tsubo = 0
            if isinstance(a_item.Rent_Warehouse, float): 
                item_Rent_Warehouse = float(a_item.Rent_Warehouse)
            else:
                item_Rent_Warehouse = 0

4.把所有的经纬度坐标放在list里面,并且通过json类型的形式进行传输,注意他外面是一个list类型,其中每一个都是字典类型的,每一个字典类型里面有三个键值对!!!这个是Json的格式中的数组形式

availability_heart_map1.append({"lng":item_longitude,"lat":item_latitude,"count":item_Leasable_Space_Tsubo})
        availability_heart_map2.append({"lng":item_longitude, "lat":item_latitude, "count":item_Rent_Warehouse})

5.通过json 类型传输,dumps含义是将Json对象输入到一个python_object中,如果python_object是文件,则dump到文件中;如果是对象,则dump到内存中。这是序列化。对象转换为字节序列的过程称为对象的序列化。
序列化
序列化的简单解释
对象的序列化主要有两种用途:
  1) 把对象的字节序列永久地保存到硬盘上,通常存放在一个文件中;
  2) 在网络上传送对象的字节序列。
  在很多应用中,需要对某些对象进行序列化,让它们离开内存空间,入住物理硬盘,以便长期保存。比如最常见的是Web服务器中的Session对象,当有 10万用户并发访问,就有可能出现10万个Session对象,内存可能吃不消,于是Web容器就会把一些seesion先序列化到硬盘中,等要用了,再把保存在硬盘中的对象还原到内存中。

  当两个进程在进行远程通信时,彼此可以发送各种类型的数据。无论是何种类型的数据,都会以二进制序列的形式在网络上传送。发送方需要把这个Java对象转换为字节序列,才能在网络上传送;接收方则需要把字节序列再恢复为Java对象。

availability_heart_map1 = simplejson.dumps(availability_heart_map1,ensure_ascii=False)
    availability_heart_map2 = simplejson.dumps(availability_heart_map2,ensure_ascii=False)

6.获得Tenant,availability,PropertyFile的数量,用于在左边上的所数量的显示

availability_count = availability_set.count()
    tenant_count = Tenant.objects.filter(Q(Property__in=properties)&Q(RecordEndDate='NULL')).count()
    property_count = properties.count()
    file_count = PropertyFile.objects.filter(Q(Property__in=properties)&Q(RecordEndDate='NULL')).count()

原始版的代码

@login_required      
def dashboard(request):
    properties = Property.objects.filter(RecordEndDate="NULL").order_by('NameUnicode')
    availability_heart_map1 = []
    availability_heart_map2 = []
    for item in properties:
        item.image_path = "default_building_pic.jpg"
        if not can_access(item, request):
            properties=properties.exclude(id=item.id)
        else:
            if PropertyFile.objects.filter(Q(Property=item) & Q(Property_File_Type = 'PHO') & Q(RecordEndDate="NULL") & Q(primary_image_flag="1")).first():
                item.image_path = PropertyFile.objects.filter(Q(Property=item) & Q(Property_File_Type = 'PHO') & Q(RecordEndDate="NULL") & Q(primary_image_flag="1")).first().Property_File_Path
            else:
                default_building_pic_path = "default_building_pic.jpg"
                item.image_path = default_building_pic_path
    availability_set = Availability.objects.filter(Q(Property__in=properties)&Q(RecordEndDate='NULL'))
    for a_item in availability_set:
        item_latitude = float(a_item.Property.Latitude)
        item_longitude = float(a_item.Property.Longitude)
        if total_setting.environment_setting =='0':
            if isinstance(a_item.Leasable_Space_Tsubo, float):
                item_Leasable_Space_Tsubo = float(a_item.Leasable_Space_Tsubo)
            else: 
                item_Leasable_Space_Tsubo = 0
            if isinstance(a_item.Rent_Warehouse, float): 
                item_Rent_Warehouse = float(a_item.Rent_Warehouse)
            else:
                item_Rent_Warehouse = 0
        else:
            if isinstance(a_item.Leasable_Space_Tsubo, float):
                item_Leasable_Space_Tsubo = float(a_item.Leasable_Space_Tsubo)
            else: 
                item_Leasable_Space_Tsubo = 0
            if isinstance(a_item.Rent_Warehouse, float): 
                item_Rent_Warehouse = float(a_item.Rent_Warehouse)
            else:
                item_Rent_Warehouse = 0
            #Rent_Warehouse 
        availability_heart_map1.append({"lng":item_longitude,"lat":item_latitude,"count":item_Leasable_Space_Tsubo})
        availability_heart_map2.append({"lng":item_longitude, "lat":item_latitude, "count":item_Rent_Warehouse})
    availability_heart_map1 = simplejson.dumps(availability_heart_map1,ensure_ascii=False)
    availability_heart_map2 = simplejson.dumps(availability_heart_map2,ensure_ascii=False)
    availability_count = availability_set.count()
    tenant_count = Tenant.objects.filter(Q(Property__in=properties)&Q(RecordEndDate='NULL')).count()
    property_count = properties.count()
    file_count = PropertyFile.objects.filter(Q(Property__in=properties)&Q(RecordEndDate='NULL')).count()
    return render_to_response('#.html', {
        'properties': properties, 
        'property_count': property_count,
        'availability_count':availability_count,
        'tenant_count':tenant_count,
        'file_count':file_count, 
        'availability_heart_map1': availability_heart_map1,
        'availability_heart_map2': availability_heart_map2,
    }, context_instance = RequestContext(request))

搜索路径

nano /home/ubuntu/.ssh/known_hosts
标准流程:pull,push 前后都是需要add +commit!!!!!
执行完 makemigrations 以后还需要一次的add +commit

add +commit ------git pull -------add +commit ---------git push ----add + commit 

google 搜索框

1.a.setattribute() is not a function
a.getattribute is not a function google maps 这是一个很常见的问题,因为你最后加了一个属性value

  var city = document.getElementById("cityName").value;

常规的是问题出现在
2. function onlick()
3. initAutocomplete()
google Map Api 的地址
错误的代码

   <script type="text/javascript">
    $('#setPosition2').click(function(e){
       e.preventDefault();
        var city = document.getElementById("cityName").value;
          if(city!= ""){
              var searchBox = new google.maps.places.SearchBox(city);
                //map.controls[google.maps.ControlPosition.TOP_LEFT].push(city);
              function initAutocomplete() {
        var map = new google.maps.Map(document.getElementById('mapContainer'), {
          center: {lat: -33.8688, lng: 151.2195},
          zoom: 18,
          mapTypeId: 'roadmap'
        });

        map.addListener('bounds_changed', function() {
          searchBox.setBounds(map.getBounds());
        });
         searchBox.addListener('places_changed', function() {
          var places = searchBox.getPlaces();
          if (places.length == 0) {
            return;
          }
         });

          };
    }
    });

</script>

正确的写法,marker 是用来做标记的函数, marker.addListener是给marker 增加了一个事件,input 是输入框里面的值

    var marker = new google.maps.Marker({
               position: {lat: {{ item.Latitude }}, lng: {{ item.Longitude }}},
               label: {text: '{{ item.NameUnicode }}', fontWeight: 'bold', color: 'red', fontFamily: 'Arial',fontSize:'12px' },
               title: '{{ item.NameUnicode }}',
               icon: image,
               shape: shape
            });

            marker.addListener('click', function() {
                var contentString = '<div style="margin:0;line-height:20px;padding:0px;">' + 
                    '<div class="col-xs-8">'+
                    '{{ item.NameUnicode}}<br/>{{ ui_setting.Address }}:{{ item.Province }} {{ item.City }} {{ item.StreetAddress }}<br/>{{ ui_setting.YearBuilt }}:{{ item.YearBuilt }}<br/>' +
                    '<a href="/property/view_detail/{{ item.id }}">{{ ui_setting.ViewPropertyDetail }}</a>' + 
                    '</div>' + 
                    '<div class="col-xs-4">'+
                    '<img src="../static/upload/{{ item.image_path }}" alt="" style="float:right;zoom:1;overflow:hidden;width:100px;height:80px;margin-left:3px;"/>' +
                    '</div>' +
                    '</div>';
                new google.maps.InfoWindow({
                  content: contentString,
                  maxWidth: 400,
                  position: {lat: {{ item.Latitude }}, lng: {{ item.Longitude }}}
                }).open(gmap1);
            });
            marker.setMap(gmap1);
            markers.push(marker);
        {% endfor %}


        var input = document.getElementById('cityName');
        var searchBox = new google.maps.places.SearchBox(input);
        gmap1.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
        gmap1.addListener('bounds_changed', function() {
          searchBox.setBounds(gmap1.getBounds());
        });

        searchBox.addListener('places_changed', function() {
          var places = searchBox.getPlaces();

          if (places.length == 0) {
            return;
          }

          // Clear out the old markers.
          //markers.forEach(function(marker) {
            //marker.setMap(null);
          //});
         var bounds = new google.maps.LatLngBounds();
          places.forEach(function(place) {
            if (!place.geometry) {
              console.log("Returned place contains no geometry");
              return;
            }


            if (place.geometry.viewport) {
              // Only geocodes have viewport.
              bounds.union(place.geometry.viewport);
            } else {
              bounds.extend(place.geometry.location);
            }
          });
            gmap1.fitBounds(bounds);
        });

* Allow user change file type after upload #163 *
1.js 出现了Cannot read property 'setAttribute' of null的问题,原因是getElementById(“abc”)后面必须是双引号!!!var link= document.getElementById("abc");

2写的下拉菜单没有办法得到对应的变化的值,以前的方式把form的形式增加到框那边,现在的问题是通过js 怎么取到变化的???

不工作的原因是因为$(“#a”).click,在上面有很多个循环的id=a 东西没有办法知道对应的是哪个,所以不工作,js 里面id 必须是唯一的!

<script type="text/javascript">
$(function() {
                          $("#a").click(function(e){
                            e.preventDefault();

                            var url = "/property/change_filetype/{{ document_item.id }}/?a='happ'"
                            url = encodeURI(url);
                            var link = document.getElementById("a"); 
                            link.setAttribute('href',url)
                             window.location.href=url
                            //href="/property/change_filetype/{{ document_item.id }}/?a='happ'"
                            //document.getElementById()
                            //var e = document.getElementById("filter-display");
                            //var strUser = e.options[e.selectedIndex].value;
                        })
     });
</script!> 
file_type_origin = request.POST['property_form_type_choice']

var e = document.getElementById(“ddlViewBy”);
var strUser = e.options[e.selectedIndex].value;

var link= document.getElementById(“abc”);

现在是下拉框里面的值取不到阿??
错误:Cannot read property 'innerHTML' of undefined
总是显示第一个值,下拉框里面的第一个值 不是变化的



问题出现真的是很多
'instance' is an invalid keyword argument for this function

property_instance = property_file_instance.Property
form_1 = PropertyFile(instance=property_instance)

现在的问题是跑通了但是没有办法正常工作,还是没有办法变化文件类型!没有抱错但是我觉得没有办法修改数据库里面的属性值!



4. 理解add_files 函数的运行操作4.1 `
4.1 通过form, UploadFileFormChoice表单形式传过来的数据需要验证form表单的有效性,

def add_files(request, property_id):
if request.method == ‘POST’:
form = UploadFileFormChoice(request.POST, request.FILES)
if form.is_valid():






4.完整版edit_files代码如下:

@login_required
def add_files(request, property_id):
if request.method == ‘POST’:
form = UploadFileFormChoice(request.POST, request.FILES) # get post
if form.is_valid():
if form_setting.form_sets == policy_jp_ind:
file_type_origin = request.POST[‘property_form_type_choice’]
if views.containsAnyFromList(file_type_origin, [‘FLP’,’MAP’]):
file_type = file_type_origin[-3:]
file_type_subpart = file_type_origin[0]
else:
file_type = file_type_origin
file_type_subpart = ”
else:
file_type = request.POST[‘property_form_type_choices’]
file_type_subpart = ”
now_time = datetime.datetime.now()
yesterdaytime = now_time + datetime.timedelta(days=-1)
userid = User.objects.filter(id=request.user.id).first().id
#???
property_instance=Property.objects.all().first()
user_role_instance = UserRole.objects.filter(user=request.user).first().userRole
propertyfiles_count = PropertyFile.objects.filter(Q(Property_File_Timestamp__gt=yesterdaytime)&Q(Q(UploadBy=userid)|Q(DeleteBy=userid))).count()
primary_image_instance=PropertyFile.objects.filter(Q(Property=property_instance) & Q(Property_File_Type = ‘PHO’) & Q(RecordEndDate=”NULL”) & Q(primary_image_flag=”1”))
#primary_image_instance primary image exist ?
if(propertyfiles_count < 500):
if request.FILES.getlist(‘file’):
for file_item in request.FILES.getlist(‘file’):#???
property_instance = get_object_or_404(Property,pk=int(property_id))
file_name_original = file_item.name
file_name_extension = file_item.name.split(‘.’)[-1].lower()
#file_name 拼接实现
file_name = file_type + ‘’ + property_id + ‘’ + datetime.datetime.now().strftime(“%Y_%m_%d_%H_%M_%S_%f”) + ‘.’ + file_name_extension
file_item.name = file_name
record_start_date=now_time
if primary_image_instance:#primary image exist! new import files will be set 0 ,primary image no exist! the new imported will be set 0
image_flag = ‘0’
elif file_type == ‘PHO’:
image_flag = ‘1’
else:
image_flag =’0’
property_file = PropertyFile(Property=property_instance,
Property_File=file_item,
Property_File_Path=file_name,
Property_File_Name = file_name_original,
Property_File_Type = file_type,
Property_File_Type_Subpart = file_type_subpart,
Property_File_Subpart = file_name_extension,
RecordStartDate=record_start_date,
view_flag = user_role_instance,
control_flag = user_role_instance,
UploadBy = userid,
primary_image_flag = image_flag)
property_file.save()
if PropertyFile.objects.filter(Q(Property=property_instance) & Q(Property_File_Type = ‘PHO’) & Q(RecordEndDate=”NULL”) & Q(primary_image_flag=”1”)).first():
property_instance.image_path = PropertyFile.objects.filter(Q(Property=property_instance) & Q(Property_File_Type = ‘PHO’) & Q(RecordEndDate=”NULL”) & Q(primary_image_flag=”1”)).first().Property_File_Path
property_instance.save()
views.write_operation_log(property_file, “Add”, request)
return HttpResponseRedirect(“/property/view_detail/%s?message=success&item=file_upload” % property_id)
else:
return HttpResponseRedirect(“/property/view_detail/%s?message=fail&item=file_upload” % property_id)
else:
return HttpResponseRedirect(“/property/view_detail/%s?message=fail&item=file_upload” % property_id)
else:
return HttpResponseRedirect(“/property/view_detail/%s?message=fail&item=file_upload” % property_id)

现在的问题是需要看一下edit 里面的代码,修改变量的时候怎么样得到一个新的对象!现在的感觉就是改不动这个对象,单单一个save()还是解决不了,怎么在的Django 中更新数据的操作,现在的办法是去看之前的update 的操作  ,现在的版本是下面的这个,还是没有办法实现!!为什么??快疯了快疯了


5.下面这个版本就是我现在的view_proprerty里面的函数

@login_required
def change_filetype(request, file_id):
a =request.GET.get(‘a’)
a_origin=”
if a ==’Photo’:
a_origin=’Pic’
elif a == ‘Property Profile’:
a_origin=’PRF’
elif a ==’Floor Plan’:
a_origin=’FLP’
elif a == ‘Map’:
a_origin=’MAP’
property_file_instance = get_object_or_404(PropertyFile,pk=int(file_id),RecordEndDate=”NULL”)
property_instance = property_file_instance.Property
property_id = property_instance.id
if not can_control(property_file_instance,request):
return views.page_not_found(request)
else:
message_for_add_result = “null”
document_1 = PropertyFile.objects.filter(Q(Property=property_instance)&Q(RecordEndDate=’NULL’)).first()
if form_setting.form_sets == policy_jp_ind:
if a_origin in [‘FLP’,’MAP’]:
document_1.file_type=a_origin
document_1.file_type_subpart=a_origin[0]
else:
document_1.update.file_type=a_origin
document_1.update.file_type_subpart=”
document_1.save()
property_instance = property_file_instance.Property
documents_2 = PropertyFile.objects.filter(Q(Property=property_instance)& Q(RecordEndDate=”NULL”))
file_type_filter = [‘PRF’,’FLP’,’PHO’,’MAP’]
for document_item in documents_2:
print ‘11’,document_item.Property_File_Type,file_id
return render_to_response(ui_sets[‘search_property_files’],{‘documents’:documents_2,’file_type_filter’:file_type_filter},context_instance = RequestContext(request))
“`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值