コード例 #1
0
 def name_tag(self):
     """
     sometimes we only need the city name as a tag
     (e.g. energy data uploads)
     vs the standard tag of cityname_state
     """
     return to_tag(str(self.name))
コード例 #2
0
ファイル: models.py プロジェクト: codeforbtv/green-rental
 def name_tag(self):
     """
     sometimes we only need the city name as a tag
     (e.g. energy data uploads)
     vs the standard tag of cityname_state
     """
     return to_tag(str(self.name))
コード例 #3
0
    def create_tag(self, force=False):
        if (not self.tag and (self.address or self.number)) or force:
            #update stored tag so it also exists
            self.tag = to_tag(self.unit_address())
            self.save()

        #either it exists or it won't
        return self.tag
コード例 #4
0
    def create_tag(self, force=False):
        if ((not self.tag) and self.address) or force:
            #update stored tag so it also exists
            self.tag = to_tag(self.address)
            self.save()

        #either it exists or it won't
        return self.tag
コード例 #5
0
ファイル: models.py プロジェクト: codeforbtv/green-rental
 def create_tag(self, force=False):
     if (not self.tag and (self.address or self.number)) or force:
         #update stored tag so it also exists
         self.tag = to_tag(self.unit_address())
         self.save()
         
     #either it exists or it won't
     return self.tag
コード例 #6
0
ファイル: models.py プロジェクト: codeforbtv/green-rental
 def create_tag(self, force=False):
     if ((not self.tag) and self.address) or force:
         #update stored tag so it also exists
         self.tag = to_tag(self.address)
         self.save()
         
     #either it exists or it won't
     return self.tag
コード例 #7
0
def find_by_city_state(city_name, city_state):
    """
    check for existing...
    """
    city = None
    city_tag = to_tag("%s_%s" % (city_name, city_state))
    city_options = City.objects.filter(tag=city_tag)
    
    #print "Number of cities available: %s" % len(city_options)
    #if not len(city_options):
    #    (city, error) = search_city("%s, %s" % (city_name, city_state), make)
    if len(city_options):    
        city = city_options[0]
    return city
コード例 #8
0
ファイル: models.py プロジェクト: codeforbtv/green-rental
class City(models.Model):
    """
    Details to define a specific City
    """
    #Name of the municipality providing this feed.
    #For example 'San Francisco' or 'Multnomah County'
    #municipality_name = models.CharField(max_length=20)

    name = models.CharField(max_length=200)

    #URL of the publishing municipality's website
    url = models.CharField(max_length=100, blank=True)

    #this is what we'll use to look up a city:
    tag = models.CharField(max_length=200,
                           unique=True,
                           default=to_tag(str(name)))

    #in case we want to represent other types of municipalities, not just cities
    type = models.CharField(max_length=50, default="city")

    #State where the property is located.
    #In the U.S. this should be the two-letter code for the state
    state = models.CharField(max_length=2)

    #where to center the map when choosing this location
    latitude = models.FloatField()
    longitude = models.FloatField()

    added = models.DateTimeField('date published', auto_now_add=True)
    updated = models.DateTimeField('date updated', auto_now=True)

    def name_tag(self):
        """
        sometimes we only need the city name as a tag
        (e.g. energy data uploads)
        vs the standard tag of cityname_state
        """
        return to_tag(str(self.name))
コード例 #9
0
def make_city(result):
    """
    assume we've already checked for existing here...
    part of that check should have involved a call to address_search...
    no need to duplicate that here...
    we just need to process the result
    """

    error = None
    city = None
    
    city_tag = to_tag("%s_%s" % (result['city'], result['state']))

    city = City()
    city.name = result['city']
    city.tag = city_tag
    city.state = result['state']

    city.latitude = result['lat']
    city.longitude = result['lng']

    city.save()

    return (city, error)
コード例 #10
0
                        nunit = Unit()
                        nunit.building = building
                        nunit.number = unit
                        #TODO: DON'T DO THIS!
                        #nunit.address = building_match.address + ", " + unit
                        #nunit.address = building.address + ", " + unit
                        nunit.save()

            else:
                #didn't match a unit number... just update the address
                building.address = street


            city_part = city_part.strip()
            print city_part
            if to_tag(city_part) != to_tag(city.name):
                print "WARNING: city does not match: %s != %s" % (city.name, city_part)
                print to_tag(city_part), str(city.tag)
                mismatched += 1

            print state_zip
            state_zip = state_zip.strip()
            parts = state_zip.split(' ')
            if len(parts) == 2:
                state, postal_code = parts
            elif len(parts) == 1:
                state = parts[0]
                postal_code = ''
            else:
                state = ''
                postal_code = ''
コード例 #11
0
units = Unit.objects.all()
print len(units)
print units.count()
count = 0
#for unit in units[:10]:
for unit in units:
#for unit in units[15320:]:
    #I think this should happen first, since tag may use it if it exists
    auto_addy = unit.building.address + ", " + unit.number
    if unit.address == auto_addy:
        print 
        print "Clearing %04d: %s, %s" % (count, unit.address, unit.number)
        #clear it out
        unit.address = ''
        unit.save()
                
    if unit.number:
        print 
        print "Starting %04d: %s, %s" % (count, unit.number, unit.building.address)

        if unit.tag != to_tag(unit.number):
            print "%s != %s" % (unit.tag, unit.number)

            #unit.tag = to_tag(unit.number)
            unit.create_tag(force=True)

            unit.save()

    count += 1
        
コード例 #12
0
                    if not matched:
                        nunit = Unit()
                        nunit.building = building
                        nunit.number = unit
                        #TODO: DON'T DO THIS!
                        #nunit.address = building_match.address + ", " + unit
                        #nunit.address = building.address + ", " + unit
                        nunit.save()

            else:
                #didn't match a unit number... just update the address
                building.address = street

            city_part = city_part.strip()
            print city_part
            if to_tag(city_part) != to_tag(city.name):
                print "WARNING: city does not match: %s != %s" % (city.name,
                                                                  city_part)
                print to_tag(city_part), str(city.tag)
                mismatched += 1

            print state_zip
            state_zip = state_zip.strip()
            parts = state_zip.split(' ')
            if len(parts) == 2:
                state, postal_code = parts
            elif len(parts) == 1:
                state = parts[0]
                postal_code = ''
            else:
                state = ''
コード例 #13
0
units = Unit.objects.all()
print len(units)
print units.count()
count = 0
#for unit in units[:10]:
for unit in units:
    #for unit in units[15320:]:
    #I think this should happen first, since tag may use it if it exists
    auto_addy = unit.building.address + ", " + unit.number
    if unit.address == auto_addy:
        print
        print "Clearing %04d: %s, %s" % (count, unit.address, unit.number)
        #clear it out
        unit.address = ''
        unit.save()

    if unit.number:
        print
        print "Starting %04d: %s, %s" % (count, unit.number,
                                         unit.building.address)

        if unit.tag != to_tag(unit.number):
            print "%s != %s" % (unit.tag, unit.number)

            #unit.tag = to_tag(unit.number)
            unit.create_tag(force=True)

            unit.save()

    count += 1