From: Radek Czajka Date: Thu, 30 Aug 2012 14:01:46 +0000 (+0200) Subject: fixes #2359: unpublished events X-Git-Url: https://git.mdrn.pl/prawokultury.git/commitdiff_plain/7a47f04940f28745309716d725b63a8278b29e62?ds=inline fixes #2359: unpublished events --- diff --git a/events/admin.py b/events/admin.py index e75c047..0cac1e0 100644 --- a/events/admin.py +++ b/events/admin.py @@ -9,6 +9,17 @@ from migdal.helpers import translated_fields class EventAdmin(admin.ModelAdmin): + fieldsets = ( + (None, {'fields': ('date', 'link')}), + ) + tuple( + (ln, {'fields': ( + ('published_%s' % lc), + 'title_%s' % lc, + 'organizer_%s' % lc, + 'place_%s' % lc, + )}) + for lc, ln in settings.LANGUAGES + ) list_display = translated_fields( ('title', 'place', 'organizer'), settings.LANGUAGES ) + ('date',) diff --git a/events/locale/pl/LC_MESSAGES/django.mo b/events/locale/pl/LC_MESSAGES/django.mo index bc4bd21..776da84 100644 Binary files a/events/locale/pl/LC_MESSAGES/django.mo and b/events/locale/pl/LC_MESSAGES/django.mo differ diff --git a/events/locale/pl/LC_MESSAGES/django.po b/events/locale/pl/LC_MESSAGES/django.po index c5bf9ce..51d5de2 100644 --- a/events/locale/pl/LC_MESSAGES/django.po +++ b/events/locale/pl/LC_MESSAGES/django.po @@ -7,45 +7,53 @@ msgid "" msgstr "" "Project-Id-Version: prawokultury-events\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-08-28 15:15+0200\n" -"PO-Revision-Date: 2012-08-28 11:28+0100\n" +"POT-Creation-Date: 2012-08-30 15:58+0200\n" +"PO-Revision-Date: 2012-08-30 15:59+0100\n" "Last-Translator: Radek Czajka \n" "Language-Team: FNP \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " -"|| n%100>=20) ? 1 : 2)\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n" -#: models.py:11 +#: models.py:13 msgid "date" msgstr "data" -#: models.py:12 +#: models.py:14 msgid "link" msgstr "link" -#: models.py:15 +#: models.py:17 msgid "event" msgstr "wydarzenie" -#: models.py:16 +#: models.py:18 msgid "events" msgstr "wydarzenia" -#: models.py:24 +#: models.py:29 +#, python-format +msgid "Published event should have a title in relevant language (%s)." +msgstr "Opublikowane wydarzenie powinno mieć tytuł w odpowiednim języku (%s)." + +#: models.py:33 msgid "title" msgstr "tytuł" -#: models.py:25 +#: models.py:34 msgid "organizer" msgstr "organizator" -#: models.py:26 +#: models.py:36 msgid "place" msgstr "miejsce" +#: models.py:37 +msgid "published" +msgstr "opublikowane" + #: urls.py:11 msgid "past" msgstr "przeszle" @@ -69,3 +77,4 @@ msgstr "Organizator" #: templates/events/snippets/events_box.html:21 msgid "more events" msgstr "więcej wydarzeń" + diff --git a/events/migrations/0002_auto__add_field_event_published_pl__add_field_event_published_en.py b/events/migrations/0002_auto__add_field_event_published_pl__add_field_event_published_en.py new file mode 100644 index 0000000..a960391 --- /dev/null +++ b/events/migrations/0002_auto__add_field_event_published_pl__add_field_event_published_en.py @@ -0,0 +1,50 @@ +# -*- 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.published_pl' + db.add_column('events_event', 'published_pl', + self.gf('django.db.models.fields.BooleanField')(default=False), + keep_default=False) + + # Adding field 'Event.published_en' + db.add_column('events_event', 'published_en', + self.gf('django.db.models.fields.BooleanField')(default=False), + keep_default=False) + + if not db.dry_run: + orm.Event.objects.all().update(published_pl=True, published_en=True) + + + def backwards(self, orm): + # Deleting field 'Event.published_pl' + db.delete_column('events_event', 'published_pl') + + # Deleting field 'Event.published_en' + db.delete_column('events_event', 'published_en') + + + models = { + 'events.event': { + 'Meta': {'ordering': "['date']", 'object_name': 'Event'}, + 'date': ('django.db.models.fields.DateTimeField', [], {'max_length': '255', 'db_index': '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 9c216af..e20ae53 100644 --- a/events/models.py +++ b/events/models.py @@ -2,8 +2,10 @@ # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from django.conf import settings +from django.core.exceptions import ValidationError from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, ugettext from migdal.helpers import add_translatable @@ -19,9 +21,18 @@ class Event(models.Model): def __unicode__(self): return self.title + def clean(self): + for lc, ln in settings.LANGUAGES: + if (getattr(self, "published_%s" % lc) and + not getattr(self, "title_%s" % lc)): + raise ValidationError( + ugettext("Published event should have a title in relevant language (%s).") % lc) + add_translatable(Event, { - 'title': models.CharField(_('title'), max_length=255), - 'organizer': models.CharField(_('organizer'), max_length=255, db_index=True), - 'place': models.CharField(_('place'), max_length=255), + 'title': models.CharField(_('title'), max_length=255, blank=True), + 'organizer': models.CharField(_('organizer'), max_length=255, + db_index=True, blank=True), + 'place': models.CharField(_('place'), max_length=255, blank=True), + 'published': models.BooleanField(_('published'), default=False), }) diff --git a/events/templatetags/events_tags.py b/events/templatetags/events_tags.py index c9dd311..cd3e7da 100644 --- a/events/templatetags/events_tags.py +++ b/events/templatetags/events_tags.py @@ -12,7 +12,9 @@ from datetime import datetime @register.inclusion_tag('events/snippets/events_box.html', takes_context=True) def events_box(context, limit=app_settings.BOX_LENGTH): - objects = Event.objects.filter(date__gte=datetime.now())[:limit] + lang = context['request'].LANGUAGE_CODE + objects = Event.objects.filter(**{"published_%s" % lang: True}) + objects = objects.filter(date__gte=datetime.now())[:limit] return {'objects': objects} diff --git a/events/views.py b/events/views.py index c3c6197..b2dccc7 100644 --- a/events/views.py +++ b/events/views.py @@ -4,14 +4,17 @@ from events.models import Event def events(request): + events = Event.objects.filter(date__gte=datetime.now()) + events = events.filter(**{"published_%s" % request.LANGUAGE_CODE: True}) return render(request, 'events/event_list.html', { - 'object_list': Event.objects.filter(date__gte=datetime.now()) + 'object_list': events, }) def events_past(request): + events = Event.objects.filter(date__lte=datetime.now()).order_by('-date') + events = events.filter(**{"published_%s" % request.LANGUAGE_CODE: True}) return render(request, 'events/event_list.html', { - 'object_list': Event.objects.filter(date__lte=datetime.now() - ).order_by('-date'), + 'object_list': events, 'past': True, }) diff --git a/migdal/locale/pl/LC_MESSAGES/django.mo b/migdal/locale/pl/LC_MESSAGES/django.mo index 69768ac..e1b0148 100644 Binary files a/migdal/locale/pl/LC_MESSAGES/django.mo and b/migdal/locale/pl/LC_MESSAGES/django.mo differ diff --git a/migdal/locale/pl/LC_MESSAGES/django.po b/migdal/locale/pl/LC_MESSAGES/django.po index 3aa59ac..f15f991 100644 --- a/migdal/locale/pl/LC_MESSAGES/django.po +++ b/migdal/locale/pl/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: django-migdal 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-08-30 11:15+0200\n" -"PO-Revision-Date: 2012-08-30 11:17+0100\n" +"POT-Creation-Date: 2012-08-30 15:59+0200\n" +"PO-Revision-Date: 2012-08-30 16:00+0100\n" "Last-Translator: Radek Czajka \n" "Language-Team: FNP \n" "Language: Polish\n" @@ -47,7 +47,7 @@ msgid "latest" msgstr "ostatnie" #: feeds.py:32 -#: models.py:52 +#: models.py:54 msgid "entries" msgstr "wpisy" @@ -63,92 +63,97 @@ msgstr "Tytuł" msgid "Content" msgstr "Treść" -#: models.py:17 +#: models.py:19 msgid "taxonomy" msgstr "taksonomia" -#: models.py:21 +#: models.py:23 msgid "category" msgstr "kategoria" -#: models.py:22 -#: models.py:48 +#: models.py:24 +#: models.py:50 #: urls.py:41 #: urls.py:43 msgid "categories" msgstr "kategorie" -#: models.py:43 +#: models.py:45 msgid "author" msgstr "autor" -#: models.py:44 +#: models.py:46 msgid "author email" msgstr "e-mail autora" -#: models.py:45 +#: models.py:47 msgid "Used only to display gravatar and send notifications." msgstr "Używany tylko do wyświetlenia gravatara i wysyłania powiadomień." -#: models.py:46 +#: models.py:48 msgid "image" msgstr "obrazek" -#: models.py:47 +#: models.py:49 msgid "promoted" msgstr "promowane" -#: models.py:51 +#: models.py:53 msgid "entry" msgstr "wpis" -#: models.py:93 +#: models.py:77 +#, python-format +msgid "Published entry should have a slug in relevant language (%s)." +msgstr "Opublikowany wpis powinien mieć slug w odpowiednim języku (%s)." + +#: models.py:96 #, python-format msgid "Your story has been published at %s." msgstr "Twój wpis został opublikowany na stronie %s." -#: models.py:101 +#: models.py:104 msgid "needed" msgstr "potrzebne" -#: models.py:102 +#: models.py:105 msgid "Unneeded" msgstr "Niepotrzebne" -#: models.py:102 +#: models.py:105 msgid "Needed" msgstr "Potrzebne" -#: models.py:102 +#: models.py:105 msgid "Done" msgstr "Ukończone" -#: models.py:108 +#: models.py:111 msgid "title" msgstr "tytuł" -#: models.py:109 +#: models.py:112 msgid "lead" msgstr "lead" -#: models.py:110 -#: models.py:112 +#: models.py:113 +#: models.py:115 msgid "Use Textile syntax." msgstr "Włączona składnia Textile." -#: models.py:111 +#: models.py:114 msgid "body" msgstr "treść" -#: models.py:113 +#: models.py:116 msgid "published" msgstr "opublikowane" -#: models.py:118 +#: models.py:121 msgid "file" msgstr "plik" -#: models.py:136 +#: models.py:139 #, python-format msgid "New comment under your story at %s." msgstr "Nowy komentarz pod Twoim wpisem na stronie %s."