Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add event type, image, zip import

  • Loading branch information...
commit b269cfa15662700ceb16f0d4fb5e260ad0d17dc4 1 parent 511eb2f
@shurik authored
View
8 README.txt
@@ -0,0 +1,8 @@
+==================
+Mezzanine Calendar
+==================
+
+0.0.1 Initial
+0.0.2 Configurable Event Type
+ Add Event Image
+ Move status, publish date, login required to Meta
View
39 mezzanine/calendar/admin.py
@@ -1,6 +1,41 @@
+from copy import deepcopy
+
from django.contrib import admin
+from mezzanine.core.admin import TabularDynamicInlineAdmin
from mezzanine.pages.admin import PageAdmin
-from .models import Event
+from .models import Event, EventType, EventImage
+
+
+event_fieldsets = deepcopy(PageAdmin.fieldsets)
+event_fieldsets[0][1]['fields'].remove('in_menus')
+event_fieldsets[0][1]['fields'].remove('login_required')
+event_fieldsets[0][1]['fields'].remove('status')
+event_fieldsets[0][1]['fields'].remove(('publish_date', 'expiry_date'))
+event_fieldsets[1][1]['fields'].append('status')
+event_fieldsets[1][1]['fields'].append(('publish_date', 'expiry_date'))
+event_fieldsets[0][1]["fields"].extend([
+ "content", "start", "end", "type", "zip_import", "in_menus", 'login_required'])
+
+
+class EventImageInline(TabularDynamicInlineAdmin):
+ model = EventImage
+
+
+class EventAdmin(PageAdmin):
+ inlines = (EventImageInline,)
+ fieldsets = event_fieldsets
+
+ def get_form(self, request, obj=None, **kwargs):
+ """Don't require content even when status is published"""
+ form = super(PageAdmin, self).get_form(request, obj, **kwargs)
+
+ def clean_content(form):
+ content = form.cleaned_data.get("content")
+ return content
+
+ form.clean_content = clean_content
+ return form
-admin.site.register(Event, PageAdmin)
+admin.site.register(Event, EventAdmin)
+admin.site.register(EventType)
View
87 mezzanine/calendar/migrations/0001_initial.py
@@ -0,0 +1,87 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'Event'
+ db.create_table('calendar_event', (
+ ('page_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['pages.Page'], unique=True, primary_key=True)),
+ ('content', self.gf('mezzanine.core.fields.RichTextField')(blank=True)),
+ ('start', self.gf('django.db.models.fields.DateTimeField')()),
+ ('end', self.gf('django.db.models.fields.DateTimeField')()),
+ ))
+ db.send_create_signal('calendar', ['Event'])
+
+
+ def backwards(self, orm):
+ # Deleting model 'Event'
+ db.delete_table('calendar_event')
+
+
+ models = {
+ 'calendar.event': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'Event', '_ormbases': ['pages.Page']},
+ 'content': ('mezzanine.core.fields.RichTextField', [], {'blank': 'True'}),
+ 'end': ('django.db.models.fields.DateTimeField', [], {}),
+ 'page_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['pages.Page']", 'unique': 'True', 'primary_key': 'True'}),
+ 'start': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", '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'})
+ },
+ 'generic.assignedkeyword': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'AssignedKeyword'},
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'keyword': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'assignments'", 'to': "orm['generic.Keyword']"}),
+ 'object_pk': ('django.db.models.fields.IntegerField', [], {})
+ },
+ 'generic.keyword': {
+ 'Meta': {'object_name': 'Keyword'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'pages.page': {
+ 'Meta': {'ordering': "('titles',)", 'object_name': 'Page'},
+ '_meta_title': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'content_model': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'expiry_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'gen_description': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'in_menus': ('mezzanine.pages.fields.MenusField', [], {'default': '(1, 2, 3)', 'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'in_sitemap': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'keywords': ('mezzanine.generic.fields.KeywordsField', [], {'object_id_field': "'object_pk'", 'to': "orm['generic.AssignedKeyword']", 'frozen_by_south': 'True'}),
+ 'keywords_string': ('django.db.models.fields.CharField', [], {'max_length': '500', 'blank': 'True'}),
+ 'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['pages.Page']"}),
+ 'publish_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'short_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '2'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+ 'titles': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True'})
+ },
+ 'sites.site': {
+ 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
+ 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ }
+ }
+
+ complete_apps = ['calendar']
View
92 mezzanine/calendar/migrations/0002_auto__add_eventtype.py
@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'EventType'
+ db.create_table('calendar_eventtype', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('site', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['sites.Site'])),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ))
+ db.send_create_signal('calendar', ['EventType'])
+
+
+ def backwards(self, orm):
+ # Deleting model 'EventType'
+ db.delete_table('calendar_eventtype')
+
+
+ models = {
+ 'calendar.event': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'Event', '_ormbases': ['pages.Page']},
+ 'content': ('mezzanine.core.fields.RichTextField', [], {'blank': 'True'}),
+ 'end': ('django.db.models.fields.DateTimeField', [], {}),
+ 'page_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['pages.Page']", 'unique': 'True', 'primary_key': 'True'}),
+ 'start': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ 'calendar.eventtype': {
+ 'Meta': {'object_name': 'EventType'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", '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'})
+ },
+ 'generic.assignedkeyword': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'AssignedKeyword'},
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'keyword': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'assignments'", 'to': "orm['generic.Keyword']"}),
+ 'object_pk': ('django.db.models.fields.IntegerField', [], {})
+ },
+ 'generic.keyword': {
+ 'Meta': {'object_name': 'Keyword'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'pages.page': {
+ 'Meta': {'ordering': "('titles',)", 'object_name': 'Page'},
+ '_meta_title': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'content_model': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'expiry_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'gen_description': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'in_menus': ('mezzanine.pages.fields.MenusField', [], {'default': '(1, 2, 3)', 'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'in_sitemap': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'keywords': ('mezzanine.generic.fields.KeywordsField', [], {'object_id_field': "'object_pk'", 'to': "orm['generic.AssignedKeyword']", 'frozen_by_south': 'True'}),
+ 'keywords_string': ('django.db.models.fields.CharField', [], {'max_length': '500', 'blank': 'True'}),
+ 'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['pages.Page']"}),
+ 'publish_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'short_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '2'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+ 'titles': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True'})
+ },
+ 'sites.site': {
+ 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
+ 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ }
+ }
+
+ complete_apps = ['calendar']
View
90 mezzanine/calendar/migrations/0003_auto__add_field_event_type.py
@@ -0,0 +1,90 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding field 'Event.type'
+ db.add_column('calendar_event', 'type',
+ self.gf('django.db.models.fields.related.ForeignKey')(to=orm['calendar.EventType'], null=True, blank=True),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting field 'Event.type'
+ db.delete_column('calendar_event', 'type_id')
+
+
+ models = {
+ 'calendar.event': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'Event', '_ormbases': ['pages.Page']},
+ 'content': ('mezzanine.core.fields.RichTextField', [], {'blank': 'True'}),
+ 'end': ('django.db.models.fields.DateTimeField', [], {}),
+ 'page_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['pages.Page']", 'unique': 'True', 'primary_key': 'True'}),
+ 'start': ('django.db.models.fields.DateTimeField', [], {}),
+ 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['calendar.EventType']", 'null': 'True', 'blank': 'True'})
+ },
+ 'calendar.eventtype': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'EventType'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", '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'})
+ },
+ 'generic.assignedkeyword': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'AssignedKeyword'},
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'keyword': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'assignments'", 'to': "orm['generic.Keyword']"}),
+ 'object_pk': ('django.db.models.fields.IntegerField', [], {})
+ },
+ 'generic.keyword': {
+ 'Meta': {'object_name': 'Keyword'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'pages.page': {
+ 'Meta': {'ordering': "('titles',)", 'object_name': 'Page'},
+ '_meta_title': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'content_model': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'expiry_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'gen_description': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'in_menus': ('mezzanine.pages.fields.MenusField', [], {'default': '(1, 2, 3)', 'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'in_sitemap': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'keywords': ('mezzanine.generic.fields.KeywordsField', [], {'object_id_field': "'object_pk'", 'to': "orm['generic.AssignedKeyword']", 'frozen_by_south': 'True'}),
+ 'keywords_string': ('django.db.models.fields.CharField', [], {'max_length': '500', 'blank': 'True'}),
+ 'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['pages.Page']"}),
+ 'publish_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'short_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '2'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+ 'titles': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True'})
+ },
+ 'sites.site': {
+ 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
+ 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ }
+ }
+
+ complete_apps = ['calendar']
View
112 mezzanine/calendar/migrations/0004_auto__add_eventimage__add_field_event_zip_import.py
@@ -0,0 +1,112 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'EventImage'
+ db.create_table('calendar_eventimage', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('_order', self.gf('django.db.models.fields.IntegerField')(null=True)),
+ ('gallery', self.gf('django.db.models.fields.related.ForeignKey')(related_name='images', to=orm['calendar.Event'])),
+ ('file', self.gf('mezzanine.core.fields.FileField')(max_length=200)),
+ ('description', self.gf('django.db.models.fields.CharField')(max_length=1000, blank=True)),
+ ))
+ db.send_create_signal('calendar', ['EventImage'])
+
+ # Adding field 'Event.zip_import'
+ db.add_column('calendar_event', 'zip_import',
+ self.gf('django.db.models.fields.files.FileField')(max_length=100, null=True, blank=True),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting model 'EventImage'
+ db.delete_table('calendar_eventimage')
+
+ # Deleting field 'Event.zip_import'
+ db.delete_column('calendar_event', 'zip_import')
+
+
+ models = {
+ 'calendar.event': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'Event', '_ormbases': ['pages.Page']},
+ 'content': ('mezzanine.core.fields.RichTextField', [], {'blank': 'True'}),
+ 'end': ('django.db.models.fields.DateTimeField', [], {}),
+ 'page_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['pages.Page']", 'unique': 'True', 'primary_key': 'True'}),
+ 'start': ('django.db.models.fields.DateTimeField', [], {}),
+ 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['calendar.EventType']", 'null': 'True', 'blank': 'True'}),
+ 'zip_import': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
+ },
+ 'calendar.eventimage': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'EventImage'},
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'description': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'blank': 'True'}),
+ 'file': ('mezzanine.core.fields.FileField', [], {'max_length': '200'}),
+ 'gallery': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'images'", 'to': "orm['calendar.Event']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ 'calendar.eventtype': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'EventType'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", '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'})
+ },
+ 'generic.assignedkeyword': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'AssignedKeyword'},
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'keyword': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'assignments'", 'to': "orm['generic.Keyword']"}),
+ 'object_pk': ('django.db.models.fields.IntegerField', [], {})
+ },
+ 'generic.keyword': {
+ 'Meta': {'object_name': 'Keyword'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'pages.page': {
+ 'Meta': {'ordering': "('titles',)", 'object_name': 'Page'},
+ '_meta_title': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'content_model': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'expiry_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'gen_description': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'in_menus': ('mezzanine.pages.fields.MenusField', [], {'default': '(1, 2, 3)', 'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'in_sitemap': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'keywords': ('mezzanine.generic.fields.KeywordsField', [], {'object_id_field': "'object_pk'", 'to': "orm['generic.AssignedKeyword']", 'frozen_by_south': 'True'}),
+ 'keywords_string': ('django.db.models.fields.CharField', [], {'max_length': '500', 'blank': 'True'}),
+ 'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['pages.Page']"}),
+ 'publish_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'short_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '2'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+ 'titles': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True'})
+ },
+ 'sites.site': {
+ 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
+ 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ }
+ }
+
+ complete_apps = ['calendar']
View
97 mezzanine/calendar/migrations/0005_auto__chg_field_event_end.py
@@ -0,0 +1,97 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Changing field 'Event.end'
+ db.alter_column('calendar_event', 'end', self.gf('django.db.models.fields.DateTimeField')(null=True))
+
+ def backwards(self, orm):
+
+ # Changing field 'Event.end'
+ db.alter_column('calendar_event', 'end', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime(2013, 3, 8, 0, 0)))
+
+ models = {
+ 'calendar.event': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'Event', '_ormbases': ['pages.Page']},
+ 'content': ('mezzanine.core.fields.RichTextField', [], {'blank': 'True'}),
+ 'end': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'page_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['pages.Page']", 'unique': 'True', 'primary_key': 'True'}),
+ 'start': ('django.db.models.fields.DateTimeField', [], {}),
+ 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['calendar.EventType']", 'null': 'True', 'blank': 'True'}),
+ 'zip_import': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
+ },
+ 'calendar.eventimage': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'EventImage'},
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'description': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'blank': 'True'}),
+ 'file': ('mezzanine.core.fields.FileField', [], {'max_length': '200'}),
+ 'gallery': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'images'", 'to': "orm['calendar.Event']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ 'calendar.eventtype': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'EventType'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", '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'})
+ },
+ 'generic.assignedkeyword': {
+ 'Meta': {'ordering': "('_order',)", 'object_name': 'AssignedKeyword'},
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'keyword': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'assignments'", 'to': "orm['generic.Keyword']"}),
+ 'object_pk': ('django.db.models.fields.IntegerField', [], {})
+ },
+ 'generic.keyword': {
+ 'Meta': {'object_name': 'Keyword'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'pages.page': {
+ 'Meta': {'ordering': "('titles',)", 'object_name': 'Page'},
+ '_meta_title': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
+ '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'content_model': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'expiry_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'gen_description': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'in_menus': ('mezzanine.pages.fields.MenusField', [], {'default': '(1, 2, 3)', 'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'in_sitemap': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'keywords': ('mezzanine.generic.fields.KeywordsField', [], {'object_id_field': "'object_pk'", 'to': "orm['generic.AssignedKeyword']", 'frozen_by_south': 'True'}),
+ 'keywords_string': ('django.db.models.fields.CharField', [], {'max_length': '500', 'blank': 'True'}),
+ 'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['pages.Page']"}),
+ 'publish_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'short_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '2'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+ 'titles': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True'})
+ },
+ 'sites.site': {
+ 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
+ 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ }
+ }
+
+ complete_apps = ['calendar']
View
0  mezzanine/calendar/migrations/__init__.py
No changes.
View
119 mezzanine/calendar/models.py
@@ -1,17 +1,124 @@
+import os
+
+from cStringIO import StringIO
+from string import punctuation
+from urllib import unquote
+from zipfile import ZipFile
+
+from django.conf import settings
+from django.core.files.base import ContentFile
+from django.core.files.storage import default_storage
from django.db import models
-from mezzanine.core.fields import RichTextField
+from django.utils.translation import ugettext_lazy as _
+
+from mezzanine.core.fields import RichTextField, FileField
+from mezzanine.core.models import SiteRelated, Orderable
from mezzanine.pages.models import Page
+from mezzanine.utils.importing import import_dotted_path
+from mezzanine.utils.models import upload_to
+
+EVENTS_UPLOAD_DIR = "galleries"
+if settings.PACKAGE_NAME_FILEBROWSER in settings.INSTALLED_APPS:
+ fb_settings = "%s.settings" % settings.PACKAGE_NAME_FILEBROWSER
+ try:
+ EVENTS_UPLOAD_DIR = import_dotted_path(fb_settings).DIRECTORY
+ except ImportError:
+ pass
class Event(Page):
- title = models.CharField(max_length=255)
- slug = models.CharField(max_length=255)
- description = models.TextField()
content = RichTextField(blank=True)
start = models.DateTimeField()
- end = models.DateTimeField()
- guestlist = models.IntegerField()
+ end = models.DateTimeField(blank=True, null=True)
+ type = models.ForeignKey('calendar.EventType', blank=True, null=True)
+ zip_import = models.FileField(verbose_name=_("Zip import"), blank=True, null=True,
+ upload_to=upload_to("calendar.Event.zip_import", "events"),
+ help_text=_("Upload a zip file containing images, and "
+ "they'll be imported into this event."))
class Meta:
verbose_name = u'Event'
verbose_name_plural = u'Events'
+
+ def save(self, delete_zip_import=True, *args, **kwargs):
+ """
+ If a zip file is uploaded, extract any images from it and add
+ them to the gallery, before removing the zip file.
+ """
+ super(Event, self).save(*args, **kwargs)
+ if self.zip_import:
+ zip_file = ZipFile(self.zip_import)
+ # import PIL in either of the two ways it can end up installed.
+ try:
+ from PIL import Image
+ except ImportError:
+ import Image
+ for name in zip_file.namelist():
+ data = zip_file.read(name)
+ try:
+ image = Image.open(StringIO(data))
+ image.load()
+ image = Image.open(StringIO(data))
+ image.verify()
+ except:
+ continue
+ path = os.path.join(EVENTS_UPLOAD_DIR, self.slug,
+ name.decode("utf-8"))
+ try:
+ saved_path = default_storage.save(path, ContentFile(data))
+ except UnicodeEncodeError:
+ from warnings import warn
+ warn("A file was saved that contains unicode "
+ "characters in its path, but somehow the current "
+ "locale does not support utf-8. You may need to set "
+ "'LC_ALL' to a correct value, eg: 'en_US.UTF-8'.")
+ path = os.path.join(EVENTS_UPLOAD_DIR, self.slug,
+ unicode(name, errors="ignore"))
+ saved_path = default_storage.save(path, ContentFile(data))
+ self.images.add(EventImage(file=saved_path))
+ if delete_zip_import:
+ zip_file.close()
+ self.zip_import.delete(save=True)
+
+
+class EventType(SiteRelated):
+ name = models.CharField(max_length=255)
+
+ class Meta:
+ ordering = ['name']
+ verbose_name = u'Event Type'
+ verbose_name_plural = u'Event Types'
+
+ def __unicode__(self):
+ return self.name
+
+
+class EventImage(Orderable):
+ gallery = models.ForeignKey("calendar.Event", related_name="images")
+ file = FileField(_("File"), max_length=200, format="Image",
+ upload_to=upload_to("calendar.EventImage.file", "events"))
+ description = models.CharField(_("Description"), max_length=1000,
+ blank=True)
+
+ class Meta:
+ verbose_name = _("Image")
+ verbose_name_plural = _("Images")
+
+ def __unicode__(self):
+ return self.description
+
+ def save(self, *args, **kwargs):
+ """
+ If no description is given when created, create one from the
+ file name.
+ """
+ if not self.id and not self.description:
+ name = unquote(self.file.url).split("/")[-1].rsplit(".", 1)[0]
+ name = name.replace("'", "")
+ name = "".join([c if c not in punctuation else " " for c in name])
+ # str.title() doesn't deal with unicode very well.
+ # http://bugs.python.org/issue6412
+ name = "".join([s.upper() if i == 0 or name[i - 1] == " " else s
+ for i, s in enumerate(name)])
+ self.description = name
+ super(EventImage, self).save(*args, **kwargs)
Please sign in to comment.
Something went wrong with that request. Please try again.