From: Radek Czajka Date: Wed, 24 Oct 2012 12:58:35 +0000 (+0200) Subject: events end dates X-Git-Url: https://git.mdrn.pl/prawokultury.git/commitdiff_plain/a133e0e8f7c0b89230c7520b2a56e2d7084ad29e events end dates + some import fixes --- diff --git a/events/admin.py b/events/admin.py index 794fa52..f15f554 100644 --- a/events/admin.py +++ b/events/admin.py @@ -10,7 +10,7 @@ from migdal.helpers import translated_fields class EventAdmin(admin.ModelAdmin): fieldsets = ( - (None, {'fields': ('date', 'link')}), + (None, {'fields': ('date', 'date_end', 'link')}), ) + tuple( (ln, {'fields': ( ('published_%s' % lc), diff --git a/events/migrations/0003_auto__add_field_event_date_end.py b/events/migrations/0003_auto__add_field_event_date_end.py new file mode 100644 index 0000000..805238c --- /dev/null +++ b/events/migrations/0003_auto__add_field_event_date_end.py @@ -0,0 +1,42 @@ +# -*- 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.date_end' + db.add_column('events_event', 'date_end', + self.gf('django.db.models.fields.DateTimeField')(db_index=True, default='2000-01-01 0:00', max_length=255, blank=True), + keep_default=False) + + if not db.dry_run: + orm.Event.objects.all().update(date_end=models.F('date')) + + def backwards(self, orm): + # Deleting field 'Event.date_end' + db.delete_column('events_event', 'date_end') + + + models = { + 'events.event': { + 'Meta': {'ordering': "['date']", 'object_name': 'Event'}, + 'date': ('django.db.models.fields.DateTimeField', [], {'max_length': '255', 'db_index': 'True'}), + 'date_end': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'max_length': '255', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'link': ('django.db.models.fields.URLField', [], {'max_length': '200'}), + 'organizer_en': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '255', 'blank': 'True'}), + 'organizer_pl': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '255', 'blank': 'True'}), + 'place_en': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), + 'place_pl': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), + 'published_en': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'published_pl': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'title_en': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), + 'title_pl': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}) + } + } + + complete_apps = ['events'] \ No newline at end of file diff --git a/events/models.py b/events/models.py index e20ae53..d147aeb 100644 --- a/events/models.py +++ b/events/models.py @@ -11,6 +11,8 @@ from migdal.helpers import add_translatable class Event(models.Model): date = models.DateTimeField(_('date'), max_length=255, db_index=True) + date_end = models.DateTimeField(_('end date'), max_length=255, + db_index=True, blank=True) link = models.URLField(_('link')) class Meta: @@ -22,6 +24,12 @@ class Event(models.Model): return self.title def clean(self): + if self.date_end: + if self.date_end < self.date: + raise ValidationError( + ugettext("End date must not be earlier than start.")) + else: + self.date_end = self.date for lc, ln in settings.LANGUAGES: if (getattr(self, "published_%s" % lc) and not getattr(self, "title_%s" % lc)): diff --git a/events/templatetags/events_tags.py b/events/templatetags/events_tags.py index cd3e7da..ea2734d 100644 --- a/events/templatetags/events_tags.py +++ b/events/templatetags/events_tags.py @@ -14,7 +14,7 @@ from datetime import datetime def events_box(context, limit=app_settings.BOX_LENGTH): lang = context['request'].LANGUAGE_CODE objects = Event.objects.filter(**{"published_%s" % lang: True}) - objects = objects.filter(date__gte=datetime.now())[:limit] + objects = objects.filter(date_end__gte=datetime.now())[:limit] return {'objects': objects} diff --git a/events/views.py b/events/views.py index b2dccc7..515e92d 100644 --- a/events/views.py +++ b/events/views.py @@ -4,7 +4,7 @@ from events.models import Event def events(request): - events = Event.objects.filter(date__gte=datetime.now()) + events = Event.objects.filter(date_end__gte=datetime.now()) events = events.filter(**{"published_%s" % request.LANGUAGE_CODE: True}) return render(request, 'events/event_list.html', { 'object_list': events, diff --git a/migdal/api.py b/migdal/api.py index 6f81a4d..fffbff8 100644 --- a/migdal/api.py +++ b/migdal/api.py @@ -4,7 +4,7 @@ # from itertools import chain from migdal.models import Entry -from migdal.settings import TYPES +from migdal import app_settings from django.utils.translation import get_language @@ -15,7 +15,7 @@ def entry_list(entry_type=None, category=None, promobox=False): if entry_type: object_list = object_list.filter(type=entry_type.db) else: - object_list = object_list.filter(type__in=[t.db for t in TYPES if t.on_main]) + object_list = object_list.filter(type__in=[t.db for t in app_settings.TYPES if t.on_main]) if category: object_list = object_list.filter(categories=category) diff --git a/migdal/feeds.py b/migdal/feeds.py index 53145c5..33e9e0b 100644 --- a/migdal/feeds.py +++ b/migdal/feeds.py @@ -8,7 +8,7 @@ from django.shortcuts import get_object_or_404 from django.utils.translation import ugettext as _, string_concat from migdal import api from migdal.models import Category -from migdal.settings import TYPES_DICT +from migdal import app_settings class EntriesFeed(Feed): @@ -19,7 +19,7 @@ class EntriesFeed(Feed): else: category = None if type_db: - entry_type = TYPES_DICT[type_db] + entry_type = app_settings.TYPES_DICT[type_db] else: entry_type = None return {'entry_type': entry_type, 'category': category} diff --git a/migdal/forms.py b/migdal/forms.py index 9c87bd1..140b5fe 100644 --- a/migdal/forms.py +++ b/migdal/forms.py @@ -5,7 +5,7 @@ from django import forms from django.utils.translation import ugettext_lazy as _, get_language from migdal.models import Entry -from migdal.settings import TYPE_SUBMIT +from migdal import app_settings from slughifi import slughifi from django.core.mail import mail_managers from django import template @@ -32,7 +32,7 @@ def get_submit_form(*args, **kwargs): def clean(self): data = super(SubmitForm, self).clean() - data['type'] = TYPE_SUBMIT + data['type'] = app_settings.TYPE_SUBMIT orig_slug = slughifi(data.get('title_%s' % lang, '')) slug = orig_slug number = 2