diff options
author | luxagraf <sng@luxagraf.net> | 2014-05-23 11:28:10 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2014-05-23 11:28:10 -0400 |
commit | 518b2d618bc10f93cfa44a83715593b8358eb9ce (patch) | |
tree | a07993c3ae31bed42f32c0e00788989568790716 /app/projects/models | |
parent | 4bae11bb25a8e3c43118891d17fd8e981ecf8dc6 (diff) |
minor refactor to adoipt pep8 and pyflakes coding styles and clean up
some cruft that's been hangin round for years
Diffstat (limited to 'app/projects/models')
-rw-r--r-- | app/projects/models/base.py | 32 | ||||
-rw-r--r-- | app/projects/models/fiveby.py | 33 | ||||
-rw-r--r-- | app/projects/models/gifs.py | 9 | ||||
-rw-r--r-- | app/projects/models/natparks.py | 41 |
4 files changed, 49 insertions, 66 deletions
diff --git a/app/projects/models/base.py b/app/projects/models/base.py index 26a0122..51379a0 100644 --- a/app/projects/models/base.py +++ b/app/projects/models/base.py @@ -1,26 +1,18 @@ import datetime from django.contrib.gis.db import models -from django.conf import settings from django.contrib.sitemaps import Sitemap -from django.template.defaultfilters import truncatewords_html -from django.contrib.syndication.views import Feed - import markdown -from photos.models import PhotoGallery -from locations.models import Location,Region - - def get_upload_path(self, filename): - return "images/project-thumbs/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + return "images/project-thumbs/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) -def markdown_processor(md): - html = markdown.markdown(md, safe_mode = False).split('<break>') + +def markdown_processor(md): + html = markdown.markdown(md, safe_mode=False).split('<break>') return html - class Project(models.Model): title = models.CharField(max_length=200) subtitle = models.CharField(max_length=200, null=True, blank=True) @@ -32,9 +24,9 @@ class Project(models.Model): (1, 'Published'), ) status = models.IntegerField(choices=PUB_STATUS, default=0) - image = models.FileField(upload_to=get_upload_path, null=True,blank=True) + image = models.FileField(upload_to=get_upload_path, null=True, blank=True) model_name = models.CharField(max_length=200, null=True) - + @property def longitude(self): '''Get the site's longitude.''' @@ -43,8 +35,8 @@ class Project(models.Model): @property def latitude(self): '''Get the site's latitude.''' - return self.point.y - + return self.point.y + class Meta: ordering = ('-pub_date',) get_latest_by = 'pub_date' @@ -55,14 +47,14 @@ class Project(models.Model): def get_absolute_url(self): return "/%s/%s/" % ('projects', self.slug) - + def get_previous_published(self): return self.get_previous_by_pub_date(status__exact=1) - + def get_next_published(self): return self.get_next_by_pub_date(status__exact=1) - - + + class ProjectSitemap(Sitemap): changefreq = "monthly" priority = 0.5 diff --git a/app/projects/models/fiveby.py b/app/projects/models/fiveby.py index 45aa21d..b6c7e33 100644 --- a/app/projects/models/fiveby.py +++ b/app/projects/models/fiveby.py @@ -1,25 +1,23 @@ import datetime from django.contrib.gis.db import models -from django.conf import settings -from django.contrib.sitemaps import Sitemap -from django.template.defaultfilters import truncatewords_html -from django.contrib.syndication.views import Feed +from locations.models import Location, Region -from locations.models import Location,Region def get_upload_path(self, filename): - return "images/projects/videos/5x5/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + return "images/projects/videos/5x5/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + def get_image_upload_path(self, filename): - return "images/projects/5x5/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) - + return "images/projects/5x5/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + + class FiveBy(models.Model): title = models.CharField(max_length=200) slug = models.SlugField(unique_for_date='pub_date') lede = models.TextField(blank=True) - image = models.FileField(upload_to=get_image_upload_path, null=True,blank=True) - videoh264 = models.FileField(upload_to=get_upload_path, null=True,blank=True) - videoogg = models.FileField(upload_to=get_upload_path, null=True,blank=True) + image = models.FileField(upload_to=get_image_upload_path, null=True, blank=True) + videoh264 = models.FileField(upload_to=get_upload_path, null=True, blank=True) + videoogg = models.FileField(upload_to=get_upload_path, null=True, blank=True) vimeo_link = models.CharField(max_length=200) youtube_link = models.CharField(max_length=200) pub_date = models.DateTimeField('Date published') @@ -31,21 +29,19 @@ class FiveBy(models.Model): point = models.PointField(null=True) location = models.ForeignKey(Location, null=True) region = models.ForeignKey(Region, null=True) - - - + class Meta: ordering = ('-pub_date',) get_latest_by = 'pub_date' app_label = 'projects' verbose_name_plural = '5x5' - - def __unicode__(self): + + def __str__(self): return self.title def get_absolute_url(self): return "/%s/%s/%s/" % ('projects', '5x5', self.slug) - + @property def longitude(self): '''Get the site's longitude.''' @@ -54,5 +50,4 @@ class FiveBy(models.Model): @property def latitude(self): '''Get the site's latitude.''' - return self.point.y - + return self.point.y diff --git a/app/projects/models/gifs.py b/app/projects/models/gifs.py index e20530b..25b8734 100644 --- a/app/projects/models/gifs.py +++ b/app/projects/models/gifs.py @@ -3,7 +3,7 @@ from django.db import models def get_upload_path(self, filename): - return "images/projects/gifs/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + return "images/projects/gifs/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) class AnimatedGif(models.Model): @@ -18,8 +18,9 @@ class AnimatedGif(models.Model): verbose_name_plural = "Animated Gifs" app_label = 'projects' ordering = ('-date_created',) - # Returns the string representation of the model. - def __unicode__(self): + + def __str__(self): return self.slug + def get_absolute_url(self): - return '/projects/gifs/%s/' %(self.slug) + return '/projects/gifs/%s/' % (self.slug) diff --git a/app/projects/models/natparks.py b/app/projects/models/natparks.py index 11fe6bb..3615737 100644 --- a/app/projects/models/natparks.py +++ b/app/projects/models/natparks.py @@ -1,19 +1,13 @@ -from django.contrib.gis.db import models +import datetime from PIL import Image +from django.contrib.gis.db import models from blog.models import Entry from photos.models import PhotoGallery from locations.models import State -PUB_STATUS = ( - (0, 'Draft'), - (1, 'Published'), - ) - - -import datetime def get_upload_path(self, filename): - return "images/projects/np/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + return "images/projects/np/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) class NationalParks(models.Model): @@ -24,33 +18,34 @@ class NationalParks(models.Model): fee = models.CharField(max_length=5, null=True) camping_fee = models.CharField(max_length=10, null=True) url = models.CharField(max_length=250, null=True) - code= models.CharField(max_length=16) - unit_name= models.CharField(max_length=254) - date_visited_begin = models.DateField('Date Visited',null=True) - date_visited_end = models.DateField('Date Visited',null=True) - date_park_created = models.DateField('Date Park Created',null=True) - zoom= models.IntegerField(null=True) + code = models.CharField(max_length=16) + unit_name = models.CharField(max_length=254) + date_visited_begin = models.DateField('Date Visited', null=True) + date_visited_end = models.DateField('Date Visited', null=True) + date_park_created = models.DateField('Date Park Created', null=True) + zoom = models.IntegerField(null=True) mpoly = models.MultiPolygonField(null=True) visited = models.BooleanField(default=False) dek = models.TextField(null=True, blank=True) tag_line = models.CharField(max_length=254, null=True) post = models.ForeignKey(Entry, null=True) gallery = models.ForeignKey(PhotoGallery, blank=True, null=True, verbose_name='photo set') - image = models.FileField(upload_to=get_upload_path, null=True,blank=True,help_text="width: 980px, height: > 450px") - image_height = models.CharField(max_length=20, null=True,blank=True) - image_width = models.CharField(max_length=20, null=True,blank=True) + image = models.FileField(upload_to=get_upload_path, null=True, blank=True, + help_text="width: 980px, height: > 450px") + image_height = models.CharField(max_length=20, null=True, blank=True) + image_width = models.CharField(max_length=20, null=True, blank=True) objects = models.GeoManager() class Meta: verbose_name_plural = "National Parks" app_label = 'projects' - ordering = ('-visited','unit_name',) - # Returns the string representation of the model. - def __unicode__(self): + ordering = ('-visited', 'unit_name',) + + def __str__(self): return self.unit_name - def save(self): + def save(self): #get image dimensions img = Image.open(self.image) - self.image_width, self.image_height = img.size + self.image_width, self.image_height = img.size super(NationalParks, self).save() |