Browse files

Initial Flickr app.

Models. Start of Admin. Not tested. Needs fetching code.
  • Loading branch information...
1 parent 20d93f7 commit 32a3874be95ba6ea9d07ce9a9b13407a6af9240a @philgyford committed May 2, 2012
View
10 archivr/managers.py
@@ -0,0 +1,10 @@
+from django.db import models
+
+
+class VisibleManager(models.Manager):
+ """
+ All ArchivrItems that are not 'hidden'.
+ """
+ def get_query_set(self):
+ return super(VisibleManager, self).get_query_set().filter(hidden=False)
+
View
36 archivr/migrations/0001_initial.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'ArchivrItem'
+ db.create_table('archivr_archivritem', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('order_date', self.gf('django.db.models.fields.DateTimeField')()),
+ ('hidden', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('coordinate', self.gf('django.contrib.gis.db.models.fields.PointField')()),
+ ('item_genre', self.gf('django.db.models.fields.CharField')(default='', max_length=20)),
+ ))
+ db.send_create_signal('archivr', ['ArchivrItem'])
+
+ def backwards(self, orm):
+ # Deleting model 'ArchivrItem'
+ db.delete_table('archivr_archivritem')
+
+ models = {
+ 'archivr.archivritem': {
+ 'Meta': {'ordering': "('-order_date',)", 'object_name': 'ArchivrItem'},
+ 'coordinate': ('django.contrib.gis.db.models.fields.PointField', [], {}),
+ 'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'item_genre': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '20'}),
+ 'order_date': ('django.db.models.fields.DateTimeField', [], {})
+ }
+ }
+
+ complete_apps = ['archivr']
View
29 archivr/migrations/0002_auto__chg_field_archivritem_coordinate.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Changing field 'ArchivrItem.coordinate'
+ db.alter_column('archivr_archivritem', 'coordinate', self.gf('django.contrib.gis.db.models.fields.PointField')(null=True))
+ def backwards(self, orm):
+
+ # Changing field 'ArchivrItem.coordinate'
+ db.alter_column('archivr_archivritem', 'coordinate', self.gf('django.contrib.gis.db.models.fields.PointField')(default=''))
+ models = {
+ 'archivr.archivritem': {
+ 'Meta': {'ordering': "('-order_date',)", 'object_name': 'ArchivrItem'},
+ 'coordinate': ('django.contrib.gis.db.models.fields.PointField', [], {'null': 'True'}),
+ 'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'item_genre': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '20'}),
+ 'order_date': ('django.db.models.fields.DateTimeField', [], {})
+ }
+ }
+
+ complete_apps = ['archivr']
View
0 archivr/migrations/__init__.py
No changes.
View
52 archivr/models.py
@@ -1,3 +1,53 @@
from django.db import models
+from django.contrib.gis.db import models
+from django.contrib.gis.geos import Point
+
+from archivr.managers import VisibleManager
+
+# So we can group different models of the same type together.
+# eg, fetch Flickr and Instagram photos together.
+ARCHIVR_ITEM_GENRES = (
+ ('image', 'Image: Photos, etc.'),
+ ('status', 'Status: Tweet, etc.'),
+ ('link', 'Link: Pinboard, Delicious, etc.'),
+)
+
+class ArchivrItem(models.Model):
+ """
+ The class that all Archivr classes representing "things" (eg, Tweet, Photo,
+ Link, etc) will be descended from.
+ Stores data that is common across all these items, and lets us fetch items of
+ different types together, ordered by date (for example).
+ """
+
+ order_date = models.DateTimeField(
+ help_text="The date used for ordering the item")
+ hidden = models.BooleanField(default=False,
+ help_text="Is this item hidden from public view?")
+ coordinate = models.PointField(null=True,
+ help_text="Where this item is located")
+ item_genre = models.CharField(max_length=20, default='',
+ choices=ARCHIVR_ITEM_GENRES)
+
+
+ class Meta:
+ ordering = ('-order_date',)
+ get_latest_by = 'order_date'
+
+ # ALL items.
+ objects = models.Manager()
+ # Items that haven't been marked as hidden.
+ visible_objects = VisibleManager()
+
+
+ def is_a(self, item_kind):
+ """
+ Test what kind of item this is.
+ eg `item.is_a('tweet')`
+ Note, this doesn't refer to the item_genre, which is a more general grouping.
+ """
+ if hasattr(self, str(item_kind)):
+ return True
+ else:
+ return False
-# Create your models here.
View
BIN archivrflickr/.DS_Store
Binary file not shown.
View
0 archivrflickr/__init__.py
No changes.
View
44 archivrflickr/admin.py
@@ -0,0 +1,44 @@
+from django.contrib import admin
+from django.contrib import gis
+from archivrflickr.models import FlickrPhoto
+
+
+class FlickrPhotoTagInline(admin.TabularInline):
+ model = FlickrPhoto.tags.through
+ raw_id_fields = ('tag',)
+
+
+class FlickrPhotoAdmin(admin.OSMGeoAdmin):
+ date_hierarchy = 'posted_date'
+ list_display = ('posted_date', 'show_thumb', 'title', 'owner', 'hidden',)
+ list_display_links = ('title', 'show_thumb',)
+ list_filter = ('posted_date',)
+ search_fields = ['title', 'description',]
+ inlines = [FlickrPhotoTagInline,]
+ exclude = ('tags',)
+ fieldsets = (
+ (None, {
+ 'fields': ('flickr_id', 'owner', 'title', 'description', 'posted_date', 'updated_date', 'taken_date', 'taken_granularity', 'license', 'comments', 'visibility_is_public', 'visibility_is_friend', 'visibility_is_family',)
+ }),
+ ('URL etc.', {
+ 'fields': ('photopage_url', 'farm', 'server', 'secret', 'original_secret', 'original_format',)
+ }),
+ ('Image sizes', {
+ 'fields': ('large_width', 'large_height', 'largesquare_width','largesquare_height', 'medium640_width', 'medium640_height', 'medium800_width', 'medium800_height', 'medium_width', 'medium_height', 'original_width', 'original_height', 'small320_width', 'small320_height', 'small_width', 'small_height', 'square_width', 'square_height', 'thumbnail_width', 'thumbnail_height',)
+ }),
+ ('Geo', {
+ 'fields': ('geo_latitude', 'geo_longitude', 'geo_accuracy', 'geo_county', 'geo_county_place_id', 'geo_county_woe_id', 'geo_country', 'geo_country_place_id', 'geo_country_woe_id', 'geo_locality', 'geo_locality_place_id', 'geo_locality_woe_id', 'geo_region', 'geo_region_place_id', 'geo_region_woe_id',)
+ }),
+ ('EXIF', {
+ 'fields': ('exif_aperture', 'exif_color_space', 'exif_exposure', 'exif_flash', 'exif_focal_length', 'exif_iso', 'exif_make', 'exif_metering_mode', 'exif_model', 'exif_orientation', 'exif_software',)
+ }),
+ )
+
+ def show_thumb(self, instance):
+ return '<img src="%s" width="%s" height="%s" alt="Thumbnail" />' % (instance.get_thumbnail_url(), instance.thumbnail_width, instance.thumbnail_height)
+ show_thumb.allow_tags = True
+ show_thumb.short_description = ''
+
+admin.site.register(FlickrPhoto, FlickrPhotoAdmin)
+
+#gis.admin.site.register(FlickrPhoto, gis.admin.OSMGeoAdmin)
View
335 archivrflickr/migrations/0001_initial.py
@@ -0,0 +1,335 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'FlickrFavorite'
+ db.create_table('archivrflickr_flickrfavorite', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('photo', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrPhoto'])),
+ ('favorite_list', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrFavoriteList'])),
+ ('date_faved', self.gf('django.db.models.fields.DateTimeField')()),
+ ))
+ db.send_create_signal('archivrflickr', ['FlickrFavorite'])
+
+ # Adding model 'FlickrFavoriteList'
+ db.create_table('archivrflickr_flickrfavoritelist', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('owner', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrUser'])),
+ ('date_archived', self.gf('django.db.models.fields.DateTimeField')()),
+ ('primary', self.gf('django.db.models.fields.related.ForeignKey')(related_name='primary_in', null=True, to=orm['archivrflickr.FlickrPhoto'])),
+ ))
+ db.send_create_signal('archivrflickr', ['FlickrFavoriteList'])
+
+ # Adding model 'FlickrPhoto'
+ db.create_table('archivrflickr_flickrphoto', (
+ ('archivritem_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['archivr.ArchivrItem'], unique=True, primary_key=True)),
+ ('flickr_id', self.gf('django.db.models.fields.CharField')(unique=True, max_length=50)),
+ ('owner', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrUser'])),
+ ('title', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ('description', self.gf('django.db.models.fields.TextField')(blank=True)),
+ ('posted_date', self.gf('django.db.models.fields.DateTimeField')()),
+ ('updated_date', self.gf('django.db.models.fields.DateTimeField')()),
+ ('taken_date', self.gf('django.db.models.fields.DateTimeField')()),
+ ('taken_granularity', self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=0)),
+ ('comments', self.gf('django.db.models.fields.PositiveIntegerField')(default=0)),
+ ('visibility_is_public', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('visibility_is_friend', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('visibility_is_family', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('photopage_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
+ ('farm', self.gf('django.db.models.fields.PositiveSmallIntegerField')()),
+ ('server', self.gf('django.db.models.fields.PositiveSmallIntegerField')()),
+ ('secret', self.gf('django.db.models.fields.CharField')(max_length=10)),
+ ('original_secret', self.gf('django.db.models.fields.CharField')(max_length=10, blank=True)),
+ ('original_format', self.gf('django.db.models.fields.CharField')(max_length=10, blank=True)),
+ ('large_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('large_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('largesquare_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('largesquare_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('medium640_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('medium640_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('medium800_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('medium800_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('medium_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('medium_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('original_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('original_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('small320_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('small320_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('small_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('small_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('square_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('square_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('thumbnail_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('thumbnail_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
+ ('license', self.gf('django.db.models.fields.CharField')(max_length=50)),
+ ('geo_latitude', self.gf('django.db.models.fields.FloatField')(null=True, blank=True)),
+ ('geo_longitude', self.gf('django.db.models.fields.FloatField')(null=True, blank=True)),
+ ('geo_accuracy', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True, blank=True)),
+ ('geo_county', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('geo_county_place_id', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
+ ('geo_county_woe_id', self.gf('django.db.models.fields.PositiveIntegerField')(max_length=50, blank=True)),
+ ('geo_country', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('geo_country_place_id', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
+ ('geo_country_woe_id', self.gf('django.db.models.fields.PositiveIntegerField')(max_length=50, blank=True)),
+ ('geo_locality', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('geo_locality_place_id', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
+ ('geo_locality_woe_id', self.gf('django.db.models.fields.PositiveIntegerField')(max_length=50, blank=True)),
+ ('geo_region', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('geo_region_place_id', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
+ ('geo_region_woe_id', self.gf('django.db.models.fields.PositiveIntegerField')(max_length=50, blank=True)),
+ ('exif_aperture', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('exif_color_space', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('exif_exposure', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('exif_flash', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('exif_focal_length', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('exif_iso', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('exif_make', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('exif_metering_mode', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('exif_model', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('exif_orientation', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ('exif_software', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+ ))
+ db.send_create_signal('archivrflickr', ['FlickrPhoto'])
+
+ # Adding model 'FlickrPhotoComment'
+ db.create_table('archivrflickr_flickrphotocomment', (
+ ('flickr_id', self.gf('django.db.models.fields.CharField')(max_length=128, primary_key=True)),
+ ('photo', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrPhoto'])),
+ ('author', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrUser'])),
+ ('pub_date', self.gf('django.db.models.fields.DateTimeField')()),
+ ('permanent_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
+ ('comment', self.gf('django.db.models.fields.TextField')()),
+ ))
+ db.send_create_signal('archivrflickr', ['FlickrPhotoComment'])
+
+ # Adding model 'FlickrPhotoset'
+ db.create_table('archivrflickr_flickrphotoset', (
+ ('flickr_id', self.gf('django.db.models.fields.CharField')(max_length=50, primary_key=True)),
+ ('primary', self.gf('django.db.models.fields.related.ForeignKey')(default=None, related_name='primary_photo_set', null=True, to=orm['archivrflickr.FlickrPhoto'])),
+ ('owner', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrUser'])),
+ ('title', self.gf('django.db.models.fields.CharField')(max_length=200)),
+ ('description', self.gf('django.db.models.fields.TextField')(blank=True)),
+ ('order', self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=0)),
+ ))
+ db.send_create_signal('archivrflickr', ['FlickrPhotoset'])
+
+ # Adding M2M table for field photos on 'FlickrPhotoset'
+ db.create_table('archivrflickr_flickrphotoset_photos', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('flickrphotoset', models.ForeignKey(orm['archivrflickr.flickrphotoset'], null=False)),
+ ('flickrphoto', models.ForeignKey(orm['archivrflickr.flickrphoto'], null=False))
+ ))
+ db.create_unique('archivrflickr_flickrphotoset_photos', ['flickrphotoset_id', 'flickrphoto_id'])
+
+ # Adding model 'FlickrPhotoTag'
+ db.create_table('archivrflickr_flickrphototag', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('tag', self.gf('django.db.models.fields.related.ForeignKey')(related_name='archivrflickr_flickrphototag_items', to=orm['taggit.Tag'])),
+ ('flickr_id', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ('author_nsid', self.gf('django.db.models.fields.CharField')(max_length=50)),
+ ('machine_tag', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('content_object', self.gf('django.db.models.fields.related.ForeignKey')(related_name='archivrflickr_flickrphototag_items', to=orm['archivrflickr.FlickrPhoto'])),
+ ))
+ db.send_create_signal('archivrflickr', ['FlickrPhotoTag'])
+
+ # Adding model 'FlickrUser'
+ db.create_table('archivrflickr_flickruser', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('nsid', self.gf('django.db.models.fields.CharField')(max_length=50)),
+ ('username', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ('realname', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ('path_alias', self.gf('django.db.models.fields.CharField')(max_length=50)),
+ ('location', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ('description', self.gf('django.db.models.fields.TextField')()),
+ ('photos_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
+ ('profile_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
+ ('mobile_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
+ ('iconserver', self.gf('django.db.models.fields.PositiveSmallIntegerField')()),
+ ('iconfarm', self.gf('django.db.models.fields.PositiveSmallIntegerField')()),
+ ('photos_first_date_taken', self.gf('django.db.models.fields.DateTimeField')()),
+ ('photos_first_date', self.gf('django.db.models.fields.DateTimeField')()),
+ ('photos_count', self.gf('django.db.models.fields.PositiveIntegerField')()),
+ ('photos_views', self.gf('django.db.models.fields.PositiveIntegerField')()),
+ ))
+ db.send_create_signal('archivrflickr', ['FlickrUser'])
+
+ def backwards(self, orm):
+ # Deleting model 'FlickrFavorite'
+ db.delete_table('archivrflickr_flickrfavorite')
+
+ # Deleting model 'FlickrFavoriteList'
+ db.delete_table('archivrflickr_flickrfavoritelist')
+
+ # Deleting model 'FlickrPhoto'
+ db.delete_table('archivrflickr_flickrphoto')
+
+ # Deleting model 'FlickrPhotoComment'
+ db.delete_table('archivrflickr_flickrphotocomment')
+
+ # Deleting model 'FlickrPhotoset'
+ db.delete_table('archivrflickr_flickrphotoset')
+
+ # Removing M2M table for field photos on 'FlickrPhotoset'
+ db.delete_table('archivrflickr_flickrphotoset_photos')
+
+ # Deleting model 'FlickrPhotoTag'
+ db.delete_table('archivrflickr_flickrphototag')
+
+ # Deleting model 'FlickrUser'
+ db.delete_table('archivrflickr_flickruser')
+
+ models = {
+ 'archivr.archivritem': {
+ 'Meta': {'ordering': "('-order_date',)", 'object_name': 'ArchivrItem'},
+ 'coordinate': ('django.contrib.gis.db.models.fields.PointField', [], {}),
+ 'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'item_genre': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '20'}),
+ 'order_date': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ 'archivrflickr.flickrfavorite': {
+ 'Meta': {'object_name': 'FlickrFavorite'},
+ 'date_faved': ('django.db.models.fields.DateTimeField', [], {}),
+ 'favorite_list': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrFavoriteList']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'photo': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrPhoto']"})
+ },
+ 'archivrflickr.flickrfavoritelist': {
+ 'Meta': {'object_name': 'FlickrFavoriteList'},
+ 'date_archived': ('django.db.models.fields.DateTimeField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrUser']"}),
+ 'photos': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['archivrflickr.FlickrPhoto']", 'through': "orm['archivrflickr.FlickrFavorite']", 'symmetrical': 'False'}),
+ 'primary': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'primary_in'", 'null': 'True', 'to': "orm['archivrflickr.FlickrPhoto']"})
+ },
+ 'archivrflickr.flickrphoto': {
+ 'Meta': {'ordering': "('-taken_date',)", 'object_name': 'FlickrPhoto', '_ormbases': ['archivr.ArchivrItem']},
+ 'archivritem_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['archivr.ArchivrItem']", 'unique': 'True', 'primary_key': 'True'}),
+ 'comments': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'exif_aperture': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'exif_color_space': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'exif_exposure': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'exif_flash': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'exif_focal_length': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'exif_iso': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'exif_make': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'exif_metering_mode': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'exif_model': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'exif_orientation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'exif_software': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'farm': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+ 'flickr_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50'}),
+ 'geo_accuracy': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'geo_country': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'geo_country_place_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
+ 'geo_country_woe_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '50', 'blank': 'True'}),
+ 'geo_county': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'geo_county_place_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
+ 'geo_county_woe_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '50', 'blank': 'True'}),
+ 'geo_latitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+ 'geo_locality': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'geo_locality_place_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
+ 'geo_locality_woe_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '50', 'blank': 'True'}),
+ 'geo_longitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+ 'geo_region': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'geo_region_place_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
+ 'geo_region_woe_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '50', 'blank': 'True'}),
+ 'large_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'large_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'largesquare_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'largesquare_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'license': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+ 'medium640_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'medium640_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'medium800_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'medium800_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'medium_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'medium_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'original_format': ('django.db.models.fields.CharField', [], {'max_length': '10', 'blank': 'True'}),
+ 'original_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'original_secret': ('django.db.models.fields.CharField', [], {'max_length': '10', 'blank': 'True'}),
+ 'original_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrUser']"}),
+ 'photopage_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+ 'posted_date': ('django.db.models.fields.DateTimeField', [], {}),
+ 'secret': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
+ 'server': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+ 'small320_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'small320_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'small_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'small_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'square_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'square_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'taken_date': ('django.db.models.fields.DateTimeField', [], {}),
+ 'taken_granularity': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '0'}),
+ 'thumbnail_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'thumbnail_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'updated_date': ('django.db.models.fields.DateTimeField', [], {}),
+ 'visibility_is_family': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'visibility_is_friend': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'visibility_is_public': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+ },
+ 'archivrflickr.flickrphotocomment': {
+ 'Meta': {'ordering': "('pub_date',)", 'object_name': 'FlickrPhotoComment'},
+ 'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrUser']"}),
+ 'comment': ('django.db.models.fields.TextField', [], {}),
+ 'flickr_id': ('django.db.models.fields.CharField', [], {'max_length': '128', 'primary_key': 'True'}),
+ 'permanent_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+ 'photo': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrPhoto']"}),
+ 'pub_date': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ 'archivrflickr.flickrphotoset': {
+ 'Meta': {'ordering': "('order',)", 'object_name': 'FlickrPhotoset'},
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'flickr_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'primary_key': 'True'}),
+ 'order': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '0'}),
+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrUser']"}),
+ 'photos': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['archivrflickr.FlickrPhoto']", 'symmetrical': 'False'}),
+ 'primary': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'related_name': "'primary_photo_set'", 'null': 'True', 'to': "orm['archivrflickr.FlickrPhoto']"}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '200'})
+ },
+ 'archivrflickr.flickrphototag': {
+ 'Meta': {'object_name': 'FlickrPhotoTag'},
+ 'author_nsid': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+ 'content_object': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'archivrflickr_flickrphototag_items'", 'to': "orm['archivrflickr.FlickrPhoto']"}),
+ 'flickr_id': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'machine_tag': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'archivrflickr_flickrphototag_items'", 'to': "orm['taggit.Tag']"})
+ },
+ 'archivrflickr.flickruser': {
+ 'Meta': {'object_name': 'FlickrUser'},
+ 'description': ('django.db.models.fields.TextField', [], {}),
+ 'iconfarm': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+ 'iconserver': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'location': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'mobile_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+ 'nsid': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+ 'path_alias': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+ 'photos_count': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'photos_first_date': ('django.db.models.fields.DateTimeField', [], {}),
+ 'photos_first_date_taken': ('django.db.models.fields.DateTimeField', [], {}),
+ 'photos_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+ 'photos_views': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'profile_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+ 'realname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'username': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ },
+ 'taggit.tag': {
+ 'Meta': {'object_name': 'Tag'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'})
+ }
+ }
+
+ complete_apps = ['archivrflickr']
View
0 archivrflickr/migrations/__init__.py
No changes.
View
405 archivrflickr/models.py
@@ -0,0 +1,405 @@
+from django.db import models
+from django.utils.html import strip_tags
+from django.utils.text import truncate_words
+from django.utils.translation import ugettext_lazy as _
+
+from taggit.managers import TaggableManager
+from taggit.models import TaggedItemBase
+
+from archivr.models import ArchivrItem
+from archivr.managers import *
+
+
+class FlickrFavorite(models.Model):
+ """
+ Linking FlickrPhotos into a FlickrFavoriteList, so that we can capture the
+ date_faved time for each one.
+ """
+ photo = models.ForeignKey('FlickrPhoto')
+ favorite_list = models.ForeignKey('FlickrFavoriteList')
+ date_faved = models.DateTimeField()
+
+
+class FlickrFavoriteList(models.Model):
+ owner = models.ForeignKey('FlickrUser')
+ date_archived = models.DateTimeField()
+ photos = models.ManyToManyField('FlickrPhoto', through='FlickrFavorite')
+ primary = models.ForeignKey('FlickrPhoto', related_name='primary_in', null=True)
+
+ def numPhotos(self):
+ return len(self.photo_list.objects.all())
+
+ def __unicode__(self):
+ return u"%s's favorite photos" % self.owner
+
+
+class FlickrPhoto(ArchivrItem):
+ """
+ A single photo on Flickr.
+ """
+
+ FLICKR_LICENSES = (
+ ('0', 'All Rights Reserved'),
+ ('1', 'Attribution-NonCommercial-ShareAlike License'),
+ ('2', 'Attribution-NonCommercial License'),
+ ('3', 'Attribution-NonCommercial-NoDerivs License'),
+ ('4', 'Attribution License'),
+ ('5', 'Attribution-ShareAlike License'),
+ ('6', 'Attribution-NoDerivs License'),
+ ('7', 'No known copyright restrictions'),
+ )
+
+ # Granularity: http://www.flickr.com/services/api/misc.dates.html
+ FLICKR_DATE_GRANULARITIES = (
+ (0, 'Y-m-d H:i:s'),
+ (4, 'Y-m'),
+ (6, 'Y'),
+ (8, 'Circa...'),
+ )
+
+ # Data from Flickr:
+ flickr_id = models.CharField(max_length=50, unique=True,
+ help_text="ID of this photo on Flickr.")
+ owner = models.ForeignKey('FlickrUser')
+ title = models.CharField(max_length=255)
+ description = models.TextField(blank=True)
+
+ posted_date = models.DateTimeField(help_text="UTC")
+ updated_date = models.DateTimeField(help_text="UTC")
+ taken_date = models.DateTimeField(
+ help_text="In Flickr user's timezone (unknown).")
+ taken_granularity = models.PositiveSmallIntegerField(default=0,
+ choices=FLICKR_DATE_GRANULARITIES)
+
+ comments = models.PositiveIntegerField(default=0)
+ license = models.CharField(max_length=50, choices=FLICKR_LICENSES)
+ visibility_is_public = models.BooleanField(default=False)
+ visibility_is_friend = models.BooleanField(default=False)
+ visibility_is_family = models.BooleanField(default=False)
+
+ photopage_url = models.URLField(verify_exists=False)
+ farm = models.PositiveSmallIntegerField()
+ server = models.PositiveSmallIntegerField()
+ secret = models.CharField(max_length=10)
+ original_secret = models.CharField(max_length=10, blank=True)
+ original_format = models.CharField(max_length=10, blank=True)
+
+ large_height = models.PositiveSmallIntegerField(null=True)
+ large_width = models.PositiveSmallIntegerField(null=True)
+ largesquare_height = models.PositiveSmallIntegerField(null=True)
+ largesquare_width = models.PositiveSmallIntegerField(null=True)
+ medium640_height = models.PositiveSmallIntegerField(null=True)
+ medium640_width = models.PositiveSmallIntegerField(null=True)
+ medium800_height = models.PositiveSmallIntegerField(null=True)
+ medium800_width = models.PositiveSmallIntegerField(null=True)
+ medium_height = models.PositiveSmallIntegerField(null=True)
+ medium_width = models.PositiveSmallIntegerField(null=True)
+ original_height = models.PositiveSmallIntegerField(null=True)
+ original_width = models.PositiveSmallIntegerField(null=True)
+ small320_height = models.PositiveSmallIntegerField(null=True)
+ small320_width = models.PositiveSmallIntegerField(null=True)
+ small_height = models.PositiveSmallIntegerField(null=True)
+ small_width = models.PositiveSmallIntegerField(null=True)
+ square_height = models.PositiveSmallIntegerField(null=True)
+ square_width = models.PositiveSmallIntegerField(null=True)
+ thumbnail_height = models.PositiveSmallIntegerField(null=True)
+ thumbnail_width = models.PositiveSmallIntegerField(null=True)
+
+ geo_latitude = models.FloatField(null=True, blank=True)
+ geo_longitude = models.FloatField(null=True, blank=True)
+ geo_accuracy = models.PositiveSmallIntegerField(null=True, blank=True)
+ geo_county = models.CharField(max_length=255, blank=True)
+ geo_county_place_id = models.CharField(max_length=50, blank=True)
+ geo_county_woe_id = models.PositiveIntegerField(max_length=50, blank=True)
+ geo_country = models.CharField(max_length=255, blank=True)
+ geo_country_place_id = models.CharField(max_length=50, blank=True)
+ geo_country_woe_id = models.PositiveIntegerField(max_length=50, blank=True)
+ geo_locality = models.CharField(max_length=255, blank=True)
+ geo_locality_place_id = models.CharField(max_length=50, blank=True)
+ geo_locality_woe_id = models.PositiveIntegerField(max_length=50, blank=True)
+ geo_region = models.CharField(max_length=255, blank=True)
+ geo_region_place_id = models.CharField(max_length=50, blank=True)
+ geo_region_woe_id = models.PositiveIntegerField(max_length=50, blank=True)
+
+ exif_aperture = models.CharField(max_length=255, blank=True)
+ exif_color_space = models.CharField(max_length=255, blank=True)
+ exif_exposure = models.CharField(max_length=255, blank=True)
+ exif_flash = models.CharField(max_length=255, blank=True)
+ exif_focal_length = models.CharField(max_length=255, blank=True)
+ exif_iso = models.CharField(max_length=255, blank=True)
+ exif_make = models.CharField(max_length=255, blank=True)
+ exif_metering_mode = models.CharField(max_length=255, blank=True)
+ exif_model = models.CharField(max_length=255, blank=True)
+ exif_orientation = models.CharField(max_length=255, blank=True)
+ exif_software = models.CharField(max_length=255, blank=True)
+
+ tags = TaggableManager(blank=True, through='FlickrPhotoTag')
+
+ class Meta:
+ ordering = ('-taken_date',)
+ get_latest_by = 'posted_date'
+
+ def __unicode__(self):
+ return u'%s' % self.title
+
+ @models.permalink
+ def get_absolute_url(self):
+ return ('flickr_photo_detail', (), { 'flickr_id': self.flickr_id, })
+
+ # ALL FlickrPhotos.
+ objects = models.Manager()
+ # FlickrPhotos that haven't been marked as hidden.
+ visible_objects = VisibleManager()
+
+ def _get_photo_url_helper(self, size, secret=None, extension='jpg'):
+ size = size and '_%s' % size or ''
+ if secret is None:
+ secret = self.secret
+ return u'http://farm%s.static.flickr.com/%s/%s_%s%s.%s' % (
+ self.farm, self.server, self.flickr_id, secret, size, extension)
+
+ def get_square_url(self):
+ return self._get_photo_url_helper('s')
+
+ def get_thumbnail_url(self):
+ return self._get_photo_url_helper('t')
+
+ def get_small_url(self):
+ return self._get_photo_url_helper('m')
+
+ def get_small320_url(self):
+ if self.has_small320_photo:
+ return self._get_photo_url_helper('n')
+ return self.get_original_url()
+
+ def get_medium_url(self):
+ if self.has_medium_photo:
+ return self._get_photo_url_helper('')
+ return self.get_original_url()
+
+ def get_medium640_url(self):
+ if self.has_medium640_photo:
+ return self._get_photo_url_helper('z')
+ return self.get_original_url()
+
+ def get_medium800_url(self):
+ if self.has_medium800_photo:
+ return self._get_photo_url_helper('c')
+ return self.get_original_url()
+
+ def get_large_url(self):
+ if self.has_large_photo:
+ return self._get_photo_url_helper('b')
+ return self.get_original_url()
+
+ def get_largesquare_url(self):
+ if self.has_largesquare_photo:
+ return self._get_photo_url_helper('q')
+ return self.get_original_url()
+
+ def get_original_url(self):
+ if self.original_secret:
+ return self._get_photo_url_helper('o', secret=self.original_secret,
+ extension=self.original_format)
+ return self._get_photo_url_helper('o', extension=self.original_format)
+
+ @property
+ def has_small320_photo(self):
+ if self.small320_width is not None:
+ return True
+ return False
+
+ @property
+ def has_medium_photo(self):
+ if self.medium_width is not None:
+ return True
+ return False
+
+ @property
+ def has_medium640_photo(self):
+ if self.medium640_width is not None:
+ return True
+ return False
+
+ @property
+ def has_medium800_photo(self):
+ if self.medium800_width is not None:
+ return True
+ return False
+
+ @property
+ def has_large_photo(self):
+ if self.large_width is not None:
+ return True
+ return False
+
+ @property
+ def has_largesquare_photo(self):
+ if self.largesquare_width is not None:
+ return True
+ return False
+
+ @property
+ def has_original_photo(self):
+ if self.original_width is not None:
+ return True
+ return False
+
+ def _next_previous_helper(self, direction, photoset):
+ order = direction == 'next' and 'taken_date' or '-taken_date'
+ filter = direction == 'next' and 'gt' or 'lt'
+ try:
+ return self.photoset_set.get(pk=photoset.pk).photos.filter(
+ **{'taken_date__%s' % filter: self.taken_date}
+ ).order_by(order)[0]
+ except IndexError:
+ return None
+
+ def get_next_in_set(self, *args, **kwargs):
+ """
+ Returns the next Entry with "live" status by ``pub_date``, if
+ there is one, or ``None`` if there isn't.
+
+ In public-facing templates, use this method instead of
+ ``get_next_by_pub_date``, because ``get_next_by_pub_date``
+ does not differentiate entry status.
+
+ """
+ return self._next_previous_helper('next', *args, **kwargs)
+
+ def get_previous_in_set(self, *args, **kwargs):
+ """
+ Returns the previous Entry with "live" status by ``pub_date``,
+ if there is one, or ``None`` if there isn't.
+
+ In public-facing templates, use this method instead of
+ ``get_previous_by_pub_date``, because
+ ``get_previous_by_pub_date`` does not differentiate entry
+ status..
+
+ """
+ return self._next_previous_helper('previous', *args, **kwargs)
+
+
+class FlickrPhotoComment(models.Model):
+ """
+ Describes a single comment on a ``FlickrPhoto``.
+ """
+ flickr_id = models.CharField(primary_key=True, max_length=128)
+ photo = models.ForeignKey(FlickrPhoto)
+ author = models.ForeignKey('FlickrUser')
+ pub_date = models.DateTimeField()
+ permanent_url = models.URLField(verify_exists=False)
+ comment = models.TextField()
+
+ class Meta:
+ ordering = ('pub_date',)
+
+ def __unicode__(self):
+ return _(u"%(author)s said: %(comment)s") % {
+ 'author': self.author, 'comment': self.get_short_comment(4)}
+
+ def get_absolute_url(self):
+ return self.permanent_url
+
+ def get_short_comment(self, num=6):
+ return truncate_words(strip_tags(self.comment), num)
+ get_short_comment.short_description = _(u'comment')
+
+
+class FlickrPhotoset(models.Model):
+ """
+ One photoset and its list of ``FlickrPhotos``.
+ """
+
+ flickr_id = models.CharField(primary_key=True, max_length=50)
+ primary = models.ForeignKey(FlickrPhoto, null=True, default=None,
+ related_name='primary_photo_set')
+ owner = models.ForeignKey('FlickrUser')
+ title = models.CharField(max_length=200)
+ description = models.TextField(blank=True)
+ order = models.PositiveSmallIntegerField(default=0)
+ photos = models.ManyToManyField(FlickrPhoto)
+
+ class Meta:
+ ordering = ('order',)
+
+ def __unicode__(self):
+ return u"%s photoset by %s" % (self.title, self.owner)
+
+ @models.permalink
+ def get_absolute_url(self):
+ return ('photoset_detail', (), { 'flickr_id': self.flickr_id })
+
+ def highlight(self):
+ """
+ Return the highlight image of this photo set.
+
+ In case there isn't a ``primary`` image set, the first one is
+ selected. (If this causes a ``IndexError``, ``None`` is
+ returned.)
+ """
+ if self.primary is not None:
+ return self.primary
+ try:
+ return self.photos.all()[0]
+ except IndexError:
+ return None
+
+ def get_time_period(self):
+ """
+ Return dict with start and end of this photo set.
+
+ Gets ``taken_date`` of first and last ``FlickrPhoto`` and returns
+ results as dict::
+
+ { 'start': datetime.datetime, 'end': datetime.datetime }
+ """
+ start_photo = self.photos.order_by('taken_date')[0]
+ end_photo = self.photos.order_by('-taken_date')[0]
+ if start_photo.taken_date and end_photo.taken_date:
+ return {'start': start_photo.taken_date, 'end': end_photo.taken_date}
+ return {'start': start_photo.posted_date, 'end': end_photo.posted_date}
+
+
+class FlickrPhotoTag(TaggedItemBase):
+ """
+ Describes the relationship between a django-taggit Tag and a FlickrPhoto.
+ Flickr has various fields which are unique to this relationship, rather
+ than the Tag itself.
+ """
+ flickr_id = models.CharField(max_length=255, verbose_name='Flickr ID')
+ author_nsid = models.CharField(max_length=50, verbose_name='Author NSID')
+ machine_tag = models.BooleanField(default=False)
+ content_object = models.ForeignKey(FlickrPhoto,
+ related_name="%(app_label)s_%(class)s_items")
+
+ class Meta:
+ verbose_name = 'FlickrPhoto/Tag Relationship'
+
+
+class FlickrUser(models.Model):
+ """
+ A single person on Flickr.
+ """
+ nsid = models.CharField(max_length=50, help_text='eg, "35034346050@N01"')
+ username = models.CharField(max_length=255, help_text="eg, 'philgyford'")
+ realname = models.CharField(max_length=255,
+ help_text="eg, 'Phil Gyford'. Doesn't always exist.")
+ path_alias = models.CharField(max_length=50)
+ location = models.CharField(max_length=255)
+ description = models.TextField()
+
+ photos_url = models.URLField(verify_exists = False)
+ profile_url = models.URLField(verify_exists = False)
+ mobile_url = models.URLField(verify_exists = False)
+
+ iconserver = models.PositiveSmallIntegerField()
+ iconfarm = models.PositiveSmallIntegerField()
+
+ photos_first_date_taken = models.DateTimeField()
+ photos_first_date = models.DateTimeField()
+ photos_count = models.PositiveIntegerField()
+ photos_views = models.PositiveIntegerField()
+
+

0 comments on commit 32a3874

Please sign in to comment.