From 518b2d618bc10f93cfa44a83715593b8358eb9ce Mon Sep 17 00:00:00 2001 From: luxagraf Date: Fri, 23 May 2014 11:28:10 -0400 Subject: minor refactor to adoipt pep8 and pyflakes coding styles and clean up some cruft that's been hangin round for years --- app/birds/aba_importer.py | 13 ++++++------- app/birds/admin.py | 8 +++++--- app/birds/models.py | 28 +++++++++++++++------------- 3 files changed, 26 insertions(+), 23 deletions(-) (limited to 'app/birds') diff --git a/app/birds/aba_importer.py b/app/birds/aba_importer.py index e5df528..93f5bef 100644 --- a/app/birds/aba_importer.py +++ b/app/birds/aba_importer.py @@ -1,17 +1,16 @@ for row_index in range(sheet.nrows): - if sheet.cell(row_index,0).value != '': + if sheet.cell(row_index, 0).value != '': sci = sheet.cell(row_index, 0).value.split("(")[1].split(")")[0] bc = BirdClass.objects.get(scientific_name__exact=sci) common_name = sheet.cell(row_index, 1).value sci_name = sheet.cell(row_index, 2).value code = int(sheet.cell(row_index, 3).value) bclass = bc - #create bird here + # create bird here b, created = Bird.objects.get_or_create( - common_name = common_name, - scientific_name = sci_name, - code = code, - bird_class = bc + common_name=common_name, + scientific_name=sci_name, + code=code, + bird_class=bc ) print(b) - diff --git a/app/birds/admin.py b/app/birds/admin.py index a9d60b0..e40baab 100644 --- a/app/birds/admin.py +++ b/app/birds/admin.py @@ -6,14 +6,15 @@ from birds.models import BirdSighting, BirdClass, Bird class BirdClassAdmin(admin.ModelAdmin): list_display = ('common_name', 'scientific_name',) + class BirdAdmin(admin.ModelAdmin): - list_display = ('pk','common_name', 'scientific_name','code','bird_class') + list_display = ('pk', 'common_name', 'scientific_name', 'code', 'bird_class') class BirdSightingAdmin(OSMGeoAdmin): - list_display = ('bird', 'location',) + list_display = ('bird', 'location') list_filter = ('location',) - #options for OSM map Using custom ESRI topo map + # options for OSM map Using custom ESRI topo map default_lon = -9285175 default_lat = 4025046 default_zoom = 6 @@ -22,6 +23,7 @@ class BirdSightingAdmin(OSMGeoAdmin): map_width = 700 map_height = 425 map_template = 'gis/admin/osm.html' + admin.site.register(BirdSighting, BirdSightingAdmin) admin.site.register(BirdClass, BirdClassAdmin) admin.site.register(Bird, BirdAdmin) diff --git a/app/birds/models.py b/app/birds/models.py index 3dd0add..3fb0c0f 100644 --- a/app/birds/models.py +++ b/app/birds/models.py @@ -2,18 +2,19 @@ import datetime from django.contrib.gis.db import models from locations.models import Location + def get_upload_path(self, filename): - return "images/bird-images/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + return "images/bird-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) -#from http://aba.org/checklist/codes.html +# from http://aba.org/checklist/codes.html ABA_CODES = ( - (1, 'regular occurring - common'), - (2, 'regular occurring - less common'), - (3, 'rare'), - (4, 'casual'), - (5, 'accidental'), - (6, 'Cannot be found'), - ) + (1, 'regular occurring - common'), + (2, 'regular occurring - less common'), + (3, 'rare'), + (4, 'casual'), + (5, 'accidental'), + (6, 'Cannot be found'), +) class BirdClass(models.Model): @@ -22,10 +23,11 @@ class BirdClass(models.Model): class Meta: verbose_name_plural = 'Bird Class' - + def __str__(self): return self.common_name + class Bird(models.Model): common_name = models.CharField(max_length=200) scientific_name = models.CharField(max_length=200) @@ -34,11 +36,11 @@ class Bird(models.Model): def __str__(self): return self.common_name - + + class BirdSighting(models.Model): bird = models.ForeignKey(Bird) point = models.PointField() location = models.ForeignKey(Location) date = models.DateTimeField('Date') - image = models.FileField(upload_to=get_upload_path, null=True,blank=True) - + image = models.FileField(upload_to=get_upload_path, null=True, blank=True) -- cgit v1.2.3-70-g09d2