changeset 1851:781b83dce636

Implemented pubread acl right for blog entries.
author Pavel Sviderski <pavel@psviderski.name>
date Fri, 02 Nov 2012 14:28:05 +0100
parents 920de041c03f
children 2af1b7d032bb
files MoinMoin/items/blog.py MoinMoin/templates/blog/utils.html
diffstat 2 files changed, 18 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/items/blog.py	Thu Nov 01 21:22:30 2012 +0100
+++ b/MoinMoin/items/blog.py	Fri Nov 02 14:28:05 2012 +0100
@@ -14,12 +14,13 @@
 from flask import current_app as app
 
 from whoosh.query import Term, And, Prefix, DateRange
+from whoosh.sorting import FunctionFacet
 
 from MoinMoin.i18n import L_
 from MoinMoin.themes import render_template
 from MoinMoin.forms import OptionalText, Tags, DateTime
 from MoinMoin.storage.middleware.protecting import AccessDenied
-from MoinMoin.constants.keys import NAME, NAME_EXACT, WIKINAME, ITEMTYPE, PTIME, TAGS
+from MoinMoin.constants.keys import NAME, NAME_EXACT, WIKINAME, ITEMTYPE, MTIME, PTIME, TAGS
 from MoinMoin.items import Item, Default, register, BaseMetaForm
 
 
@@ -63,13 +64,23 @@
                  Term(ITEMTYPE, ITEMTYPE_BLOG_ENTRY),
                  # Only sub items of this item
                  Prefix(NAME_EXACT, prefix),
-                 # Filter out those items that do not have a PTIME meta or PTIME is in the future.
-                 DateRange(PTIME, start=None, end=datetime.utcfromtimestamp(current_timestamp)),
                 ]
         if tag:
             terms.append(Term(TAGS, tag))
         query = And(terms)
-        revs = flaskg.storage.search(query, sortedby=[PTIME], reverse=True, limit=None)
+
+        def ptime_sort_key(searcher, docnum):
+            """
+            Compute the publication time key for blog entries sorting.
+
+            If PTIME is not defined, we use MTIME.
+            """
+            fields = searcher.stored_fields(docnum)
+            ptime = fields.get(PTIME, fields[MTIME])
+            return ptime
+        ptime_sort_facet = FunctionFacet(ptime_sort_key)
+
+        revs = flaskg.storage.search(query, sortedby=ptime_sort_facet, reverse=True, limit=None)
         blog_entry_items = [Item.create(rev.meta[NAME], rev_id=rev.revid) for rev in revs]
         return render_template('blog/main.html',
                                item_name=self.name,
--- a/MoinMoin/templates/blog/utils.html	Thu Nov 01 21:22:30 2012 +0100
+++ b/MoinMoin/templates/blog/utils.html	Fri Nov 02 14:28:05 2012 +0100
@@ -16,9 +16,9 @@
         </div>
     {% endif %}
     <div class="moin-blog-entry-info">
-        {% set publish_time = entry_item.meta['ptime'] %}
-        {% if publish_time %}
-            {{ _("Published on") }} {{ entry_item.meta['ptime']|datetimeformat }}
+        {% set publication_time = entry_item.meta['ptime'] or entry_item.meta['mtime'] %}
+        {% if publication_time %}
+            {{ _("Published on") }} {{ publication_time|datetimeformat }}
             {{ _("by") }} {{ utils.editor_info(entry_item.meta) }}
         {% else %}
             {{ _("Not published yet.") }}