From: Radek Czajka Date: Thu, 13 Dec 2012 16:22:46 +0000 (+0100) Subject: add in_stream Entry property, X-Git-Tag: 0.3.1~5 X-Git-Url: https://git.mdrn.pl/django-migdal.git/commitdiff_plain/476685a9de9b8380c5c8ee71d63d6d6020533926?ds=sidebyside add in_stream Entry property, add interlang publication date --- diff --git a/migdal/admin.py b/migdal/admin.py index 1a7fdd7..0df9352 100644 --- a/migdal/admin.py +++ b/migdal/admin.py @@ -37,14 +37,15 @@ def filtered_entry_admin(typ): return field date_hierarchy = 'date' - readonly_fields = ('date', 'changed_at') + \ + readonly_fields = ('date', 'changed_at', 'first_published_at') + \ translated_fields(('published_at',)) _promo_if_necessary = ('promo',) if typ.promotable else () fieldsets = ( (None, { 'fields': _promo_if_necessary + ( - 'author', 'author_email', 'image', 'date', 'changed_at') + 'in_stream', 'author', 'author_email', 'image', + 'date', 'first_published_at', 'changed_at') }), ) + tuple( (ln, {'fields': ( @@ -81,6 +82,7 @@ def filtered_entry_admin(typ): app_settings.OBLIGATORY_LANGUAGES) + \ ('date', 'author') + \ _promo_if_necessary + \ + ('in_stream', 'first_published_at',) + \ translated_fields(('published_at',)) + \ translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) list_filter = _promo_if_necessary + \ diff --git a/migdal/api.py b/migdal/api.py index d4f031e..abd3b21 100644 --- a/migdal/api.py +++ b/migdal/api.py @@ -8,10 +8,16 @@ from migdal import app_settings from django.utils.translation import get_language -def entry_list(entry_type=None, category=None, promobox=False): +def entry_list(entry_type=None, category=None, promobox=False, + for_feed=False): lang = get_language() - object_list = Entry.objects.filter(**{"published_%s" % lang: True} - ).order_by('-published_at_%s' % lang) + object_list = Entry.objects.filter(**{"published_%s" % lang: True}) + + if for_feed: + object_list = object_list.order_by('-published_at_%s' % lang) + else: + object_list = object_list.order_by('-first_published_at') + if entry_type: object_list = object_list.filter(type=entry_type.db) else: @@ -23,6 +29,10 @@ def entry_list(entry_type=None, category=None, promobox=False): if promobox: promo = list(object_list.filter(promo=True)[:promobox]) #object_list = object_list.exclude(pk__in=[p.pk for p in promo]) + + object_list = object_list.filter(in_stream=True) + + if promobox: object_list.promobox = promo return object_list diff --git a/migdal/feeds.py b/migdal/feeds.py index 33e9e0b..3f49f32 100644 --- a/migdal/feeds.py +++ b/migdal/feeds.py @@ -42,13 +42,12 @@ class EntriesFeed(Feed): return reverse('migdal_main') def items(self, obj): - return api.entry_list(**obj) + return api.entry_list(for_feed=True, **obj) def item_title(self, item): return item.title def item_description(self, item): - return item.lead image = item.image.url if item.image else "/static/img/square-logo.png" return string_concat("" % image, item.lead) diff --git a/migdal/migrations/0006_auto__add_field_entry_in_stream__add_field_entry_first_published_at.py b/migdal/migrations/0006_auto__add_field_entry_in_stream__add_field_entry_first_published_at.py new file mode 100644 index 0000000..8686f62 --- /dev/null +++ b/migdal/migrations/0006_auto__add_field_entry_in_stream__add_field_entry_first_published_at.py @@ -0,0 +1,93 @@ +# -*- 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.in_stream' + db.add_column('migdal_entry', 'in_stream', + self.gf('django.db.models.fields.BooleanField')(default=True), + keep_default=False) + + # Adding field 'Entry.first_published_at' + db.add_column('migdal_entry', 'first_published_at', + self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), + keep_default=False) + + if not db.dry_run: + for entry in orm.Entry.objects.exclude( + published_at_en=None, published_at_pl=None): + if entry.published_at_en and entry.published_at_pl: + entry.first_published_at = min( + entry.published_at_en, entry.published_at_pl) + else: + entry.first_published_at = ( + entry.published_at_en or entry.published_at_pl) + entry.save() + + def backwards(self, orm): + # Deleting field 'Entry.in_stream' + db.delete_column('migdal_entry', 'in_stream') + + # Deleting field 'Entry.first_published_at' + db.delete_column('migdal_entry', 'first_published_at') + + + 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'}), + 'first_published_at': ('django.db.models.fields.DateTimeField', [], {'null': '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'}), + 'in_stream': ('django.db.models.fields.BooleanField', [], {'default': '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 c98b74f..4977562 100644 --- a/migdal/models.py +++ b/migdal/models.py @@ -51,7 +51,9 @@ class Entry(models.Model): help_text=_('Used only to display gravatar and send notifications.')) image = models.ImageField(_('image'), upload_to='entry/image/', null=True, blank=True) promo = models.BooleanField(_('promoted'), default=False) + in_stream = models.BooleanField(_('in stream'), default=True) categories = models.ManyToManyField(Category, null=True, blank=True, verbose_name=_('categories')) + first_published_at = models.DateTimeField(_('published at'), null=True, blank=True) class Meta: verbose_name = _('entry') @@ -62,17 +64,18 @@ class Entry(models.Model): return self.title def save(self, *args, **kwargs): - if self.pk is not None: - orig = type(self).objects.get(pk=self.pk) - published_now = False - for lc, ln in settings.LANGUAGES: - 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 = False + for lc, ln in settings.LANGUAGES: + if (getattr(self, "published_%s" % lc) + and getattr(self, "published_at_%s" % lc) is None): + now = datetime.now() + setattr(self, "published_at_%s" % lc, now) + if self.first_published_at is None: + self.first_published_at = now published_now = True - if published_now: - self.notify_author_published() super(Entry, self).save(*args, **kwargs) + if published_now and self.pk is not None: + self.notify_author_published() def clean(self): for lc, ln in settings.LANGUAGES: diff --git a/migdal/templates/migdal/entry/entry_begin.html b/migdal/templates/migdal/entry/entry_begin.html index 161e359..c26d6fd 100644 --- a/migdal/templates/migdal/entry/entry_begin.html +++ b/migdal/templates/migdal/entry/entry_begin.html @@ -9,7 +9,7 @@ {% endif %}
-
{{ object.published_at }}
+
{{ object.first_published_at }}
{{ object.author }}
diff --git a/migdal/templates/migdal/entry/entry_list.html b/migdal/templates/migdal/entry/entry_list.html index 3585adb..0dda2e8 100644 --- a/migdal/templates/migdal/entry/entry_list.html +++ b/migdal/templates/migdal/entry/entry_list.html @@ -45,6 +45,9 @@

{% endif %} +{% if not object_list %} +

{% trans "Work in progress." %}

+{% endif %} {% autopaginate object_list 10 %} {% for object in object_list %} diff --git a/migdal/templates/migdal/entry/publications/entry_begin.html b/migdal/templates/migdal/entry/publications/entry_begin.html index e9eae95..d277f2e 100644 --- a/migdal/templates/migdal/entry/publications/entry_begin.html +++ b/migdal/templates/migdal/entry/publications/entry_begin.html @@ -8,24 +8,6 @@ {% endif %} -{% comment %} -
-{% if request.LANGUAGE_CODE == 'pl' %} - {% if object.published_en %} - {% language 'en' %} - English version - {% endlanguage %} - {% endif %} -{% elif object.published_pl %} - {{ request.LANGUAGE_CODE }} - {% language 'pl' %} - polska wersja - {% endlanguage %} -{% endif %} -
-{% endcomment %} - - {% if object.image %}