add in_stream Entry property,
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 13 Dec 2012 16:22:46 +0000 (17:22 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 13 Dec 2012 16:22:46 +0000 (17:22 +0100)
add interlang publication date

migdal/admin.py
migdal/api.py
migdal/feeds.py
migdal/migrations/0006_auto__add_field_entry_in_stream__add_field_entry_first_published_at.py [new file with mode: 0644]
migdal/models.py
migdal/templates/migdal/entry/entry_begin.html
migdal/templates/migdal/entry/entry_list.html
migdal/templates/migdal/entry/publications/entry_begin.html
setup.py

index 1a7fdd7..0df9352 100644 (file)
@@ -37,14 +37,15 @@ def filtered_entry_admin(typ):
             return field
 
         date_hierarchy = 'date'
             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 + (
             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': (
                 }),
         ) + tuple(
             (ln, {'fields': (
@@ -81,6 +82,7 @@ def filtered_entry_admin(typ):
                             app_settings.OBLIGATORY_LANGUAGES) + \
                 ('date', 'author') + \
                 _promo_if_necessary + \
                             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 + \
                 translated_fields(('published_at',)) + \
                 translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
         list_filter = _promo_if_necessary + \
index d4f031e..abd3b21 100644 (file)
@@ -8,10 +8,16 @@ from migdal import app_settings
 from django.utils.translation import get_language
 
 
 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()
     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:
     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])
     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
         object_list.promobox = promo
 
     return object_list
index 33e9e0b..3f49f32 100644 (file)
@@ -42,13 +42,12 @@ class EntriesFeed(Feed):
         return reverse('migdal_main')
 
     def items(self, obj):
         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):
 
     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("<img src='%s'/>" % image, item.lead)
 
         image = item.image.url if item.image else "/static/img/square-logo.png"
         return string_concat("<img src='%s'/>" % 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 (file)
index 0000000..8686f62
--- /dev/null
@@ -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
index c98b74f..4977562 100644 (file)
@@ -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)
             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'))
     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')
 
     class Meta:
         verbose_name = _('entry')
@@ -62,17 +64,18 @@ class Entry(models.Model):
         return self.title
 
     def save(self, *args, **kwargs):
         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
                     published_now = True
-            if published_now:
-                self.notify_author_published()
         super(Entry, self).save(*args, **kwargs)
         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:
 
     def clean(self):
         for lc, ln in settings.LANGUAGES:
index 161e359..c26d6fd 100644 (file)
@@ -9,7 +9,7 @@
 {% endif %}
 
 <div class="entry-data">
 {% endif %}
 
 <div class="entry-data">
-<div class="date">{{ object.published_at }}</div>
+<div class="date">{{ object.first_published_at }}</div>
 <div class="author">{{ object.author }}</div>
 
 <div class="categories">
 <div class="author">{{ object.author }}</div>
 
 <div class="categories">
index 3585adb..0dda2e8 100644 (file)
@@ -45,6 +45,9 @@
     </p>
 {% endif %}
 
     </p>
 {% endif %}
 
+{% if not object_list %}
+   <p class="warning">{% trans "Work in progress." %}</p>
+{% endif %}
 
 {% autopaginate object_list 10 %}
 {% for object in object_list %}
 
 {% autopaginate object_list 10 %}
 {% for object in object_list %}
index e9eae95..d277f2e 100644 (file)
@@ -8,24 +8,6 @@
 {% endif %}
 
 
 {% endif %}
 
 
-{% comment %}
-<div class="entry-data">
-{% if request.LANGUAGE_CODE == 'pl' %}
-    {% if object.published_en %}
-        {% language 'en' %}
-            <a href="{{ object.get_absolute_url }}">English version</a>
-        {% endlanguage %}
-    {% endif %}
-{% elif object.published_pl %}
-    {{ request.LANGUAGE_CODE }}
-    {% language 'pl' %}
-        <a href="{{ object.get_absolute_url }}">polska wersja</a>
-    {% endlanguage %}
-{% endif %}
-</div>
-{% endcomment %}
-
-
 {% if object.image %}
     <img class="entry-picture" src="{% thumbnail object.image "250x300" as thumb %}
                     {{ thumb.url }}
 {% if object.image %}
     <img class="entry-picture" src="{% thumbnail object.image "250x300" as thumb %}
                     {{ thumb.url }}
index ed6a8c7..3f77297 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def whole_trees(package_dir, paths):
 
 setup(
     name='django-migdal',
 
 setup(
     name='django-migdal',
-    version='0.1',
+    version='0.2',
     author='Radek Czajka',
     author_email='radoslaw.czajka@nowoczesnapolska.org.pl',
     url = '',
     author='Radek Czajka',
     author_email='radoslaw.czajka@nowoczesnapolska.org.pl',
     url = '',