Commits

psviderski committed 781b83d

Implemented pubread acl right for blog entries.

Comments (0)

Files changed (2)

MoinMoin/items/blog.py

 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
 
 
                  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,

MoinMoin/templates/blog/utils.html

         </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.") }}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.