Example #1
0
    def save(self,request):
        from django.contrib.gis.geos import Point
        species = self.cleaned_data.get('species_id')
        if species:
            spp = Species.objects.filter(symbol=species)
            if spp:
                new_tree = Tree(species=spp[0])
            else:
                new_tree = Tree()
        else:
            new_tree = Tree()
        add = self.cleaned_data.get('edit_address_street')
        if add:
            new_tree.address_street = add
            new_tree.geocoded_address = add
        city = self.cleaned_data.get('edit_address_city')
        if city:
            new_tree.address_city = city

        zip_ = self.cleaned_data.get('edit_address_zip')
        if zip_:
            new_tree.address_zip = zip_
            
        #import pdb;pdb.set_trace()
        pnt = Point(self.cleaned_data.get('lon'),self.cleaned_data.get('lat'),srid=4326)
        new_tree.geometry = pnt
        n = Neighborhood.objects.filter(geometry__contains=pnt)
        z = ZipCode.objects.filter(geometry__contains=pnt)
        if n: new_tree.neighborhood = n[0]
        else: new_tree.neighborhood = None
        if z: new_tree.zipcode = z[0]
        else: new_tree.zipcode = None
        new_tree.last_updated_by = request.user
        new_tree.save()
        dbh = self.cleaned_data.get('dbh')
        if dbh:
            ts = TreeStatus(
                reported_by = request.user,
                value = dbh,
                key = 'dbh',
                tree = new_tree)
            ts.save()
        return new_tree
Example #2
0
 def save(self,request):
     from django.contrib.gis.geos import Point
     species = self.cleaned_data.get('species_id')
     if species:
         spp = Species.objects.filter(symbol=species)
         if spp:
             new_tree = Tree(species=spp[0])
         else:
             new_tree = Tree()
     else:
         new_tree = Tree()
     address = self.cleaned_data.get('edit_address_street')
     if address:
         new_tree.address_street = address
         new_tree.geocoded_address = address
     city = self.cleaned_data.get('edit_address_city')
     geo_address = self.cleaned_data.get('geocode_address')
     if geo_address:
         new_tree.geocoded_address = geo_address
     if city:
         new_tree.address_city = city
     zip_ = self.cleaned_data.get('edit_address_zip')
     if zip_:
         new_tree.address_zip = zip_
     
     plot_width = self.cleaned_data.get('plot_width')
     plot_width_in = self.cleaned_data.get('plot_width_in')
     if plot_width:
         new_tree.plot_width = float(plot_width)
     if plot_width_in:
         new_tree.plot_width = new_tree.plot_width + (float(plot_width_in) / 12)
     plot_length = self.cleaned_data.get('plot_length')
     plot_length_in = self.cleaned_data.get('plot_length_in')
     if plot_length:
         new_tree.plot_length = float(plot_length)
     if plot_length_in:
         new_tree.plot_length = new_tree.plot_length + (float(plot_length_in) / 12)
     plot_type = self.cleaned_data.get('plot_type')
     if plot_type:
         new_tree.plot_type = plot_type
     power_lines = self.cleaned_data.get('power_lines')
     if power_lines != "":
         new_tree.powerline_conflict_potential = power_lines
     height = self.cleaned_data.get('height')
     if height:
         new_tree.height = height
     canopy_height = self.cleaned_data.get('canopy_height')
     if canopy_height:
         new_tree.canopy_height = canopy_height
     dbh = self.cleaned_data.get('dbh')
     dbh_type = self.cleaned_data.get('dbh_type')
     if dbh:
         if dbh_type == 'circumference':
             dbh = dbh / math.pi
         new_tree.dbh = dbh
     sidewalk_damage = self.cleaned_data.get('sidewalk_damage')
     if sidewalk_damage:
         new_tree.sidewalk_damage = sidewalk_damage
     condition = self.cleaned_data.get('condition')
     if condition:
         new_tree.condition = condition
     canopy_condition = self.cleaned_data.get('canopy_condition')
     if canopy_condition:
         new_tree.canopy_condition = canopy_condition
     
     import_event, created = ImportEvent.objects.get_or_create(file_name='site_add',)
     new_tree.import_event = import_event
     
     pnt = Point(self.cleaned_data.get('lon'),self.cleaned_data.get('lat'),srid=4326)
     new_tree.geometry = pnt
     new_tree.last_updated_by = request.user
     new_tree.save()
     
     return new_tree