예제 #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
예제 #2
0
파일: forms.py 프로젝트: jlivni/OpenTreeMap
    def save(self,request):
        from django.contrib.gis.geos import Point

        plot = Plot()
        plot.data_owner = request.user

        address = self.cleaned_data.get('edit_address_street')
        if address:
            plot.address_street = address
            plot.geocoded_address = address
        city = self.cleaned_data.get('edit_address_city')
        geo_address = self.cleaned_data.get('geocode_address')
        if geo_address:
            plot.geocoded_address = geo_address
        if city:
            plot.address_city = city
        zip_ = self.cleaned_data.get('edit_address_zip')
        if zip_:
            plot.address_zip = zip_
        
        plot_width = self.cleaned_data.get('plot_width')
        plot_width_in = self.cleaned_data.get('plot_width_in')
        if plot_width:
            plot.width = float(plot_width)
        if plot_width_in:
            plot.width = 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:
            plot.length = float(plot_length)
        if plot_length_in:
            plot.length = plot.length + (float(plot_length_in) / 12)
        plot_type = self.cleaned_data.get('plot_type')
        if plot_type:
            plot.type = plot_type
        power_lines = self.cleaned_data.get('power_lines')
        if power_lines != "":
            plot.powerline_conflict_potential = power_lines
        sidewalk_damage = self.cleaned_data.get('sidewalk_damage')
        if sidewalk_damage:
            plot.sidewalk_damage = sidewalk_damage

        import_event, created = ImportEvent.objects.get_or_create(file_name='site_add',)
        plot.import_event = import_event

        pnt = Point(self.cleaned_data.get('lon'),self.cleaned_data.get('lat'),srid=4326)
        plot.geometry = pnt
        plot.last_updated_by = request.user
        plot.save()

        species = self.cleaned_data.get('species_id')
        height = self.cleaned_data.get('height')
        canopy_height = self.cleaned_data.get('canopy_height')
        dbh = self.cleaned_data.get('dbh')
        crown_width = self.cleaned_data.get('crown_width')
        dbh_type = self.cleaned_data.get('dbh_type')
        condition = self.cleaned_data.get('condition')
        canopy_condition = self.cleaned_data.get('canopy_condition')

        new_tree = Tree()
        if species:
            spp = Species.objects.filter(symbol=species)
            if spp:
              new_tree.species=spp[0]

        if crown_width:
            new_tree.crown_width = crown_width
        if height:
            new_tree.height = height
        if canopy_height:
            new_tree.canopy_height = canopy_height
        if dbh:
            if dbh_type == 'circumference':
                dbh = dbh / math.pi
            new_tree.dbh = dbh
        if condition:
            new_tree.condition = condition
        if canopy_condition:
            new_tree.canopy_condition = canopy_condition
        
        new_tree.import_event = import_event            
        new_tree.last_updated_by = request.user
        new_tree.plot = plot
        new_tree.save()
        #print new_tree.__dict__
        fauna = self.cleaned_data.get('fauna')
        if fauna:
            print 'fauna',fauna
            fauna_dict = dict(Choices().get_field_choices('fauna'))
            for f in fauna:
              fauna = TreeFauna()
              fauna.reported_by = request.user
              fauna.key = f
              fauna.value = datetime.now()
              fauna.fauna = fauna_dict[f] # or random string
              fauna.tree = new_tree
              fauna.save()
        
        return plot
예제 #3
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
예제 #4
0
    def save(self,request):
        from django.contrib.gis.geos import Point

        plot = Plot()
        plot.data_owner = request.user

        address = self.cleaned_data.get('edit_address_street')
        if address:
            plot.address_street = address
            plot.geocoded_address = address
        city = self.cleaned_data.get('edit_address_city')
        geo_address = self.cleaned_data.get('geocode_address')
        if geo_address:
            plot.geocoded_address = geo_address
        if city:
            plot.address_city = city
        zip_ = self.cleaned_data.get('edit_address_zip')
        if zip_:
            plot.address_zip = zip_
        
        plot_width = self.cleaned_data.get('plot_width')
        plot_width_in = self.cleaned_data.get('plot_width_in')
        if plot_width:
            plot.width = float(plot_width)
        if plot_width_in:
            plot.width = 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:
            plot.length = float(plot_length)
        if plot_length_in:
            plot.length = plot.length + (float(plot_length_in) / 12)
        plot_type = self.cleaned_data.get('plot_type')
        if plot_type:
            plot.type = plot_type
        power_lines = self.cleaned_data.get('power_lines')
        if power_lines != "":
            plot.powerline_conflict_potential = power_lines
        sidewalk_damage = self.cleaned_data.get('sidewalk_damage')
        if sidewalk_damage:
            plot.sidewalk_damage = sidewalk_damage
        owner_additional_id = self.cleaned_data.get('owner_additional_id')
        if owner_additional_id:
            plot.owner_additional_id = owner_additional_id

        import_event, created = ImportEvent.objects.get_or_create(file_name='site_add',)
        plot.import_event = import_event

        pnt = Point(self.cleaned_data.get('lon'),self.cleaned_data.get('lat'),srid=4326)
        plot.geometry = pnt
        plot.last_updated_by = request.user
        plot.save()

        species = self.cleaned_data.get('species_id')
        species_other1 = self.cleaned_data.get('species_other1')
        species_other2 = self.cleaned_data.get('species_other2')
        height = self.cleaned_data.get('height')
        canopy_height = self.cleaned_data.get('canopy_height')
        dbh = self.cleaned_data.get('dbh')
        dbh_type = self.cleaned_data.get('dbh_type')
        condition = self.cleaned_data.get('condition')
        canopy_condition = self.cleaned_data.get('canopy_condition')

        #TODO: fix this
        pests = self.cleaned_data.get('pests')
        if species or height or canopy_height or dbh or \
           condition or canopy_condition or pests:
           # print species, height, canopy_height, dbh, condition, canopy_condition
            if species:
                spp = Species.objects.filter(id=species)
                if spp:
                    new_tree = Tree(species=spp[0])
                else:
                    new_tree = Tree()
            else:
                new_tree = Tree()

            new_tree.pests = pests

            if species_other1:
                new_tree.species_other1 = species_other1
            if species_other2:
                new_tree.species_other2 = species_other2
            if height:
                new_tree.height = height
            if canopy_height:
                new_tree.canopy_height = canopy_height
            if dbh:
                if dbh_type == 'circumference':
                    new_tree.dbh = dbh / math.pi
                else:
                    new_tree.dbh = dbh
            if condition:
                new_tree.condition = condition
            if canopy_condition:
                new_tree.canopy_condition = canopy_condition
            
            new_tree.import_event = import_event            
            new_tree.last_updated_by = request.user
            new_tree.plot = plot
            new_tree.save()
            #print new_tree.__dict__
        
        return plot
예제 #5
0
    def save(self, request):
        from django.contrib.gis.geos import Point

        plot = Plot()
        plot.data_owner = request.user

        address = self.cleaned_data.get('edit_address_street')
        if address:
            plot.address_street = address
            plot.geocoded_address = address
        city = self.cleaned_data.get('edit_address_city')
        geo_address = self.cleaned_data.get('geocode_address')
        if geo_address:
            plot.geocoded_address = geo_address
        if city:
            plot.address_city = city
        zip_ = self.cleaned_data.get('edit_address_zip')
        if zip_:
            plot.address_zip = zip_

        plot_width = self.cleaned_data.get('plot_width')
        plot_width_in = self.cleaned_data.get('plot_width_in')
        if plot_width:
            plot.width = float(plot_width)
        if plot_width_in:
            plot.width = 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:
            plot.length = float(plot_length)
        if plot_length_in:
            plot.length = plot.length + (float(plot_length_in) / 12)
        plot_type = self.cleaned_data.get('plot_type')
        if plot_type:
            plot.type = plot_type
        power_lines = self.cleaned_data.get('power_lines')
        if power_lines != "":
            plot.powerline_conflict_potential = power_lines
        sidewalk_damage = self.cleaned_data.get('sidewalk_damage')
        if sidewalk_damage:
            plot.sidewalk_damage = sidewalk_damage
        owner_additional_id = self.cleaned_data.get('owner_additional_id')
        if owner_additional_id:
            plot.owner_additional_id = owner_additional_id

        import_event, created = ImportEvent.objects.get_or_create(
            file_name='site_add', )
        plot.import_event = import_event

        pnt = Point(self.cleaned_data.get('lon'),
                    self.cleaned_data.get('lat'),
                    srid=4326)
        plot.geometry = pnt
        plot.last_updated_by = request.user
        plot.save()

        species = self.cleaned_data.get('species_id')
        species_other1 = self.cleaned_data.get('species_other1')
        species_other2 = self.cleaned_data.get('species_other2')
        height = self.cleaned_data.get('height')
        canopy_height = self.cleaned_data.get('canopy_height')
        dbh = self.cleaned_data.get('dbh')
        dbh_type = self.cleaned_data.get('dbh_type')
        condition = self.cleaned_data.get('condition')
        canopy_condition = self.cleaned_data.get('canopy_condition')

        #TODO: fix this
        pests = self.cleaned_data.get('pests')
        if species or height or canopy_height or dbh or \
           condition or canopy_condition or pests:
            # print species, height, canopy_height, dbh, condition, canopy_condition
            if species:
                spp = Species.objects.filter(id=species)
                if spp:
                    new_tree = Tree(species=spp[0])
                else:
                    new_tree = Tree()
            else:
                new_tree = Tree()

            new_tree.pests = pests

            if species_other1:
                new_tree.species_other1 = species_other1
            if species_other2:
                new_tree.species_other2 = species_other2
            if height:
                new_tree.height = height
            if canopy_height:
                new_tree.canopy_height = canopy_height
            if dbh:
                if dbh_type == 'circumference':
                    new_tree.dbh = dbh / math.pi
                else:
                    new_tree.dbh = dbh
            if condition:
                new_tree.condition = condition
            if canopy_condition:
                new_tree.canopy_condition = canopy_condition

            new_tree.import_event = import_event
            new_tree.last_updated_by = request.user
            new_tree.plot = plot
            new_tree.save()
            #print new_tree.__dict__

        return plot