Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial Flickr app.

Models. Start of Admin. Not tested. Needs fetching code.
  • Loading branch information...
commit 32a3874be95ba6ea9d07ce9a9b13407a6af9240a 1 parent 20d93f7
Phil Gyford authored
10 archivr/managers.py
... ... @@ -0,0 +1,10 @@
  1 +from django.db import models
  2 +
  3 +
  4 +class VisibleManager(models.Manager):
  5 + """
  6 + All ArchivrItems that are not 'hidden'.
  7 + """
  8 + def get_query_set(self):
  9 + return super(VisibleManager, self).get_query_set().filter(hidden=False)
  10 +
36 archivr/migrations/0001_initial.py
... ... @@ -0,0 +1,36 @@
  1 +# -*- coding: utf-8 -*-
  2 +import datetime
  3 +from south.db import db
  4 +from south.v2 import SchemaMigration
  5 +from django.db import models
  6 +
  7 +
  8 +class Migration(SchemaMigration):
  9 +
  10 + def forwards(self, orm):
  11 + # Adding model 'ArchivrItem'
  12 + db.create_table('archivr_archivritem', (
  13 + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
  14 + ('order_date', self.gf('django.db.models.fields.DateTimeField')()),
  15 + ('hidden', self.gf('django.db.models.fields.BooleanField')(default=False)),
  16 + ('coordinate', self.gf('django.contrib.gis.db.models.fields.PointField')()),
  17 + ('item_genre', self.gf('django.db.models.fields.CharField')(default='', max_length=20)),
  18 + ))
  19 + db.send_create_signal('archivr', ['ArchivrItem'])
  20 +
  21 + def backwards(self, orm):
  22 + # Deleting model 'ArchivrItem'
  23 + db.delete_table('archivr_archivritem')
  24 +
  25 + models = {
  26 + 'archivr.archivritem': {
  27 + 'Meta': {'ordering': "('-order_date',)", 'object_name': 'ArchivrItem'},
  28 + 'coordinate': ('django.contrib.gis.db.models.fields.PointField', [], {}),
  29 + 'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  30 + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  31 + 'item_genre': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '20'}),
  32 + 'order_date': ('django.db.models.fields.DateTimeField', [], {})
  33 + }
  34 + }
  35 +
  36 + complete_apps = ['archivr']
29 archivr/migrations/0002_auto__chg_field_archivritem_coordinate.py
... ... @@ -0,0 +1,29 @@
  1 +# -*- coding: utf-8 -*-
  2 +import datetime
  3 +from south.db import db
  4 +from south.v2 import SchemaMigration
  5 +from django.db import models
  6 +
  7 +
  8 +class Migration(SchemaMigration):
  9 +
  10 + def forwards(self, orm):
  11 +
  12 + # Changing field 'ArchivrItem.coordinate'
  13 + db.alter_column('archivr_archivritem', 'coordinate', self.gf('django.contrib.gis.db.models.fields.PointField')(null=True))
  14 + def backwards(self, orm):
  15 +
  16 + # Changing field 'ArchivrItem.coordinate'
  17 + db.alter_column('archivr_archivritem', 'coordinate', self.gf('django.contrib.gis.db.models.fields.PointField')(default=''))
  18 + models = {
  19 + 'archivr.archivritem': {
  20 + 'Meta': {'ordering': "('-order_date',)", 'object_name': 'ArchivrItem'},
  21 + 'coordinate': ('django.contrib.gis.db.models.fields.PointField', [], {'null': 'True'}),
  22 + 'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  23 + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  24 + 'item_genre': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '20'}),
  25 + 'order_date': ('django.db.models.fields.DateTimeField', [], {})
  26 + }
  27 + }
  28 +
  29 + complete_apps = ['archivr']
0  archivr/migrations/__init__.py
No changes.
52 archivr/models.py
... ... @@ -1,3 +1,53 @@
1 1 from django.db import models
  2 +from django.contrib.gis.db import models
  3 +from django.contrib.gis.geos import Point
  4 +
  5 +from archivr.managers import VisibleManager
  6 +
  7 +# So we can group different models of the same type together.
  8 +# eg, fetch Flickr and Instagram photos together.
  9 +ARCHIVR_ITEM_GENRES = (
  10 + ('image', 'Image: Photos, etc.'),
  11 + ('status', 'Status: Tweet, etc.'),
  12 + ('link', 'Link: Pinboard, Delicious, etc.'),
  13 +)
  14 +
  15 +class ArchivrItem(models.Model):
  16 + """
  17 + The class that all Archivr classes representing "things" (eg, Tweet, Photo,
  18 + Link, etc) will be descended from.
  19 + Stores data that is common across all these items, and lets us fetch items of
  20 + different types together, ordered by date (for example).
  21 + """
  22 +
  23 + order_date = models.DateTimeField(
  24 + help_text="The date used for ordering the item")
  25 + hidden = models.BooleanField(default=False,
  26 + help_text="Is this item hidden from public view?")
  27 + coordinate = models.PointField(null=True,
  28 + help_text="Where this item is located")
  29 + item_genre = models.CharField(max_length=20, default='',
  30 + choices=ARCHIVR_ITEM_GENRES)
  31 +
  32 +
  33 + class Meta:
  34 + ordering = ('-order_date',)
  35 + get_latest_by = 'order_date'
  36 +
  37 + # ALL items.
  38 + objects = models.Manager()
  39 + # Items that haven't been marked as hidden.
  40 + visible_objects = VisibleManager()
  41 +
  42 +
  43 + def is_a(self, item_kind):
  44 + """
  45 + Test what kind of item this is.
  46 + eg `item.is_a('tweet')`
  47 + Note, this doesn't refer to the item_genre, which is a more general grouping.
  48 + """
  49 + if hasattr(self, str(item_kind)):
  50 + return True
  51 + else:
  52 + return False
2 53
3   -# Create your models here.
BIN  archivrflickr/.DS_Store
Binary file not shown
0  archivrflickr/__init__.py
No changes.
44 archivrflickr/admin.py
... ... @@ -0,0 +1,44 @@
  1 +from django.contrib import admin
  2 +from django.contrib import gis
  3 +from archivrflickr.models import FlickrPhoto
  4 +
  5 +
  6 +class FlickrPhotoTagInline(admin.TabularInline):
  7 + model = FlickrPhoto.tags.through
  8 + raw_id_fields = ('tag',)
  9 +
  10 +
  11 +class FlickrPhotoAdmin(admin.OSMGeoAdmin):
  12 + date_hierarchy = 'posted_date'
  13 + list_display = ('posted_date', 'show_thumb', 'title', 'owner', 'hidden',)
  14 + list_display_links = ('title', 'show_thumb',)
  15 + list_filter = ('posted_date',)
  16 + search_fields = ['title', 'description',]
  17 + inlines = [FlickrPhotoTagInline,]
  18 + exclude = ('tags',)
  19 + fieldsets = (
  20 + (None, {
  21 + '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',)
  22 + }),
  23 + ('URL etc.', {
  24 + 'fields': ('photopage_url', 'farm', 'server', 'secret', 'original_secret', 'original_format',)
  25 + }),
  26 + ('Image sizes', {
  27 + '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',)
  28 + }),
  29 + ('Geo', {
  30 + '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',)
  31 + }),
  32 + ('EXIF', {
  33 + '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',)
  34 + }),
  35 + )
  36 +
  37 + def show_thumb(self, instance):
  38 + return '<img src="%s" width="%s" height="%s" alt="Thumbnail" />' % (instance.get_thumbnail_url(), instance.thumbnail_width, instance.thumbnail_height)
  39 + show_thumb.allow_tags = True
  40 + show_thumb.short_description = ''
  41 +
  42 +admin.site.register(FlickrPhoto, FlickrPhotoAdmin)
  43 +
  44 +#gis.admin.site.register(FlickrPhoto, gis.admin.OSMGeoAdmin)
335 archivrflickr/migrations/0001_initial.py
... ... @@ -0,0 +1,335 @@
  1 +# -*- coding: utf-8 -*-
  2 +import datetime
  3 +from south.db import db
  4 +from south.v2 import SchemaMigration
  5 +from django.db import models
  6 +
  7 +
  8 +class Migration(SchemaMigration):
  9 +
  10 + def forwards(self, orm):
  11 + # Adding model 'FlickrFavorite'
  12 + db.create_table('archivrflickr_flickrfavorite', (
  13 + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
  14 + ('photo', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrPhoto'])),
  15 + ('favorite_list', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrFavoriteList'])),
  16 + ('date_faved', self.gf('django.db.models.fields.DateTimeField')()),
  17 + ))
  18 + db.send_create_signal('archivrflickr', ['FlickrFavorite'])
  19 +
  20 + # Adding model 'FlickrFavoriteList'
  21 + db.create_table('archivrflickr_flickrfavoritelist', (
  22 + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
  23 + ('owner', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrUser'])),
  24 + ('date_archived', self.gf('django.db.models.fields.DateTimeField')()),
  25 + ('primary', self.gf('django.db.models.fields.related.ForeignKey')(related_name='primary_in', null=True, to=orm['archivrflickr.FlickrPhoto'])),
  26 + ))
  27 + db.send_create_signal('archivrflickr', ['FlickrFavoriteList'])
  28 +
  29 + # Adding model 'FlickrPhoto'
  30 + db.create_table('archivrflickr_flickrphoto', (
  31 + ('archivritem_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['archivr.ArchivrItem'], unique=True, primary_key=True)),
  32 + ('flickr_id', self.gf('django.db.models.fields.CharField')(unique=True, max_length=50)),
  33 + ('owner', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrUser'])),
  34 + ('title', self.gf('django.db.models.fields.CharField')(max_length=255)),
  35 + ('description', self.gf('django.db.models.fields.TextField')(blank=True)),
  36 + ('posted_date', self.gf('django.db.models.fields.DateTimeField')()),
  37 + ('updated_date', self.gf('django.db.models.fields.DateTimeField')()),
  38 + ('taken_date', self.gf('django.db.models.fields.DateTimeField')()),
  39 + ('taken_granularity', self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=0)),
  40 + ('comments', self.gf('django.db.models.fields.PositiveIntegerField')(default=0)),
  41 + ('visibility_is_public', self.gf('django.db.models.fields.BooleanField')(default=False)),
  42 + ('visibility_is_friend', self.gf('django.db.models.fields.BooleanField')(default=False)),
  43 + ('visibility_is_family', self.gf('django.db.models.fields.BooleanField')(default=False)),
  44 + ('photopage_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
  45 + ('farm', self.gf('django.db.models.fields.PositiveSmallIntegerField')()),
  46 + ('server', self.gf('django.db.models.fields.PositiveSmallIntegerField')()),
  47 + ('secret', self.gf('django.db.models.fields.CharField')(max_length=10)),
  48 + ('original_secret', self.gf('django.db.models.fields.CharField')(max_length=10, blank=True)),
  49 + ('original_format', self.gf('django.db.models.fields.CharField')(max_length=10, blank=True)),
  50 + ('large_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  51 + ('large_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  52 + ('largesquare_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  53 + ('largesquare_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  54 + ('medium640_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  55 + ('medium640_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  56 + ('medium800_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  57 + ('medium800_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  58 + ('medium_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  59 + ('medium_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  60 + ('original_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  61 + ('original_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  62 + ('small320_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  63 + ('small320_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  64 + ('small_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  65 + ('small_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  66 + ('square_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  67 + ('square_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  68 + ('thumbnail_height', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  69 + ('thumbnail_width', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True)),
  70 + ('license', self.gf('django.db.models.fields.CharField')(max_length=50)),
  71 + ('geo_latitude', self.gf('django.db.models.fields.FloatField')(null=True, blank=True)),
  72 + ('geo_longitude', self.gf('django.db.models.fields.FloatField')(null=True, blank=True)),
  73 + ('geo_accuracy', self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True, blank=True)),
  74 + ('geo_county', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  75 + ('geo_county_place_id', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
  76 + ('geo_county_woe_id', self.gf('django.db.models.fields.PositiveIntegerField')(max_length=50, blank=True)),
  77 + ('geo_country', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  78 + ('geo_country_place_id', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
  79 + ('geo_country_woe_id', self.gf('django.db.models.fields.PositiveIntegerField')(max_length=50, blank=True)),
  80 + ('geo_locality', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  81 + ('geo_locality_place_id', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
  82 + ('geo_locality_woe_id', self.gf('django.db.models.fields.PositiveIntegerField')(max_length=50, blank=True)),
  83 + ('geo_region', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  84 + ('geo_region_place_id', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
  85 + ('geo_region_woe_id', self.gf('django.db.models.fields.PositiveIntegerField')(max_length=50, blank=True)),
  86 + ('exif_aperture', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  87 + ('exif_color_space', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  88 + ('exif_exposure', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  89 + ('exif_flash', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  90 + ('exif_focal_length', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  91 + ('exif_iso', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  92 + ('exif_make', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  93 + ('exif_metering_mode', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  94 + ('exif_model', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  95 + ('exif_orientation', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  96 + ('exif_software', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
  97 + ))
  98 + db.send_create_signal('archivrflickr', ['FlickrPhoto'])
  99 +
  100 + # Adding model 'FlickrPhotoComment'
  101 + db.create_table('archivrflickr_flickrphotocomment', (
  102 + ('flickr_id', self.gf('django.db.models.fields.CharField')(max_length=128, primary_key=True)),
  103 + ('photo', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrPhoto'])),
  104 + ('author', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrUser'])),
  105 + ('pub_date', self.gf('django.db.models.fields.DateTimeField')()),
  106 + ('permanent_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
  107 + ('comment', self.gf('django.db.models.fields.TextField')()),
  108 + ))
  109 + db.send_create_signal('archivrflickr', ['FlickrPhotoComment'])
  110 +
  111 + # Adding model 'FlickrPhotoset'
  112 + db.create_table('archivrflickr_flickrphotoset', (
  113 + ('flickr_id', self.gf('django.db.models.fields.CharField')(max_length=50, primary_key=True)),
  114 + ('primary', self.gf('django.db.models.fields.related.ForeignKey')(default=None, related_name='primary_photo_set', null=True, to=orm['archivrflickr.FlickrPhoto'])),
  115 + ('owner', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archivrflickr.FlickrUser'])),
  116 + ('title', self.gf('django.db.models.fields.CharField')(max_length=200)),
  117 + ('description', self.gf('django.db.models.fields.TextField')(blank=True)),
  118 + ('order', self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=0)),
  119 + ))
  120 + db.send_create_signal('archivrflickr', ['FlickrPhotoset'])
  121 +
  122 + # Adding M2M table for field photos on 'FlickrPhotoset'
  123 + db.create_table('archivrflickr_flickrphotoset_photos', (
  124 + ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
  125 + ('flickrphotoset', models.ForeignKey(orm['archivrflickr.flickrphotoset'], null=False)),
  126 + ('flickrphoto', models.ForeignKey(orm['archivrflickr.flickrphoto'], null=False))
  127 + ))
  128 + db.create_unique('archivrflickr_flickrphotoset_photos', ['flickrphotoset_id', 'flickrphoto_id'])
  129 +
  130 + # Adding model 'FlickrPhotoTag'
  131 + db.create_table('archivrflickr_flickrphototag', (
  132 + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
  133 + ('tag', self.gf('django.db.models.fields.related.ForeignKey')(related_name='archivrflickr_flickrphototag_items', to=orm['taggit.Tag'])),
  134 + ('flickr_id', self.gf('django.db.models.fields.CharField')(max_length=255)),
  135 + ('author_nsid', self.gf('django.db.models.fields.CharField')(max_length=50)),
  136 + ('machine_tag', self.gf('django.db.models.fields.BooleanField')(default=False)),
  137 + ('content_object', self.gf('django.db.models.fields.related.ForeignKey')(related_name='archivrflickr_flickrphototag_items', to=orm['archivrflickr.FlickrPhoto'])),
  138 + ))
  139 + db.send_create_signal('archivrflickr', ['FlickrPhotoTag'])
  140 +
  141 + # Adding model 'FlickrUser'
  142 + db.create_table('archivrflickr_flickruser', (
  143 + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
  144 + ('nsid', self.gf('django.db.models.fields.CharField')(max_length=50)),
  145 + ('username', self.gf('django.db.models.fields.CharField')(max_length=255)),
  146 + ('realname', self.gf('django.db.models.fields.CharField')(max_length=255)),
  147 + ('path_alias', self.gf('django.db.models.fields.CharField')(max_length=50)),
  148 + ('location', self.gf('django.db.models.fields.CharField')(max_length=255)),
  149 + ('description', self.gf('django.db.models.fields.TextField')()),
  150 + ('photos_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
  151 + ('profile_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
  152 + ('mobile_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
  153 + ('iconserver', self.gf('django.db.models.fields.PositiveSmallIntegerField')()),
  154 + ('iconfarm', self.gf('django.db.models.fields.PositiveSmallIntegerField')()),
  155 + ('photos_first_date_taken', self.gf('django.db.models.fields.DateTimeField')()),
  156 + ('photos_first_date', self.gf('django.db.models.fields.DateTimeField')()),
  157 + ('photos_count', self.gf('django.db.models.fields.PositiveIntegerField')()),
  158 + ('photos_views', self.gf('django.db.models.fields.PositiveIntegerField')()),
  159 + ))
  160 + db.send_create_signal('archivrflickr', ['FlickrUser'])
  161 +
  162 + def backwards(self, orm):
  163 + # Deleting model 'FlickrFavorite'
  164 + db.delete_table('archivrflickr_flickrfavorite')
  165 +
  166 + # Deleting model 'FlickrFavoriteList'
  167 + db.delete_table('archivrflickr_flickrfavoritelist')
  168 +
  169 + # Deleting model 'FlickrPhoto'
  170 + db.delete_table('archivrflickr_flickrphoto')
  171 +
  172 + # Deleting model 'FlickrPhotoComment'
  173 + db.delete_table('archivrflickr_flickrphotocomment')
  174 +
  175 + # Deleting model 'FlickrPhotoset'
  176 + db.delete_table('archivrflickr_flickrphotoset')
  177 +
  178 + # Removing M2M table for field photos on 'FlickrPhotoset'
  179 + db.delete_table('archivrflickr_flickrphotoset_photos')
  180 +
  181 + # Deleting model 'FlickrPhotoTag'
  182 + db.delete_table('archivrflickr_flickrphototag')
  183 +
  184 + # Deleting model 'FlickrUser'
  185 + db.delete_table('archivrflickr_flickruser')
  186 +
  187 + models = {
  188 + 'archivr.archivritem': {
  189 + 'Meta': {'ordering': "('-order_date',)", 'object_name': 'ArchivrItem'},
  190 + 'coordinate': ('django.contrib.gis.db.models.fields.PointField', [], {}),
  191 + 'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  192 + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  193 + 'item_genre': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '20'}),
  194 + 'order_date': ('django.db.models.fields.DateTimeField', [], {})
  195 + },
  196 + 'archivrflickr.flickrfavorite': {
  197 + 'Meta': {'object_name': 'FlickrFavorite'},
  198 + 'date_faved': ('django.db.models.fields.DateTimeField', [], {}),
  199 + 'favorite_list': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrFavoriteList']"}),
  200 + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  201 + 'photo': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrPhoto']"})
  202 + },
  203 + 'archivrflickr.flickrfavoritelist': {
  204 + 'Meta': {'object_name': 'FlickrFavoriteList'},
  205 + 'date_archived': ('django.db.models.fields.DateTimeField', [], {}),
  206 + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  207 + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrUser']"}),
  208 + 'photos': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['archivrflickr.FlickrPhoto']", 'through': "orm['archivrflickr.FlickrFavorite']", 'symmetrical': 'False'}),
  209 + 'primary': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'primary_in'", 'null': 'True', 'to': "orm['archivrflickr.FlickrPhoto']"})
  210 + },
  211 + 'archivrflickr.flickrphoto': {
  212 + 'Meta': {'ordering': "('-taken_date',)", 'object_name': 'FlickrPhoto', '_ormbases': ['archivr.ArchivrItem']},
  213 + 'archivritem_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['archivr.ArchivrItem']", 'unique': 'True', 'primary_key': 'True'}),
  214 + 'comments': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
  215 + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
  216 + 'exif_aperture': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  217 + 'exif_color_space': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  218 + 'exif_exposure': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  219 + 'exif_flash': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  220 + 'exif_focal_length': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  221 + 'exif_iso': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  222 + 'exif_make': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  223 + 'exif_metering_mode': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  224 + 'exif_model': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  225 + 'exif_orientation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  226 + 'exif_software': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  227 + 'farm': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
  228 + 'flickr_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50'}),
  229 + 'geo_accuracy': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
  230 + 'geo_country': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  231 + 'geo_country_place_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
  232 + 'geo_country_woe_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '50', 'blank': 'True'}),
  233 + 'geo_county': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  234 + 'geo_county_place_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
  235 + 'geo_county_woe_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '50', 'blank': 'True'}),
  236 + 'geo_latitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
  237 + 'geo_locality': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  238 + 'geo_locality_place_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
  239 + 'geo_locality_woe_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '50', 'blank': 'True'}),
  240 + 'geo_longitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
  241 + 'geo_region': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
  242 + 'geo_region_place_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
  243 + 'geo_region_woe_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '50', 'blank': 'True'}),
  244 + 'large_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  245 + 'large_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  246 + 'largesquare_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  247 + 'largesquare_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  248 + 'license': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
  249 + 'medium640_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  250 + 'medium640_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  251 + 'medium800_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  252 + 'medium800_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  253 + 'medium_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  254 + 'medium_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  255 + 'original_format': ('django.db.models.fields.CharField', [], {'max_length': '10', 'blank': 'True'}),
  256 + 'original_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  257 + 'original_secret': ('django.db.models.fields.CharField', [], {'max_length': '10', 'blank': 'True'}),
  258 + 'original_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  259 + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrUser']"}),
  260 + 'photopage_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
  261 + 'posted_date': ('django.db.models.fields.DateTimeField', [], {}),
  262 + 'secret': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
  263 + 'server': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
  264 + 'small320_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  265 + 'small320_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  266 + 'small_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  267 + 'small_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  268 + 'square_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  269 + 'square_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  270 + 'taken_date': ('django.db.models.fields.DateTimeField', [], {}),
  271 + 'taken_granularity': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '0'}),
  272 + 'thumbnail_height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  273 + 'thumbnail_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
  274 + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
  275 + 'updated_date': ('django.db.models.fields.DateTimeField', [], {}),
  276 + 'visibility_is_family': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  277 + 'visibility_is_friend': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  278 + 'visibility_is_public': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
  279 + },
  280 + 'archivrflickr.flickrphotocomment': {
  281 + 'Meta': {'ordering': "('pub_date',)", 'object_name': 'FlickrPhotoComment'},
  282 + 'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrUser']"}),
  283 + 'comment': ('django.db.models.fields.TextField', [], {}),
  284 + 'flickr_id': ('django.db.models.fields.CharField', [], {'max_length': '128', 'primary_key': 'True'}),
  285 + 'permanent_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
  286 + 'photo': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrPhoto']"}),
  287 + 'pub_date': ('django.db.models.fields.DateTimeField', [], {})
  288 + },
  289 + 'archivrflickr.flickrphotoset': {
  290 + 'Meta': {'ordering': "('order',)", 'object_name': 'FlickrPhotoset'},
  291 + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
  292 + 'flickr_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'primary_key': 'True'}),
  293 + 'order': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '0'}),
  294 + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archivrflickr.FlickrUser']"}),
  295 + 'photos': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['archivrflickr.FlickrPhoto']", 'symmetrical': 'False'}),
  296 + 'primary': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'related_name': "'primary_photo_set'", 'null': 'True', 'to': "orm['archivrflickr.FlickrPhoto']"}),
  297 + 'title': ('django.db.models.fields.CharField', [], {'max_length': '200'})
  298 + },
  299 + 'archivrflickr.flickrphototag': {
  300 + 'Meta': {'object_name': 'FlickrPhotoTag'},
  301 + 'author_nsid': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
  302 + 'content_object': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'archivrflickr_flickrphototag_items'", 'to': "orm['archivrflickr.FlickrPhoto']"}),
  303 + 'flickr_id': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
  304 + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  305 + 'machine_tag': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  306 + 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'archivrflickr_flickrphototag_items'", 'to': "orm['taggit.Tag']"})
  307 + },
  308 + 'archivrflickr.flickruser': {
  309 + 'Meta': {'object_name': 'FlickrUser'},
  310 + 'description': ('django.db.models.fields.TextField', [], {}),
  311 + 'iconfarm': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
  312 + 'iconserver': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
  313 + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  314 + 'location': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
  315 + 'mobile_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
  316 + 'nsid': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
  317 + 'path_alias': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
  318 + 'photos_count': ('django.db.models.fields.PositiveIntegerField', [], {}),
  319 + 'photos_first_date': ('django.db.models.fields.DateTimeField', [], {}),
  320 + 'photos_first_date_taken': ('django.db.models.fields.DateTimeField', [], {}),
  321 + 'photos_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
  322 + 'photos_views': ('django.db.models.fields.PositiveIntegerField', [], {}),
  323 + 'profile_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
  324 + 'realname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
  325 + 'username': ('django.db.models.fields.CharField', [], {'max_length': '255'})
  326 + },
  327 + 'taggit.tag': {
  328 + 'Meta': {'object_name': 'Tag'},
  329 + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  330 + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
  331 + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'})
  332 + }
  333 + }
  334 +
  335 + complete_apps = ['archivrflickr']
0  archivrflickr/migrations/__init__.py
No changes.
405 archivrflickr/models.py
... ... @@ -0,0 +1,405 @@
  1 +from django.db import models
  2 +from django.utils.html import strip_tags
  3 +from django.utils.text import truncate_words
  4 +from django.utils.translation import ugettext_lazy as _
  5 +
  6 +from taggit.managers import TaggableManager
  7 +from taggit.models import TaggedItemBase
  8 +
  9 +from archivr.models import ArchivrItem
  10 +from archivr.managers import *
  11 +
  12 +
  13 +class FlickrFavorite(models.Model):
  14 + """
  15 + Linking FlickrPhotos into a FlickrFavoriteList, so that we can capture the
  16 + date_faved time for each one.
  17 + """
  18 + photo = models.ForeignKey('FlickrPhoto')
  19 + favorite_list = models.ForeignKey('FlickrFavoriteList')
  20 + date_faved = models.DateTimeField()
  21 +
  22 +
  23 +class FlickrFavoriteList(models.Model):
  24 + owner = models.ForeignKey('FlickrUser')
  25 + date_archived = models.DateTimeField()
  26 + photos = models.ManyToManyField('FlickrPhoto', through='FlickrFavorite')
  27 + primary = models.ForeignKey('FlickrPhoto', related_name='primary_in', null=True)
  28 +
  29 + def numPhotos(self):
  30 + return len(self.photo_list.objects.all())
  31 +
  32 + def __unicode__(self):
  33 + return u"%s's favorite photos" % self.owner
  34 +
  35 +
  36 +class FlickrPhoto(ArchivrItem):
  37 + """
  38 + A single photo on Flickr.
  39 + """
  40 +
  41 + FLICKR_LICENSES = (
  42 + ('0', 'All Rights Reserved'),
  43 + ('1', 'Attribution-NonCommercial-ShareAlike License'),
  44 + ('2', 'Attribution-NonCommercial License'),
  45 + ('3', 'Attribution-NonCommercial-NoDerivs License'),
  46 + ('4', 'Attribution License'),
  47 + ('5', 'Attribution-ShareAlike License'),
  48 + ('6', 'Attribution-NoDerivs License'),
  49 + ('7', 'No known copyright restrictions'),
  50 + )
  51 +
  52 + # Granularity: http://www.flickr.com/services/api/misc.dates.html
  53 + FLICKR_DATE_GRANULARITIES = (
  54 + (0, 'Y-m-d H:i:s'),
  55 + (4, 'Y-m'),
  56 + (6, 'Y'),
  57 + (8, 'Circa...'),
  58 + )
  59 +
  60 + # Data from Flickr:
  61 + flickr_id = models.CharField(max_length=50, unique=True,
  62 + help_text="ID of this photo on Flickr.")
  63 + owner = models.ForeignKey('FlickrUser')
  64 + title = models.CharField(max_length=255)
  65 + description = models.TextField(blank=True)
  66 +
  67 + posted_date = models.DateTimeField(help_text="UTC")
  68 + updated_date = models.DateTimeField(help_text="UTC")
  69 + taken_date = models.DateTimeField(
  70 + help_text="In Flickr user's timezone (unknown).")
  71 + taken_granularity = models.PositiveSmallIntegerField(default=0,
  72 + choices=FLICKR_DATE_GRANULARITIES)
  73 +
  74 + comments = models.PositiveIntegerField(default=0)
  75 + license = models.CharField(max_length=50, choices=FLICKR_LICENSES)
  76 + visibility_is_public = models.BooleanField(default=False)
  77 + visibility_is_friend = models.BooleanField(default=False)
  78 + visibility_is_family = models.BooleanField(default=False)
  79 +
  80 + photopage_url = models.URLField(verify_exists=False)
  81 + farm = models.PositiveSmallIntegerField()
  82 + server = models.PositiveSmallIntegerField()
  83 + secret = models.CharField(max_length=10)
  84 + original_secret = models.CharField(max_length=10, blank=True)
  85 + original_format = models.CharField(max_length=10, blank=True)
  86 +
  87 + large_height = models.PositiveSmallIntegerField(null=True)
  88 + large_width = models.PositiveSmallIntegerField(null=True)
  89 + largesquare_height = models.PositiveSmallIntegerField(null=True)
  90 + largesquare_width = models.PositiveSmallIntegerField(null=True)
  91 + medium640_height = models.PositiveSmallIntegerField(null=True)
  92 + medium640_width = models.PositiveSmallIntegerField(null=True)
  93 + medium800_height = models.PositiveSmallIntegerField(null=True)
  94 + medium800_width = models.PositiveSmallIntegerField(null=True)
  95 + medium_height = models.PositiveSmallIntegerField(null=True)
  96 + medium_width = models.PositiveSmallIntegerField(null=True)
  97 + original_height = models.PositiveSmallIntegerField(null=True)
  98 + original_width = models.PositiveSmallIntegerField(null=True)
  99 + small320_height = models.PositiveSmallIntegerField(null=True)
  100 + small320_width = models.PositiveSmallIntegerField(null=True)
  101 + small_height = models.PositiveSmallIntegerField(null=True)
  102 + small_width = models.PositiveSmallIntegerField(null=True)
  103 + square_height = models.PositiveSmallIntegerField(null=True)
  104 + square_width = models.PositiveSmallIntegerField(null=True)
  105 + thumbnail_height = models.PositiveSmallIntegerField(null=True)
  106 + thumbnail_width = models.PositiveSmallIntegerField(null=True)
  107 +
  108 + geo_latitude = models.FloatField(null=True, blank=True)
  109 + geo_longitude = models.FloatField(null=True, blank=True)
  110 + geo_accuracy = models.PositiveSmallIntegerField(null=True, blank=True)
  111 + geo_county = models.CharField(max_length=255, blank=True)
  112 + geo_county_place_id = models.CharField(max_length=50, blank=True)
  113 + geo_county_woe_id = models.PositiveIntegerField(max_length=50, blank=True)
  114 + geo_country = models.CharField(max_length=255, blank=True)
  115 + geo_country_place_id = models.CharField(max_length=50, blank=True)
  116 + geo_country_woe_id = models.PositiveIntegerField(max_length=50, blank=True)
  117 + geo_locality = models.CharField(max_length=255, blank=True)
  118 + geo_locality_place_id = models.CharField(max_length=50, blank=True)
  119 + geo_locality_woe_id = models.PositiveIntegerField(max_length=50, blank=True)
  120 + geo_region = models.CharField(max_length=255, blank=True)
  121 + geo_region_place_id = models.CharField(max_length=50, blank=True)
  122 + geo_region_woe_id = models.PositiveIntegerField(max_length=50, blank=True)
  123 +
  124 + exif_aperture = models.CharField(max_length=255, blank=True)
  125 + exif_color_space = models.CharField(max_length=255, blank=True)
  126 + exif_exposure = models.CharField(max_length=255, blank=True)
  127 + exif_flash = models.CharField(max_length=255, blank=True)
  128 + exif_focal_length = models.CharField(max_length=255, blank=True)
  129 + exif_iso = models.CharField(max_length=255, blank=True)
  130 + exif_make = models.CharField(max_length=255, blank=True)
  131 + exif_metering_mode = models.CharField(max_length=255, blank=True)
  132 + exif_model = models.CharField(max_length=255, blank=True)
  133 + exif_orientation = models.CharField(max_length=255, blank=True)
  134 + exif_software = models.CharField(max_length=255, blank=True)
  135 +
  136 + tags = TaggableManager(blank=True, through='FlickrPhotoTag')
  137 +
  138 + class Meta:
  139 + ordering = ('-taken_date',)
  140 + get_latest_by = 'posted_date'
  141 +
  142 + def __unicode__(self):
  143 + return u'%s' % self.title
  144 +
  145 + @models.permalink
  146 + def get_absolute_url(self):
  147 + return ('flickr_photo_detail', (), { 'flickr_id': self.flickr_id, })
  148 +
  149 + # ALL FlickrPhotos.
  150 + objects = models.Manager()
  151 + # FlickrPhotos that haven't been marked as hidden.
  152 + visible_objects = VisibleManager()
  153 +
  154 + def _get_photo_url_helper(self, size, secret=None, extension='jpg'):
  155 + size = size and '_%s' % size or ''
  156 + if secret is None:
  157 + secret = self.secret
  158 + return u'http://farm%s.static.flickr.com/%s/%s_%s%s.%s' % (
  159 + self.farm, self.server, self.flickr_id, secret, size, extension)
  160 +
  161 + def get_square_url(self):
  162 + return self._get_photo_url_helper('s')
  163 +
  164 + def get_thumbnail_url(self):
  165 + return self._get_photo_url_helper('t')
  166 +
  167 + def get_small_url(self):
  168 + return self._get_photo_url_helper('m')
  169 +
  170 + def get_small320_url(self):
  171 + if self.has_small320_photo:
  172 + return self._get_photo_url_helper('n')
  173 + return self.get_original_url()
  174 +
  175 + def get_medium_url(self):
  176 + if self.has_medium_photo:
  177 + return self._get_photo_url_helper('')
  178 + return self.get_original_url()
  179 +
  180 + def get_medium640_url(self):
  181 + if self.has_medium640_photo:
  182 + return self._get_photo_url_helper('z')
  183 + return self.get_original_url()
  184 +
  185 + def get_medium800_url(self):
  186 + if self.has_medium800_photo:
  187 + return self._get_photo_url_helper('c')
  188 + return self.get_original_url()
  189 +
  190 + def get_large_url(self):
  191 + if self.has_large_photo:
  192 + return self._get_photo_url_helper('b')
  193 + return self.get_original_url()
  194 +
  195 + def get_largesquare_url(self):
  196 + if self.has_largesquare_photo:
  197 + return self._get_photo_url_helper('q')
  198 + return self.get_original_url()
  199 +
  200 + def get_original_url(self):
  201 + if self.original_secret:
  202 + return self._get_photo_url_helper('o', secret=self.original_secret,
  203 + extension=self.original_format)
  204 + return self._get_photo_url_helper('o', extension=self.original_format)
  205 +
  206 + @property
  207 + def has_small320_photo(self):
  208 + if self.small320_width is not None:
  209 + return True
  210 + return False
  211 +
  212 + @property
  213 + def has_medium_photo(self):
  214 + if self.medium_width is not None:
  215 + return True
  216 + return False
  217 +
  218 + @property
  219 + def has_medium640_photo(self):
  220 + if self.medium640_width is not None:
  221 + return True
  222 + return False
  223 +
  224 + @property
  225 + def has_medium800_photo(self):
  226 + if self.medium800_width is not None:
  227 + return True
  228 + return False
  229 +
  230 + @property
  231 + def has_large_photo(self):
  232 + if self.large_width is not None:
  233 + return True
  234 + return False
  235 +
  236 + @property
  237 + def has_largesquare_photo(self):
  238 + if self.largesquare_width is not None:
  239 + return True
  240 + return False
  241 +
  242 + @property
  243 + def has_original_photo(self):
  244 + if self.original_width is not None:
  245 + return True
  246 + return False
  247 +
  248 + def _next_previous_helper(self, direction, photoset):
  249 + order = direction == 'next' and 'taken_date' or '-taken_date'
  250 + filter = direction == 'next' and 'gt' or 'lt'
  251 + try:
  252 + return self.photoset_set.get(pk=photoset.pk).photos.filter(
  253 + **{'taken_date__%s' % filter: self.taken_date}
  254 + ).order_by(order)[0]
  255 + except IndexError:
  256 + return None
  257 +
  258 + def get_next_in_set(self, *args, **kwargs):
  259 + """
  260 + Returns the next Entry with "live" status by ``pub_date``, if
  261 + there is one, or ``None`` if there isn't.
  262 +
  263 + In public-facing templates, use this method instead of
  264 + ``get_next_by_pub_date``, because ``get_next_by_pub_date``
  265 + does not differentiate entry status.
  266 +
  267 + """
  268 + return self._next_previous_helper('next', *args, **kwargs)
  269 +
  270 + def get_previous_in_set(self, *args, **kwargs):
  271 + """
  272 + Returns the previous Entry with "live" status by ``pub_date``,
  273 + if there is one, or ``None`` if there isn't.
  274 +
  275 + In public-facing templates, use this method instead of
  276 + ``get_previous_by_pub_date``, because
  277 + ``get_previous_by_pub_date`` does not differentiate entry
  278 + status..
  279 +
  280 + """
  281 + return self._next_previous_helper('previous', *args, **kwargs)
  282 +
  283 +
  284 +class FlickrPhotoComment(models.Model):
  285 + """
  286 + Describes a single comment on a ``FlickrPhoto``.
  287 + """
  288 + flickr_id = models.CharField(primary_key=True, max_length=128)
  289 + photo = models.ForeignKey(FlickrPhoto)
  290 + author = models.ForeignKey('FlickrUser')
  291 + pub_date = models.DateTimeField()
  292 + permanent_url = models.URLField(verify_exists=False)
  293 + comment = models.TextField()
  294 +
  295 + class Meta:
  296 + ordering = ('pub_date',)
  297 +
  298 + def __unicode__(self):
  299 + return _(u"%(author)s said: %(comment)s") % {
  300 + 'author': self.author, 'comment': self.get_short_comment(4)}
  301 +
  302 + def get_absolute_url(self):
  303 + return self.permanent_url
  304 +
  305 + def get_short_comment(self, num=6):
  306 + return truncate_words(strip_tags(self.comment), num)
  307 + get_short_comment.short_description = _(u'comment')
  308 +
  309 +
  310 +class FlickrPhotoset(models.Model):
  311 + """
  312 + One photoset and its list of ``FlickrPhotos``.
  313 + """
  314 +
  315 + flickr_id = models.CharField(primary_key=True, max_length=50)
  316 + primary = models.ForeignKey(FlickrPhoto, null=True, default=None,
  317 + related_name='primary_photo_set')
  318 + owner = models.ForeignKey('FlickrUser')
  319 + title = models.CharField(max_length=200)
  320 + description = models.TextField(blank=True)
  321 + order = models.PositiveSmallIntegerField(default=0)
  322 + photos = models.ManyToManyField(FlickrPhoto)
  323 +
  324 + class Meta:
  325 + ordering = ('order',)
  326 +
  327 + def __unicode__(self):
  328 + return u"%s photoset by %s" % (self.title, self.owner)
  329 +
  330 + @models.permalink
  331 + def get_absolute_url(self):
  332 + return ('photoset_detail', (), { 'flickr_id': self.flickr_id })
  333 +
  334 + def highlight(self):
  335 + """
  336 + Return the highlight image of this photo set.
  337 +
  338 + In case there isn't a ``primary`` image set, the first one is
  339 + selected. (If this causes a ``IndexError``, ``None`` is
  340 + returned.)
  341 + """
  342 + if self.primary is not None:
  343 + return self.primary
  344 + try:
  345 + return self.photos.all()[0]
  346 + except IndexError:
  347 + return None
  348 +
  349 + def get_time_period(self):
  350 + """
  351 + Return dict with start and end of this photo set.
  352 +
  353 + Gets ``taken_date`` of first and last ``FlickrPhoto`` and returns
  354 + results as dict::
  355 +
  356 + { 'start': datetime.datetime, 'end': datetime.datetime }
  357 + """
  358 + start_photo = self.photos.order_by('taken_date')[0]
  359 + end_photo = self.photos.order_by('-taken_date')[0]
  360 + if start_photo.taken_date and end_photo.taken_date:
  361 + return {'start': start_photo.taken_date, 'end': end_photo.taken_date}
  362 + return {'start': start_photo.posted_date, 'end': end_photo.posted_date}
  363 +
  364 +
  365 +class FlickrPhotoTag(TaggedItemBase):
  366 + """
  367 + Describes the relationship between a django-taggit Tag and a FlickrPhoto.
  368 + Flickr has various fields which are unique to this relationship, rather
  369 + than the Tag itself.
  370 + """
  371 + flickr_id = models.CharField(max_length=255, verbose_name='Flickr ID')
  372 + author_nsid = models.CharField(max_length=50, verbose_name='Author NSID')
  373 + machine_tag = models.BooleanField(default=False)
  374 + content_object = models.ForeignKey(FlickrPhoto,
  375 + related_name="%(app_label)s_%(class)s_items")
  376 +
  377 + class Meta:
  378 + verbose_name = 'FlickrPhoto/Tag Relationship'
  379 +
  380 +
  381 +class FlickrUser(models.Model):
  382 + """
  383 + A single person on Flickr.
  384 + """
  385 + nsid = models.CharField(max_length=50, help_text='eg, "35034346050@N01"')
  386 + username = models.CharField(max_length=255, help_text="eg, 'philgyford'")
  387 + realname = models.CharField(max_length=255,
  388 + help_text="eg, 'Phil Gyford'. Doesn't always exist.")
  389 + path_alias = models.CharField(max_length=50)
  390 + location = models.CharField(max_length=255)
  391 + description = models.TextField()
  392 +
  393 + photos_url = models.URLField(verify_exists = False)
  394 + profile_url = models.URLField(verify_exists = False)
  395 + mobile_url = models.URLField(verify_exists = False)
  396 +
  397 + iconserver = models.PositiveSmallIntegerField()
  398 + iconfarm = models.PositiveSmallIntegerField()
  399 +
  400 + photos_first_date_taken = models.DateTimeField()
  401 + photos_first_date = models.DateTimeField()
  402 + photos_count = models.PositiveIntegerField()
  403 + photos_views = models.PositiveIntegerField()
  404 +
  405 +

0 comments on commit 32a3874

Please sign in to comment.
Something went wrong with that request. Please try again.