From 7a47f04940f28745309716d725b63a8278b29e62 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 30 Aug 2012 16:01:46 +0200 Subject: [PATCH 1/1] fixes #2359: unpublished events --- events/admin.py | 11 ++++ events/locale/pl/LC_MESSAGES/django.mo | Bin 1085 -> 1292 bytes events/locale/pl/LC_MESSAGES/django.po | 31 ++++++---- ...lished_pl__add_field_event_published_en.py | 50 +++++++++++++++ events/models.py | 19 ++++-- events/templatetags/events_tags.py | 4 +- events/views.py | 9 ++- migdal/locale/pl/LC_MESSAGES/django.mo | Bin 4305 -> 4465 bytes migdal/locale/pl/LC_MESSAGES/django.po | 57 ++++++++++-------- 9 files changed, 136 insertions(+), 45 deletions(-) create mode 100644 events/migrations/0002_auto__add_field_event_published_pl__add_field_event_published_en.py 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 bc4bd21528e5e41a32bf2e0febbb93c280ff0b0d..776da8473a398d4af6e1ea640a1faef3a274b392 100644 GIT binary patch delta 602 zcmYL_J4gdT5Qg^>qj~u*6cn98K^q@Pz*yKt0v55gJh>$~z3hd{U191Bq zQ3{MB?#6B0a2U*j6Ce*z#KL(e;7*_)g8k4>Kt6W~M!{>a3%muBq9Mc`HX{&P;5hgJ z@=GF^0{8pI4U%xAeB(y^DsIHX^T1&^pKBZD_KknGZT>?L^stbrNVV#gMb63V%B)LA zta%%jSuRL}Byuj53$|w&RM0DubaGACl4L4!q$Mjl@|Ldho}QO9HCdjXX|8MOSgGBj zd8+M47v^X_wUkmr^&in#|^k)A6 delta 395 zcmXxgKTE?v7{~ETnzm_DD_U?-ux}wnq;@R@o#NaM;t)zf16FY;NEg8+lc#hnbnPMt zE>^mU;tO!9yK6^r@cX3a!H*C3M7lKAZY0 zu2KI$Ie3mPeq$aNxQRcwjT>wx586dbwU\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 69768ac1db65890fb2252c2772cdb5e51abfcb72..e1b01484cdda10ae926367e221b20e3ef055bb39 100644 GIT binary patch delta 1494 zcmZwHOGs2v9LMp~q-B#?S@wQhO>-=@$<)$nVbsE)>>;#}79-wta-6ZIQH*FP0(TLG zi-L$iXjK$O5JE1pS_v6M5fMcQwJ}-v?#JDD4D)aRn{f~|!B50{Fmhcc9EXq zzH_L&qQf7SsXHELmaUjr;M_vIjXdKXn8TcIk5r8{1WTHs+mR$&A;;W^Za+(Dh#Jv@lR zsH+b0#i+!lMV!Bm<~$87(p^GLa22(K8|EOY-#ygbJ~SVr`aeP4@pEf`h1%E~%Ri#V zn?Q~8&GM-<6&=Z6YY6fxC|`P+{FJOz6!~DI<8VGuNP8MOUNK-Ad?H z)CsO7JiY&Vw{;gYrJhP5q1}}d>xuuBIvPuel|+E3C3M6yMc1LriCgYKIECM5i#k1pOfj;^|Oy=`aWh z8bXMd0*P2%3JNfmKw!(WPd~@CwGTgi$QJQy3wi#xOoaKK96+!5*`~ zo^#X07hkXef1_TA^0pd?b7{d=T#o&izycn|5#$vs<5rx+75Exk@iV6J7czG1VU!wZ zhRZPhTaKGN56)u>r%?^gqB?ww8qg=yOy`l0{oq2I_6OB)gwd;B9F-?gE7a!CQ>b<` zo)0Rgf6M!W-R@pg2P19~HISpo$4$IAy@VRreO!$**pKf}D-q#KtyBUJVh0Z67!Ke))QZd@UE0S+ z)?XcbMrC&r_2M1RAGnX*XQ+Wyk*&4$gl61FBnfS+R(2Dyk!T|_M4(w{DOM6X zhC_soekY-#v;Kdf4_ifa5xv9~LffDjFBTm=&UdY7U^|I+Vl$!t8WmPHsGV&knyvP< zn^;F^75*)05*<^OZNvtmK\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." -- 2.20.1