diff options
author | luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f <luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f> | 2009-01-05 04:07:10 +0000 |
---|---|---|
committer | luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f <luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f> | 2009-01-05 04:07:10 +0000 |
commit | 637d71d2c3a7c1c65a931e1eb094052a095cdf05 (patch) | |
tree | ca34a2fead939b133143ec7647a9437d52c89075 /apps/photos/models.py |
have at it
Diffstat (limited to 'apps/photos/models.py')
-rw-r--r-- | apps/photos/models.py | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/apps/photos/models.py b/apps/photos/models.py new file mode 100644 index 0000000..9b6d331 --- /dev/null +++ b/apps/photos/models.py @@ -0,0 +1,154 @@ +import datetime +from django.contrib.gis.db import models +from django.contrib.syndication.feeds import Feed +from django.contrib.sitemaps import Sitemap +from django.utils.encoding import force_unicode +from django.conf import settings + +from tagging.fields import TagField +from tagging.models import Tag + +from locations.models import Location,Region + +class Photo(models.Model): + description = models.TextField(blank=True, null=True) + title = models.CharField(blank=True, max_length=300) + pub_date = models.DateTimeField() + tags = TagField() + exif_aperture = models.CharField(max_length=50, blank=True, null=True) + exif_make = models.CharField(max_length=50, blank=True, null=True) + exif_model = models.CharField(max_length=50, blank=True, null=True) + exif_shutter = models.CharField(max_length=50, blank=True, null=True) + exif_iso = models.CharField(max_length=50, blank=True, null=True) + exif_lens = models.CharField(max_length=50, blank=True, null=True) + exif_date = models.DateTimeField() + """Flickr Specific Stuff""" + flickr_id = models.CharField(max_length=300) #varchar since Flickr ids are larger than than integerfield can handle and BigIntegerField gets weird in Postgres. + flickr_owner = models.CharField(max_length=20) + flickr_server = models.IntegerField() + flickr_farm = models.IntegerField() + flickr_secret = models.CharField(max_length=50) + flickr_originalsecret = models.CharField(max_length=50) + lon = models.FloatField('Longitude',help_text="Longitude of centerpoint",null=True) + lat = models.FloatField('Latitude',help_text="Latitude of centerpoint",null=True) + location = models.ForeignKey(Location, null=True) + region = models.ForeignKey(Region, null=True) + + + + + class Meta: + ordering = ('-pub_date',) + + + def admin_thumbnail(self): + return force_unicode('<a href="%s"><img src="%s"></a>' % \ + (self.get_absolute_url(), self.get_small_square_url())) + admin_thumbnail.allow_tags = True + admin_thumbnail.short_description = 'Thumbnail' + + + def __unicode__(self): + return self.title + + def get_absolute_url(self): + return "/photo/%s/" % (self.id) + + def get_model_name(self): + return 'photo' + + def get_small_square_url(self): + return self.get_pic_url(size="small_square") + + def get_large_url(self): + return self.get_pic_url(size="large") + + def get_small_url(self): + return self.get_pic_url(size="small") + + def get_medium_url(self): + return self.get_pic_url(size="medium") + + def get_original_url(self): + #return self.get_pic_url(size="original") + return "http://farm%s.static.flickr.com/%s/%s_%s_o.jpg" % (self.flickr_farm, self.flickr_server, self.flickr_id, self.flickr_originalsecret) + + def get_pic_url(self, size='small'): + # small_square=75x75 + # thumb=100 on longest side + # small=240 on longest side + # medium=500 on longest side + # large=1024 on longest side + # original=duh + + base_url = "http://static.flickr.com" + size_char='s' # default to small_square + + if size == 'small_square': + size_char='_s' + elif size == 'thumb': + size_char='_t' + elif size == 'small': + size_char='_m' + elif size == 'medium': + size_char='' + elif size == 'large': + size_char='_b' + elif size == 'original': + size_char='_o' + + return "http://farm%s.static.flickr.com/%s/%s_%s%s.jpg" % (self.flickr_farm, self.flickr_server, self.flickr_id, self.flickr_secret, size_char) + + def get_tumble_image(self): + return "%s/crops/%s/%s.jpg" %(settings.IMAGES_URL, self.pub_date.strftime("%Y/%b").lower(), self.id) + + def get_tags(self): + return Tag.objects.get_for_object(self) + + def get_previous_published(self): + return self.get_previous_by_pub_date() + + def get_next_published(self): + return self.get_next_by_pub_date() + + def comment_period_open(self): + return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date + """ + def save(self): + self.lat = self.gps.split(',')[0] + self.lon = self.gps.split(',')[1] + super(Photo, self).save() + """ +class PhotoGallery(models.Model): + set_id = models.CharField(blank=True, max_length=300) + set_title = models.CharField(blank=True, max_length=300) + set_desc = models.TextField(blank=True, null=True) + set_slug = models.CharField(blank=True, max_length=300) + primary = models.CharField(blank=True, max_length=300) + photos = models.ManyToManyField(Photo) + location = models.ForeignKey(Location, null=True) + region = models.ForeignKey(Region, null=True) + + class Meta: + ordering = ('id',) + + def __unicode__(self): + return self.set_title + + def get_main_image(self): + return "%sgallery_thumbs/%s.jpg" % (settings.IMAGES_URL, self.id) + + def get_absolute_url(self): + return "/photos/album/%s/" % (self.id) + + +class PhotoSitemap(Sitemap): + changefreq = "never" + priority = 0.7 + + def items(self): + return Photo.objects.all() + + def lastmod(self, obj): + return obj.pub_date + |