From: Radek Czajka Date: Thu, 4 Oct 2012 11:00:33 +0000 (+0200) Subject: add publication dates, last change date X-Git-Url: https://git.mdrn.pl/prawokultury.git/commitdiff_plain/da08b3d204094543fbc810ba09a82cf0a8eabdf6?hp=9b6d232f7a8bc0ed1f9b090c06c8438db14e8179 add publication dates, last change date --- diff --git a/migdal/admin.py b/migdal/admin.py index 920f29c..d93a782 100644 --- a/migdal/admin.py +++ b/migdal/admin.py @@ -17,11 +17,13 @@ class AttachmentInline(admin.TabularInline): class EntryAdmin(admin.ModelAdmin): date_hierarchy = 'date' + readonly_fields = ('date', 'changed_at') + translated_fields(('published_at',)) fieldsets = ( - (None, {'fields': (('type', 'promo'), 'author', 'author_email', 'image', 'date')}), + (None, {'fields': (('type', 'promo'), 'author', 'author_email', 'image', 'date', 'changed_at')}), ) + tuple( (ln, {'fields': ( ('published_%s' % lc), + 'published_at_%s' % lc, 'title_%s' % lc, 'slug_%s' % lc, 'lead_%s' % lc, @@ -31,6 +33,7 @@ class EntryAdmin(admin.ModelAdmin): ) + tuple( (ln, {'fields': ( ('needed_%s' % lc, 'published_%s' % lc), + 'published_at_%s' % lc, 'title_%s' % lc, 'slug_%s' % lc, 'lead_%s' % lc, diff --git a/migdal/api.py b/migdal/api.py index 7fd6fe3..6f81a4d 100644 --- a/migdal/api.py +++ b/migdal/api.py @@ -10,7 +10,8 @@ from django.utils.translation import get_language def entry_list(entry_type=None, category=None, promobox=False): lang = get_language() - object_list = Entry.objects.filter(**{"published_%s" % lang: True}) + object_list = Entry.objects.filter(**{"published_%s" % lang: True} + ).order_by('-published_at_%s' % lang) if entry_type: object_list = object_list.filter(type=entry_type.db) else: diff --git a/migdal/feeds.py b/migdal/feeds.py index 8203735..53145c5 100644 --- a/migdal/feeds.py +++ b/migdal/feeds.py @@ -53,4 +53,4 @@ class EntriesFeed(Feed): return string_concat("" % image, item.lead) def item_pubdate(self, item): - return item.date + return item.published_at diff --git a/migdal/locale/pl/LC_MESSAGES/django.mo b/migdal/locale/pl/LC_MESSAGES/django.mo index e1b0148..f222f82 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 f15f991..8347953 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 15:59+0200\n" -"PO-Revision-Date: 2012-08-30 16:00+0100\n" +"POT-Creation-Date: 2012-10-04 12:58+0200\n" +"PO-Revision-Date: 2012-10-04 12:58+0100\n" "Last-Translator: Radek Czajka \n" "Language-Team: FNP \n" "Language: Polish\n" @@ -38,7 +38,7 @@ msgstr "tematy" msgid "types" msgstr "rodzaje" -#: admin.py:41 +#: admin.py:44 msgid "Categories" msgstr "Kategorie" @@ -47,7 +47,7 @@ msgid "latest" msgstr "ostatnie" #: feeds.py:32 -#: models.py:54 +#: models.py:56 msgid "entries" msgstr "wpisy" @@ -63,97 +63,109 @@ msgstr "Tytuł" msgid "Content" msgstr "Treść" -#: models.py:19 +#: models.py:20 msgid "taxonomy" msgstr "taksonomia" -#: models.py:23 +#: models.py:24 msgid "category" msgstr "kategoria" -#: models.py:24 -#: models.py:50 +#: models.py:25 +#: models.py:52 #: urls.py:41 #: urls.py:43 msgid "categories" msgstr "kategorie" #: models.py:45 +msgid "created at" +msgstr "data utworzenia" + +#: models.py:46 +msgid "changed at" +msgstr "data ostatniej zmiany" + +#: models.py:47 msgid "author" msgstr "autor" -#: models.py:46 +#: models.py:48 msgid "author email" msgstr "e-mail autora" -#: models.py:47 +#: models.py:49 msgid "Used only to display gravatar and send notifications." msgstr "Używany tylko do wyświetlenia gravatara i wysyłania powiadomień." -#: models.py:48 +#: models.py:50 msgid "image" msgstr "obrazek" -#: models.py:49 +#: models.py:51 msgid "promoted" msgstr "promowane" -#: models.py:53 +#: models.py:55 msgid "entry" msgstr "wpis" -#: models.py:77 +#: models.py:80 #, 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 +#: models.py:99 #, python-format msgid "Your story has been published at %s." msgstr "Twój wpis został opublikowany na stronie %s." -#: models.py:104 +#: models.py:105 msgid "needed" msgstr "potrzebne" -#: models.py:105 +#: models.py:106 msgid "Unneeded" msgstr "Niepotrzebne" -#: models.py:105 +#: models.py:106 msgid "Needed" msgstr "Potrzebne" -#: models.py:105 +#: models.py:106 msgid "Done" msgstr "Ukończone" -#: models.py:111 +#: models.py:112 msgid "title" msgstr "tytuł" -#: models.py:112 +#: models.py:113 msgid "lead" msgstr "lead" -#: models.py:113 -#: models.py:115 +#: models.py:114 +#: models.py:116 msgid "Use Textile syntax." msgstr "Włączona składnia Textile." -#: models.py:114 +#: models.py:115 msgid "body" msgstr "treść" -#: models.py:116 +#: models.py:117 msgid "published" msgstr "opublikowane" -#: models.py:121 +#: models.py:118 +msgid "published at" +msgstr "data publikacji" + +#: models.py:123 msgid "file" msgstr "plik" -#: models.py:139 +#: models.py:141 #, python-format msgid "New comment under your story at %s." msgstr "Nowy komentarz pod Twoim wpisem na stronie %s." diff --git a/migdal/migrations/0005_auto__add_field_entry_changed_at__add_field_entry_published_at_pl__add.py b/migdal/migrations/0005_auto__add_field_entry_changed_at__add_field_entry_published_at_pl__add.py new file mode 100644 index 0000000..2110ee4 --- /dev/null +++ b/migdal/migrations/0005_auto__add_field_entry_changed_at__add_field_entry_published_at_pl__add.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): + # Adding field 'Entry.changed_at' + db.add_column('migdal_entry', 'changed_at', + self.gf('django.db.models.fields.DateTimeField')(auto_now=True, default=datetime.datetime(2000, 1, 1, 0, 0), db_index=True, blank=True), + keep_default=False) + + # Adding field 'Entry.published_at_pl' + db.add_column('migdal_entry', 'published_at_pl', + self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), + keep_default=False) + + # Adding field 'Entry.published_at_en' + db.add_column('migdal_entry', 'published_at_en', + self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), + keep_default=False) + + if not db.dry_run: + for entry in orm['migdal.Entry'].objects.all(): + if entry.published_pl: + entry.published_at_pl = entry.date + if entry.published_en: + entry.published_at_en = entry.date + entry.save() + + + def backwards(self, orm): + # Deleting field 'Entry.changed_at' + db.delete_column('migdal_entry', 'changed_at') + + # Deleting field 'Entry.published_at_pl' + db.delete_column('migdal_entry', 'published_at_pl') + + # Deleting field 'Entry.published_at_en' + db.delete_column('migdal_entry', 'published_at_en') + + + models = { + 'migdal.attachment': { + 'Meta': {'object_name': 'Attachment'}, + 'entry': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['migdal.Entry']"}), + 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) + }, + 'migdal.category': { + 'Meta': {'object_name': 'Category'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'slug_en': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}), + 'slug_pl': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}), + 'taxonomy': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'title_en': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64', 'db_index': 'True'}), + 'title_pl': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64', 'db_index': 'True'}) + }, + 'migdal.entry': { + 'Meta': {'ordering': "['-date']", 'object_name': 'Entry'}, + '_body_en_rendered': ('django.db.models.fields.TextField', [], {}), + '_body_pl_rendered': ('django.db.models.fields.TextField', [], {}), + '_lead_en_rendered': ('django.db.models.fields.TextField', [], {}), + '_lead_pl_rendered': ('django.db.models.fields.TextField', [], {}), + 'author': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'author_email': ('django.db.models.fields.EmailField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}), + 'body_en': ('markupfield.fields.MarkupField', [], {'null': 'True', 'rendered_field': 'True', 'blank': 'True'}), + 'body_en_markup_type': ('django.db.models.fields.CharField', [], {'default': "'textile_pl'", 'max_length': '30', 'blank': 'True'}), + 'body_pl': ('markupfield.fields.MarkupField', [], {'null': 'True', 'rendered_field': 'True', 'blank': 'True'}), + 'body_pl_markup_type': ('django.db.models.fields.CharField', [], {'default': "'textile_pl'", 'max_length': '30', 'blank': 'True'}), + 'categories': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['migdal.Category']", 'null': 'True', 'blank': 'True'}), + 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}), + 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'lead_en': ('markupfield.fields.MarkupField', [], {'null': 'True', 'rendered_field': 'True', 'blank': 'True'}), + 'lead_en_markup_type': ('django.db.models.fields.CharField', [], {'default': "'textile_pl'", 'max_length': '30', 'blank': 'True'}), + 'lead_pl': ('markupfield.fields.MarkupField', [], {'null': 'True', 'rendered_field': 'True', 'blank': 'True'}), + 'lead_pl_markup_type': ('django.db.models.fields.CharField', [], {'default': "'textile_pl'", 'max_length': '30', 'blank': 'True'}), + 'needed_en': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '1', 'db_index': 'True'}), + 'promo': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'published_at_en': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'published_at_pl': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'published_en': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'published_pl': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'slug_en': ('migdal.fields.SlugNullField', [], {'max_length': '50', 'unique': 'True', 'null': 'True', 'blank': 'True'}), + 'slug_pl': ('migdal.fields.SlugNullField', [], {'max_length': '50', 'unique': 'True', 'null': 'True', 'blank': 'True'}), + 'title_en': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'title_pl': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'type': ('django.db.models.fields.CharField', [], {'max_length': '16', 'db_index': 'True'}) + } + } + + complete_apps = ['migdal'] \ No newline at end of file diff --git a/migdal/models.py b/migdal/models.py index e3f7819..028350c 100644 --- a/migdal/models.py +++ b/migdal/models.py @@ -2,6 +2,7 @@ # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from datetime import datetime from django.conf import settings from django.contrib.sites.models import Site from django.core.exceptions import ValidationError @@ -41,7 +42,8 @@ class Entry(models.Model): type = models.CharField(max_length=16, choices=((t.db, t.slug) for t in app_settings.TYPES), db_index=True) - date = models.DateTimeField(auto_now_add=True, db_index=True, editable=True) + date = models.DateTimeField(_('created at'), auto_now_add=True, db_index=True) + changed_at = models.DateTimeField(_('changed at'), auto_now=True, db_index=True) author = models.CharField(_('author'), max_length=128) author_email = models.EmailField(_('author email'), max_length=128, null=True, blank=True, help_text=_('Used only to display gravatar and send notifications.')) @@ -62,8 +64,9 @@ class Entry(models.Model): orig = type(self).objects.get(pk=self.pk) published_now = False for lc, ln in settings.LANGUAGES: - if (not getattr(orig, "published_%s" % lc) and - getattr(self, "published_%s" % lc)): + if (getattr(self, "published_%s" % lc) + and getattr(self, "published_at_%s" % lc) is None): + setattr(self, "published_at_%s" % lc, datetime.now()) published_now = True if published_now: self.notify_author_published() @@ -96,9 +99,7 @@ class Entry(models.Model): ugettext(u'Your story has been published at %s.') % site.domain, mail_text, settings.SERVER_EMAIL, [self.author_email] ) - - - + add_translatable(Entry, languages=app_settings.OPTIONAL_LANGUAGES, fields={ 'needed': models.CharField(_('needed'), max_length=1, db_index=True, choices=( @@ -114,6 +115,7 @@ add_translatable(Entry, { 'body': MarkupField(_('body'), markup_type='textile_pl', null=True, blank=True, help_text=_('Use Textile syntax.')), 'published': models.BooleanField(_('published'), default=False), + 'published_at': models.DateTimeField(_('published at'), null=True, blank=True), }) diff --git a/migdal/templates/migdal/entry/entry_begin.html b/migdal/templates/migdal/entry/entry_begin.html index 9f07e0d..12f49ae 100755 --- a/migdal/templates/migdal/entry/entry_begin.html +++ b/migdal/templates/migdal/entry/entry_begin.html @@ -9,7 +9,7 @@ {% endif %}
-
{{ object.date }}
+
{{ object.published_at }}
{{ object.author }}
{% comment %}