From cd3e03effc20790582d5ae6e8f2c1597c49ce31e Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 30 Mar 2011 15:06:09 -0400 Subject: [PATCH] Made uuid of event autogenerated. Fully resolves issue #119. Also had to reset julian migrations again. --- contrib/julian/admin.py | 2 +- contrib/julian/feedgenerator.py | 7 ------- contrib/julian/migrations/0001_initial.py | 14 ++++++++++---- contrib/julian/models.py | 19 +++++++++++++++---- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/contrib/julian/admin.py b/contrib/julian/admin.py index 72bdef7..8f104e2 100644 --- a/contrib/julian/admin.py +++ b/contrib/julian/admin.py @@ -19,7 +19,7 @@ class EventAdmin(EntityAdmin): 'fields': (('start_date', 'start_time'), ('end_date', 'end_time'),), }), ('Advanced', { - 'fields': ('parent_event', 'uuid',), + 'fields': ('parent_event', 'site',), 'classes': COLLAPSE_CLASSES }) ) diff --git a/contrib/julian/feedgenerator.py b/contrib/julian/feedgenerator.py index 19e959d..819a273 100644 --- a/contrib/julian/feedgenerator.py +++ b/contrib/julian/feedgenerator.py @@ -41,13 +41,6 @@ ITEM_ICAL_MAP = { class ICalendarFeed(SyndicationFeed): - #def __init__(self, title, link, description, language=None, author_email=None, - # author_name=None, author_link=None, subtitle=None, categories=None, - # feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs): - # super(ICalendarFeed, self).__init__(title, link, description, language, - # author_email, author_name, author_link, subtitle, categories, - # feed_url, feed_copyright, feed_guid, ttl, **kwargs) - # mime_type = 'text/calendar' def add_item(self, *args, **kwargs): diff --git a/contrib/julian/migrations/0001_initial.py b/contrib/julian/migrations/0001_initial.py index e52b74f..3236095 100644 --- a/contrib/julian/migrations/0001_initial.py +++ b/contrib/julian/migrations/0001_initial.py @@ -32,10 +32,13 @@ class Migration(SchemaMigration): ('owner', self.gf('django.db.models.fields.related.ForeignKey')(related_name='owned_events', to=orm['auth.User'])), ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), ('last_modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), - ('uuid', self.gf('django.db.models.fields.TextField')()), + ('site', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['sites.Site'])), )) db.send_create_signal('julian', ['Event']) + # Adding unique constraint on 'Event', fields ['site', 'created'] + db.create_unique('julian_event', ['site_id', 'created']) + # Adding M2M table for field tags on 'Event' db.create_table('julian_event_tags', ( ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), @@ -98,6 +101,9 @@ class Migration(SchemaMigration): # Removing unique constraint on 'Calendar', fields ['name', 'site', 'language'] db.delete_unique('julian_calendar', ['name', 'site_id', 'language']) + # Removing unique constraint on 'Event', fields ['site', 'created'] + db.delete_unique('julian_event', ['site_id', 'created']) + # Deleting model 'Location' db.delete_table('julian_location') @@ -189,7 +195,7 @@ class Migration(SchemaMigration): 'timespan_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'calendar_timespan_related'", 'null': 'True', 'to': "orm['philo.Page']"}) }, 'julian.event': { - 'Meta': {'object_name': 'Event'}, + 'Meta': {'unique_together': "(('site', 'created'),)", 'object_name': 'Event'}, 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'description': ('philo.models.fields.TemplateField', [], {}), 'end_date': ('django.db.models.fields.DateField', [], {}), @@ -201,11 +207,11 @@ class Migration(SchemaMigration): 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), 'owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'owned_events'", 'to': "orm['auth.User']"}), 'parent_event': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['julian.Event']", 'null': 'True', 'blank': 'True'}), + 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}), 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}), 'start_date': ('django.db.models.fields.DateField', [], {}), 'start_time': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}), - 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'events'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['philo.Tag']"}), - 'uuid': ('django.db.models.fields.TextField', [], {}) + 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'events'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['philo.Tag']"}) }, 'julian.location': { 'Meta': {'object_name': 'Location'}, diff --git a/contrib/julian/models.py b/contrib/julian/models.py index 0653363..5dea7a3 100644 --- a/contrib/julian/models.py +++ b/contrib/julian/models.py @@ -121,12 +121,20 @@ class Event(Entity, TimedModel): created = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True) - uuid = models.TextField() # Format? + + site = models.ForeignKey(Site, default=DEFAULT_SITE) + + @property + def uuid(self): + return "%s@%s" % (self.created.isoformat(), getattr(self.site, 'domain', 'None')) objects = EventManager() def __unicode__(self): return self.name + + class Meta: + unique_together = ('site', 'created') class Calendar(Entity): @@ -141,6 +149,11 @@ class Calendar(Entity): def __unicode__(self): return self.name + @property + def fpi(self): + # See http://xml.coverpages.org/tauber-fpi.html or ISO 9070:1991 for format information. + return "-//%s//%s//%s" % (self.site.name, self.name, self.language.split('-')[0].upper()) + class Meta: unique_together = ('name', 'site', 'language') @@ -398,9 +411,7 @@ class CalendarView(FeedView): return "" def feed_guid(self, obj): - # Is this correct? Should I have a different id for different subfeeds? - # See http://xml.coverpages.org/tauber-fpi.html for format. - return "-//%s//%s %s//%s" % (obj.site.name.upper(), self.feed_type.upper(), obj.name.upper(), obj.language.upper()) + return obj.fpi def description(self, obj): return obj.description -- 2.20.1