From 051e647c3f313cb4a2a51d7b17bcfda79f192b46 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Tue, 15 Feb 2011 18:40:50 -0500 Subject: [PATCH] Added admin sugar for julian models. Corrected minor typos and omissions. Filled out the CalendarView view methods and process_page_items method. Everything seems to work and be stable. --- contrib/julian/admin.py | 48 +++- contrib/julian/feedgenerator.py | 2 +- ...d_calendarview__add_field_location_slug.py | 205 ++++++++++++++++++ ...ents_per_page__chg_field_calendarview_t.py | 188 ++++++++++++++++ contrib/julian/models.py | 132 ++++++++--- 5 files changed, 537 insertions(+), 38 deletions(-) create mode 100644 contrib/julian/migrations/0005_auto__del_icalendarfeedview__add_calendarview__add_field_location_slug.py create mode 100644 contrib/julian/migrations/0006_auto__add_field_calendarview_events_per_page__chg_field_calendarview_t.py diff --git a/contrib/julian/admin.py b/contrib/julian/admin.py index f976e82..10bc6f9 100644 --- a/contrib/julian/admin.py +++ b/contrib/julian/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin from philo.admin import EntityAdmin, COLLAPSE_CLASSES -from philo.contrib.julian.models import Location, Event, Calendar, ICalendarFeedView +from philo.contrib.julian.models import Location, Event, Calendar, CalendarView class LocationAdmin(EntityAdmin): @@ -23,22 +23,56 @@ class EventAdmin(EntityAdmin): 'classes': COLLAPSE_CLASSES }) ) + filter_horizontal = ['tags'] + raw_id_fields = ['parent_event'] related_lookup_fields = { + 'fk': raw_id_fields, 'generic': [["location_content_type", "location_pk"]] } - filter_horizontal = ['tags'] - raw_id_fields = ['parent_event'] + prepopulated_fields = {'slug': ('name',)} class CalendarAdmin(EntityAdmin): - pass + prepopulated_fields = {'slug': ('name',)} + filter_horizontal = ['events'] + fieldsets = ( + (None, { + 'fields': ('name', 'description', 'events') + }), + ('Advanced', { + 'fields': ('slug', 'uuid'), + 'classes': COLLAPSE_CLASSES + }) + ) -class ICalendarFeedViewAdmin(EntityAdmin): - pass +class CalendarViewAdmin(EntityAdmin): + fieldsets = ( + (None, { + 'fields': ('calendar',) + }), + ('Pages', { + 'fields': ('index_page', 'event_detail_page') + }), + ('General Settings', { + 'fields': ('tag_permalink_base', 'owner_permalink_base', 'location_permalink_base', 'events_per_page') + }), + ('Event List Pages', { + 'fields': ('timespan_page', 'tag_page', 'location_page', 'owner_page'), + 'classes': COLLAPSE_CLASSES + }), + ('Archive Pages', { + 'fields': ('location_archive_page', 'tag_archive_page', 'owner_archive_page'), + 'classes': COLLAPSE_CLASSES + }), + ('Feed Settings', { + 'fields': ( 'feeds_enabled', 'feed_suffix', 'feed_type', 'item_title_template', 'item_description_template',), + 'classes': COLLAPSE_CLASSES + }) + ) admin.site.register(Location, LocationAdmin) admin.site.register(Event, EventAdmin) admin.site.register(Calendar, CalendarAdmin) -admin.site.register(ICalendarFeedView, ICalendarFeedViewAdmin) \ No newline at end of file +admin.site.register(CalendarView, CalendarViewAdmin) \ No newline at end of file diff --git a/contrib/julian/feedgenerator.py b/contrib/julian/feedgenerator.py index 23efdca..19e959d 100644 --- a/contrib/julian/feedgenerator.py +++ b/contrib/julian/feedgenerator.py @@ -81,4 +81,4 @@ class ICalendarFeed(SyndicationFeed): if isinstance(outfile, HttpResponse): filename = self.feed.get('filename', 'filename.ics') outfile['Filename'] = filename - response['Content-Disposition'] = 'attachment; filename=%s' % filename \ No newline at end of file + outfile['Content-Disposition'] = 'attachment; filename=%s' % filename \ No newline at end of file diff --git a/contrib/julian/migrations/0005_auto__del_icalendarfeedview__add_calendarview__add_field_location_slug.py b/contrib/julian/migrations/0005_auto__del_icalendarfeedview__add_calendarview__add_field_location_slug.py new file mode 100644 index 0000000..e3bae80 --- /dev/null +++ b/contrib/julian/migrations/0005_auto__del_icalendarfeedview__add_calendarview__add_field_location_slug.py @@ -0,0 +1,205 @@ +# encoding: 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): + + # Deleting model 'ICalendarFeedView' + db.delete_table('julian_icalendarfeedview') + + # Adding model 'CalendarView' + db.create_table('julian_calendarview', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('feed_type', self.gf('django.db.models.fields.CharField')(default='text/calendar', max_length=50)), + ('feed_suffix', self.gf('django.db.models.fields.CharField')(default='feed', max_length=255)), + ('feeds_enabled', self.gf('django.db.models.fields.BooleanField')(default=True, blank=True)), + ('item_title_template', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='julian_calendarview_title_related', null=True, to=orm['philo.Template'])), + ('item_description_template', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='julian_calendarview_description_related', null=True, to=orm['philo.Template'])), + ('calendar', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['julian.Calendar'])), + ('index_page', self.gf('django.db.models.fields.related.ForeignKey')(related_name='calendar_index_related', to=orm['philo.Page'])), + ('timespan_page', self.gf('django.db.models.fields.related.ForeignKey')(related_name='calendar_timespan_related', to=orm['philo.Page'])), + ('event_detail_page', self.gf('django.db.models.fields.related.ForeignKey')(related_name='calendar_detail_related', to=orm['philo.Page'])), + ('tag_page', self.gf('django.db.models.fields.related.ForeignKey')(related_name='calendar_tag_related', to=orm['philo.Page'])), + ('location_page', self.gf('django.db.models.fields.related.ForeignKey')(related_name='calendar_location_related', to=orm['philo.Page'])), + ('owner_page', self.gf('django.db.models.fields.related.ForeignKey')(related_name='calendar_owner_related', to=orm['philo.Page'])), + ('tag_archive_page', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='calendar_tag_archive_related', null=True, to=orm['philo.Page'])), + ('location_archive_page', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='calendar_location_archive_related', null=True, to=orm['philo.Page'])), + ('owner_archive_page', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='calendar_owner_archive_related', null=True, to=orm['philo.Page'])), + ('tag_permalink_base', self.gf('django.db.models.fields.CharField')(default='tags', max_length=30)), + ('owner_permalink_base', self.gf('django.db.models.fields.CharField')(default='owner', max_length=30)), + ('location_permalink_base', self.gf('django.db.models.fields.CharField')(default='location', max_length=30)), + )) + db.send_create_signal('julian', ['CalendarView']) + + # Adding field 'Location.slug' + db.add_column('julian_location', 'slug', self.gf('django.db.models.fields.SlugField')(default='slug', unique=True, max_length=255, db_index=True), keep_default=False) + + + def backwards(self, orm): + + # Adding model 'ICalendarFeedView' + db.create_table('julian_icalendarfeedview', ( + ('item_title_template', self.gf('django.db.models.fields.related.ForeignKey')(related_name='julian_icalendarfeedview_title_related', null=True, to=orm['philo.Template'], blank=True)), + ('feed_type', self.gf('django.db.models.fields.CharField')(default='application/atom+xml', max_length=50)), + ('item_description_template', self.gf('django.db.models.fields.related.ForeignKey')(related_name='julian_icalendarfeedview_description_related', null=True, to=orm['philo.Template'], blank=True)), + ('feeds_enabled', self.gf('django.db.models.fields.BooleanField')(default=True, blank=True)), + ('calendar', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['julian.Calendar'])), + ('feed_suffix', self.gf('django.db.models.fields.CharField')(default='feed', max_length=255)), + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + )) + db.send_create_signal('julian', ['ICalendarFeedView']) + + # Deleting model 'CalendarView' + db.delete_table('julian_calendarview') + + # Deleting field 'Location.slug' + db.delete_column('julian_location', 'slug') + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'julian.calendar': { + 'Meta': {'object_name': 'Calendar'}, + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'events': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'calendars'", 'symmetrical': 'False', 'to': "orm['julian.Event']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '100', 'db_index': 'True'}), + 'uuid': ('django.db.models.fields.TextField', [], {'unique': 'True'}) + }, + 'julian.calendarview': { + 'Meta': {'object_name': 'CalendarView'}, + 'calendar': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['julian.Calendar']"}), + 'event_detail_page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'calendar_detail_related'", 'to': "orm['philo.Page']"}), + 'feed_suffix': ('django.db.models.fields.CharField', [], {'default': "'feed'", 'max_length': '255'}), + 'feed_type': ('django.db.models.fields.CharField', [], {'default': "'text/calendar'", 'max_length': '50'}), + 'feeds_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'index_page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'calendar_index_related'", 'to': "orm['philo.Page']"}), + 'item_description_template': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'julian_calendarview_description_related'", 'null': 'True', 'to': "orm['philo.Template']"}), + 'item_title_template': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'julian_calendarview_title_related'", 'null': 'True', 'to': "orm['philo.Template']"}), + 'location_archive_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'calendar_location_archive_related'", 'null': 'True', 'to': "orm['philo.Page']"}), + 'location_page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'calendar_location_related'", 'to': "orm['philo.Page']"}), + 'location_permalink_base': ('django.db.models.fields.CharField', [], {'default': "'location'", 'max_length': '30'}), + 'owner_archive_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'calendar_owner_archive_related'", 'null': 'True', 'to': "orm['philo.Page']"}), + 'owner_page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'calendar_owner_related'", 'to': "orm['philo.Page']"}), + 'owner_permalink_base': ('django.db.models.fields.CharField', [], {'default': "'owner'", 'max_length': '30'}), + 'tag_archive_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'calendar_tag_archive_related'", 'null': 'True', 'to': "orm['philo.Page']"}), + 'tag_page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'calendar_tag_related'", 'to': "orm['philo.Page']"}), + 'tag_permalink_base': ('django.db.models.fields.CharField', [], {'default': "'tags'", 'max_length': '30'}), + 'timespan_page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'calendar_timespan_related'", 'to': "orm['philo.Page']"}) + }, + 'julian.event': { + 'Meta': {'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', [], {}), + 'end_time': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'location_content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), + 'location_pk': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), + 'parent_event': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['julian.Event']", 'null': 'True', 'blank': 'True'}), + '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', [], {}) + }, + 'julian.location': { + 'Meta': {'object_name': 'Location'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}) + }, + 'philo.attribute': { + 'Meta': {'unique_together': "(('key', 'entity_content_type', 'entity_object_id'), ('value_content_type', 'value_object_id'))", 'object_name': 'Attribute'}, + 'entity_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'attribute_entity_set'", 'to': "orm['contenttypes.ContentType']"}), + 'entity_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'value_content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'attribute_value_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}), + 'value_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}) + }, + 'philo.node': { + 'Meta': {'object_name': 'Node'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Node']"}), + 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}), + 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'view_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'node_view_set'", 'to': "orm['contenttypes.ContentType']"}), + 'view_object_id': ('django.db.models.fields.PositiveIntegerField', [], {}) + }, + 'philo.page': { + 'Meta': {'object_name': 'Page'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'template': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'pages'", 'to': "orm['philo.Template']"}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'philo.tag': { + 'Meta': {'object_name': 'Tag'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}) + }, + 'philo.template': { + 'Meta': {'object_name': 'Template'}, + 'code': ('philo.models.fields.TemplateField', [], {}), + 'documentation': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'mimetype': ('django.db.models.fields.CharField', [], {'default': "'text/html'", 'max_length': '255'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Template']"}), + 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}), + 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}) + } + } + + complete_apps = ['julian'] diff --git a/contrib/julian/migrations/0006_auto__add_field_calendarview_events_per_page__chg_field_calendarview_t.py b/contrib/julian/migrations/0006_auto__add_field_calendarview_events_per_page__chg_field_calendarview_t.py new file mode 100644 index 0000000..b561219 --- /dev/null +++ b/contrib/julian/migrations/0006_auto__add_field_calendarview_events_per_page__chg_field_calendarview_t.py @@ -0,0 +1,188 @@ +# encoding: 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 field 'CalendarView.events_per_page' + db.add_column('julian_calendarview', 'events_per_page', self.gf('django.db.models.fields.PositiveIntegerField')(null=True, blank=True), keep_default=False) + + # Changing field 'CalendarView.timespan_page' + db.alter_column('julian_calendarview', 'timespan_page_id', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, null=True, to=orm['philo.Page'])) + + # Changing field 'CalendarView.owner_page' + db.alter_column('julian_calendarview', 'owner_page_id', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, null=True, to=orm['philo.Page'])) + + # Changing field 'CalendarView.location_page' + db.alter_column('julian_calendarview', 'location_page_id', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, null=True, to=orm['philo.Page'])) + + # Changing field 'CalendarView.tag_page' + db.alter_column('julian_calendarview', 'tag_page_id', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, null=True, to=orm['philo.Page'])) + + + def backwards(self, orm): + + # Deleting field 'CalendarView.events_per_page' + db.delete_column('julian_calendarview', 'events_per_page') + + # Changing field 'CalendarView.timespan_page' + db.alter_column('julian_calendarview', 'timespan_page_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['philo.Page'])) + + # Changing field 'CalendarView.owner_page' + db.alter_column('julian_calendarview', 'owner_page_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['philo.Page'])) + + # Changing field 'CalendarView.location_page' + db.alter_column('julian_calendarview', 'location_page_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['philo.Page'])) + + # Changing field 'CalendarView.tag_page' + db.alter_column('julian_calendarview', 'tag_page_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['philo.Page'])) + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'julian.calendar': { + 'Meta': {'object_name': 'Calendar'}, + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'events': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'calendars'", 'symmetrical': 'False', 'to': "orm['julian.Event']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '100', 'db_index': 'True'}), + 'uuid': ('django.db.models.fields.TextField', [], {'unique': 'True'}) + }, + 'julian.calendarview': { + 'Meta': {'object_name': 'CalendarView'}, + 'calendar': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['julian.Calendar']"}), + 'event_detail_page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'calendar_detail_related'", 'to': "orm['philo.Page']"}), + 'events_per_page': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}), + 'feed_suffix': ('django.db.models.fields.CharField', [], {'default': "'feed'", 'max_length': '255'}), + 'feed_type': ('django.db.models.fields.CharField', [], {'default': "'text/calendar'", 'max_length': '50'}), + 'feeds_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'index_page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'calendar_index_related'", 'to': "orm['philo.Page']"}), + 'item_description_template': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'julian_calendarview_description_related'", 'null': 'True', 'to': "orm['philo.Template']"}), + 'item_title_template': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'julian_calendarview_title_related'", 'null': 'True', 'to': "orm['philo.Template']"}), + 'location_archive_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'calendar_location_archive_related'", 'null': 'True', 'to': "orm['philo.Page']"}), + 'location_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'calendar_location_related'", 'null': 'True', 'to': "orm['philo.Page']"}), + 'location_permalink_base': ('django.db.models.fields.CharField', [], {'default': "'location'", 'max_length': '30'}), + 'owner_archive_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'calendar_owner_archive_related'", 'null': 'True', 'to': "orm['philo.Page']"}), + 'owner_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'calendar_owner_related'", 'null': 'True', 'to': "orm['philo.Page']"}), + 'owner_permalink_base': ('django.db.models.fields.CharField', [], {'default': "'owner'", 'max_length': '30'}), + 'tag_archive_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'calendar_tag_archive_related'", 'null': 'True', 'to': "orm['philo.Page']"}), + 'tag_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'calendar_tag_related'", 'null': 'True', 'to': "orm['philo.Page']"}), + 'tag_permalink_base': ('django.db.models.fields.CharField', [], {'default': "'tags'", 'max_length': '30'}), + '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'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'description': ('philo.models.fields.TemplateField', [], {}), + 'end_date': ('django.db.models.fields.DateField', [], {}), + 'end_time': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'location_content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), + 'location_pk': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), + 'parent_event': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['julian.Event']", 'null': 'True', 'blank': 'True'}), + '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', [], {}) + }, + 'julian.location': { + 'Meta': {'object_name': 'Location'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}) + }, + 'philo.attribute': { + 'Meta': {'unique_together': "(('key', 'entity_content_type', 'entity_object_id'), ('value_content_type', 'value_object_id'))", 'object_name': 'Attribute'}, + 'entity_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'attribute_entity_set'", 'to': "orm['contenttypes.ContentType']"}), + 'entity_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'value_content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'attribute_value_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}), + 'value_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}) + }, + 'philo.node': { + 'Meta': {'object_name': 'Node'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Node']"}), + 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}), + 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'view_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'node_view_set'", 'to': "orm['contenttypes.ContentType']"}), + 'view_object_id': ('django.db.models.fields.PositiveIntegerField', [], {}) + }, + 'philo.page': { + 'Meta': {'object_name': 'Page'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'template': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'pages'", 'to': "orm['philo.Template']"}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'philo.tag': { + 'Meta': {'object_name': 'Tag'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}) + }, + 'philo.template': { + 'Meta': {'object_name': 'Template'}, + 'code': ('philo.models.fields.TemplateField', [], {}), + 'documentation': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'mimetype': ('django.db.models.fields.CharField', [], {'default': "'text/html'", 'max_length': '255'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Template']"}), + 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}), + 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}) + } + } + + complete_apps = ['julian'] diff --git a/contrib/julian/models.py b/contrib/julian/models.py index 7faf4f0..14a0b17 100644 --- a/contrib/julian/models.py +++ b/contrib/julian/models.py @@ -75,7 +75,7 @@ class TimedModel(models.Model): class Event(Entity, TimedModel): name = models.CharField(max_length=255) - slug = models.SlugField(max_length=255, unique_for_date='created') + slug = models.SlugField(max_length=255, unique_for_date='start_date') location_content_type = models.ForeignKey(ContentType, limit_choices_to=location_content_type_limiter, blank=True, null=True) location_pk = models.TextField(blank=True) @@ -88,7 +88,7 @@ class Event(Entity, TimedModel): parent_event = models.ForeignKey('self', blank=True, null=True) # TODO: "User module" - owner = models.ForeignKey(User) + owner = models.ForeignKey(User, related_name='owned_events') created = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True) @@ -105,25 +105,30 @@ class Calendar(Entity): events = models.ManyToManyField(Event, related_name='calendars') # TODO: Can we auto-generate this on save based on site id and calendar name and settings language? - uuid = models.TextField("Calendar UUID", unique=True, help_text="Should conform to Formal Public Identifier format. See <http://en.wikipedia.org/wiki/Formal_Public_Identifier>", validators=[RegexValidator(FPI_REGEX)]) + uuid = models.TextField("Calendar UUID", unique=True, help_text="Should conform to Formal Public Identifier format. See Wikipedia.", validators=[RegexValidator(FPI_REGEX)]) + + def __unicode__(self): + return self.name class CalendarView(FeedView): calendar = models.ForeignKey(Calendar) index_page = models.ForeignKey(Page, related_name="calendar_index_related") - timespan_page = models.ForeignKey(Page, related_name="calendar_timespan_related") event_detail_page = models.ForeignKey(Page, related_name="calendar_detail_related") - tag_page = models.ForeignKey(Page, related_name="calendar_tag_related") - location_page = models.ForeignKey(Page, related_name="calendar_location_related") - owner_page = models.ForeignKey(Page, related_name="calendar_owner_related") + + timespan_page = models.ForeignKey(Page, related_name="calendar_timespan_related", blank=True, null=True) + tag_page = models.ForeignKey(Page, related_name="calendar_tag_related", blank=True, null=True) + location_page = models.ForeignKey(Page, related_name="calendar_location_related", blank=True, null=True) + owner_page = models.ForeignKey(Page, related_name="calendar_owner_related", blank=True, null=True) tag_archive_page = models.ForeignKey(Page, related_name="calendar_tag_archive_related", blank=True, null=True) location_archive_page = models.ForeignKey(Page, related_name="calendar_location_archive_related", blank=True, null=True) owner_archive_page = models.ForeignKey(Page, related_name="calendar_owner_archive_related", blank=True, null=True) tag_permalink_base = models.CharField(max_length=30, default='tags') - owner_permalink_base = models.CharField(max_length=30, default='owner') - location_permalink_base = models.CharField(max_length=30, default='location') + owner_permalink_base = models.CharField(max_length=30, default='owners') + location_permalink_base = models.CharField(max_length=30, default='locations') + events_per_page = models.PositiveIntegerField(blank=True, null=True) item_context_var = "events" object_attr = "calendar" @@ -133,9 +138,9 @@ class CalendarView(FeedView): return 'events_for_user', [], {'username': obj.username} elif isinstance(obj, Event): return 'event_detail', [], { - 'year': obj.start_date.year, - 'month': obj.start_date.month, - 'day': obj.start_date.day, + 'year': str(obj.start_date.year).zfill(4), + 'month': str(obj.start_date.month).zfill(2), + 'day': str(obj.start_date.day).zfill(2), 'slug': obj.slug } elif isinstance(obj, Tag) or isinstance(obj, models.query.QuerySet) and obj.model == Tag: @@ -145,9 +150,7 @@ class CalendarView(FeedView): raise ViewCanNotProvideSubpath def timespan_patterns(self, timespan_name): - urlpatterns = patterns('', - ) + self.feed_patterns('get_events_by_timespan', 'timespan_page', "events_by_%s" % timespan_name) - return urlpatterns + return self.feed_patterns('get_events_by_timespan', 'timespan_page', "events_by_%s" % timespan_name) @property def urlpatterns(self): @@ -160,7 +163,7 @@ class CalendarView(FeedView): #url(r'^(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P\d{1,2})', include(self.timespan_patterns('hour'))), url(r'(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P[\w-]+)', self.event_detail_view, name="event_detail"), - url(r'^%s/(?P[^/]+)' % self.owner_permalink_base, include(self.feed_patterns('get_events_by_user', 'owner_page', 'events_by_user'))), + url(r'^%s/(?P[^/]+)' % self.owner_permalink_base, include(self.feed_patterns('get_events_by_owner', 'owner_page', 'events_by_user'))), # Some sort of shortcut for a location would be useful. This could be on a per-calendar # or per-calendar-view basis. @@ -186,12 +189,13 @@ class CalendarView(FeedView): url(r'^%s$' % self.owner_permalink_base, self.owner_archive_view, name='owner_archive') ) - if self.owner_archive_page: + if self.location_archive_page: urlpatterns += patterns('', url(r'^%s$' % self.location_permalink_base, self.location_archive_view, name='location_archive') ) return urlpatterns + # Basic QuerySet fetchers. def get_event_queryset(self): return self.calendar.events.all() @@ -199,21 +203,44 @@ class CalendarView(FeedView): qs = self.get_event_queryset() # See python documentation for the min/max values. if year and month and day: + year, month, day = int(year), int(month), int(day) start_datetime = datetime.datetime(year, month, day, 0, 0) end_datetime = datetime.datetime(year, month, day, 23, 59) elif year and month: + year, month = int(year), int(month) start_datetime = datetime.datetime(year, month, 1, 0, 0) end_datetime = datetime.datetime(year, month, calendar.monthrange(year, month)[1], 23, 59) else: + year = int(year) start_datetime = datetime.datetime(year, 1, 1, 0, 0) end_datetime = datetime.datetime(year, 12, 31, 23, 59) - return qs.exclude(end_date__lt=start_datetime, end_time__lt=start_datetime.time()).exclude(start_date__gt=end_datetime, start_time__gt=end_datetime.time(), start_time__isnull=False).exclude(start_time__isnull=True, start_date__gt=end_datetime.time()) + return qs.exclude(end_date__lt=start_datetime, end_time__lt=start_datetime).exclude(start_date__gt=end_datetime, start_time__gt=end_datetime, start_time__isnull=False).exclude(start_time__isnull=True, start_date__gt=end_datetime) def get_tag_queryset(self): - return Tag.objects.filter(events__calendar=self.calendar).distinct() + return Tag.objects.filter(events__calendars=self.calendar).distinct() - # Event fetchers. + def get_location_querysets(self): + # Potential bottleneck? + location_map = {} + locations = Event.objects.values_list('location_content_type', 'location_pk') + + for ct, pk in locations: + location_map.setdefault(ct, []).append(pk) + + location_cts = ContentType.objects.in_bulk(location_map.keys()) + location_querysets = {} + + for ct_pk, pks in location_map.items(): + ct = location_cts[ct_pk] + location_querysets[ct] = ct.model_class()._default_manager.filter(pk__in=pks) + + return location_querysets + + def get_owner_queryset(self): + return User.objects.filter(owned_events__calendars=self.calendar).distinct() + + # Event QuerySet parsers for a request/args/kwargs def get_all_events(self, request, extra_context=None): return self.get_event_queryset(), extra_context @@ -226,16 +253,16 @@ class CalendarView(FeedView): }) return self.get_timespan_queryset(year, month, day), context - def get_events_by_user(self, request, username, extra_context=None): + def get_events_by_owner(self, request, username, extra_context=None): try: - user = User.objects.get(username) + owner = self.get_owner_queryset().get(username=username) except User.DoesNotExist: raise Http404 - qs = self.event_queryset().filter(owner=user) + qs = self.get_event_queryset().filter(owner=owner) context = extra_context or {} context.update({ - 'user': user + 'owner': owner }) return qs, context @@ -276,19 +303,64 @@ class CalendarView(FeedView): }) return events, context - # Detail View. TODO: fill this out. + # Detail View. def event_detail_view(self, request, year, month, day, slug, extra_context=None): - pass + try: + event = Event.objects.select_related('parent_event').get(start_date__year=year, start_date__month=month, start_date__day=day, slug=slug) + except Event.DoesNotExist: + raise Http404 + + context = self.get_context() + context.update(extra_context or {}) + context.update({ + 'event': event + }) + return self.event_detail_page.render_to_response(request, extra_context=context) - # Archive Views. TODO: fill these out. + # Archive Views. def tag_archive_view(self, request, extra_context=None): - pass + tags = self.get_tag_queryset() + context = self.get_context() + context.update(extra_context or {}) + context.update({ + 'tags': tags + }) + return self.tag_archive_page.render_to_response(request, extra_context=context) def location_archive_view(self, request, extra_context=None): - pass + # What datastructure should locations be? + locations = self.get_location_querysets() + context = self.get_context() + context.update(extra_context or {}) + context.update({ + 'locations': locations + }) + return self.location_archive_page.render_to_response(request, extra_context=context) def owner_archive_view(self, request, extra_context=None): - pass + owners = self.get_owner_queryset() + context = self.get_context() + context.update(extra_context or {}) + context.update({ + 'owners': owners + }) + return self.owner_archive_page.render_to_response(request, extra_context=context) + + # Process page items + def process_page_items(self, request, items): + if self.events_per_page: + page_num = request.GET.get('page', 1) + paginator, paginated_page, items = paginate(items, self.events_per_page, page_num) + item_context = { + 'paginator': paginator, + 'paginated_page': paginated_page, + self.item_context_var: items + } + else: + item_context = { + self.item_context_var: items + } + return items, item_context # Feed information hooks def title(self, obj): -- 2.20.1