changeset 1676:36ae694c4122

merged
author Pavel Sviderski <pavel@psviderski.name>
date Mon, 13 Aug 2012 13:50:18 +0200
parents dcea928c99bf (current diff) b0ba46ffe914 (diff)
children d74b9e4d41e5 959d9a202b6e
files MoinMoin/items/__init__.py
diffstat 4 files changed, 52 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Mon Aug 13 17:08:16 2012 +0800
+++ b/MoinMoin/apps/frontend/views.py	Mon Aug 13 13:50:18 2012 +0200
@@ -498,66 +498,6 @@
     return item.do_modify()
 
 
-@frontend.route('/+blog/+<rev>/<itemname:item_name>', methods=['GET'])
-@frontend.route('/+blog/<itemname:item_name>', defaults=dict(rev=CURRENT), methods=['GET'])
-def show_blog(item_name, rev):
-    """
-    Show a blog item and a list of blog entries below it.
-
-    If supertag GET-parameter is defined, the list of blog entries consists only
-    of those entries that contain the supertag value in their lists of tags.
-    """
-    supertag = request.values.get('supertag')
-    flaskg.user.add_trail(item_name)
-    try:
-        item = Item.create(item_name, rev_id=rev)
-    except AccessDenied:
-        abort(403)
-    if isinstance(item, NonExistent):
-        abort(404, item_name)
-    prefix = item_name + u'/'
-    current_timestamp = int(time.time())
-    terms = [Term(WIKINAME, app.cfg.interwikiname),
-             # 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 supertag:
-        terms.append(Term(TAGS, supertag))
-    query = And(terms)
-    revs = flaskg.storage.search(query, sortedby=[PTIME], reverse=True, limit=None)
-    blog_entry_items = [Item.create(rev.meta[NAME], rev_id=rev.revid) for rev in revs]
-    return render_template('blog.html',
-                           item_name=item.name,
-                           blog_item=item,
-                           blog_entry_items=blog_entry_items,
-                           supertag=supertag,
-                          )
-
-@frontend.route('/+blog_entry/+<rev>/<itemname:item_name>', methods=['GET'])
-@frontend.route('/+blog_entry/<itemname:item_name>', defaults=dict(rev=CURRENT), methods=['GET'])
-def show_blog_entry(item_name, rev):
-    flaskg.user.add_trail(item_name)
-    blog_item_name = item_name.rsplit('/', 1)[0]
-    if blog_item_name == item_name:
-        abort(403)
-    try:
-        item = Item.create(item_name, rev_id=rev)
-        blog_item = Item.create(blog_item_name)
-    except AccessDenied:
-        abort(403)
-    if isinstance(item, NonExistent):
-        abort(404, item_name)
-    if isinstance(blog_item, NonExistent):
-        abort(404, blog_item_name)
-    return render_template('blog_entry.html',
-                           item_name=item.name,
-                           blog_item=blog_item,
-                           blog_entry_item=item,
-                          )
-
-
 class TargetChangeForm(BaseChangeForm):
     target = RequiredText.using(label=L_('Target')).with_properties(placeholder=L_("The name of the target item"))
 
--- a/MoinMoin/items/__init__.py	Mon Aug 13 17:08:16 2012 +0800
+++ b/MoinMoin/items/__init__.py	Mon Aug 13 13:50:18 2012 +0200
@@ -23,13 +23,14 @@
 from StringIO import StringIO
 from collections import namedtuple
 from functools import partial
+from datetime import datetime
 
 from flatland import Form
 from flatland.validation import Validator
 
 from jinja2 import Markup
 
-from whoosh.query import Term, And, Prefix
+from whoosh.query import Term, And, Prefix, DateRange
 
 from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags, DateTime, Submit
 
@@ -54,7 +55,7 @@
 from MoinMoin.storage.error import NoSuchItemError, NoSuchRevisionError, StorageError
 from MoinMoin.util.registry import RegistryBase
 from MoinMoin.constants.keys import (
-    NAME, NAME_OLD, NAME_EXACT, WIKINAME, MTIME, SYSITEM_VERSION, ITEMTYPE,
+    NAME, NAME_OLD, NAME_EXACT, WIKINAME, MTIME, PTIME, SYSITEM_VERSION, ITEMTYPE,
     CONTENTTYPE, SIZE, TAGS, ACTION, ADDRESS, HOSTNAME, USERID, COMMENT,
     HASH_ALGORITHM, ITEMID, REVID, DATAID, CURRENT, PARENTID
     )
@@ -700,6 +701,34 @@
         meta_form = BlogMetaForm
         meta_template = 'modify_blog_meta.html'
 
+    def do_show(self, revid):
+        """
+        Show a blog item and a list of its blog entries below it.
+
+        If tag GET-parameter is defined, the list of blog entries consists only
+        of those entries that contain the tag value in their lists of tags.
+        """
+        # for now it is just one tag=value, later it could be tag=value1&tag=value2&...
+        tag = request.values.get('tag')
+        prefix = self.name + u'/'
+        current_timestamp = int(time.time())
+        terms = [Term(WIKINAME, app.cfg.interwikiname),
+                 # 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)
+        blog_entry_items = [Item.create(rev.meta[NAME], rev_id=rev.revid) for rev in revs]
+        return render_template('blog.html',
+                               item_name=self.name,
+                               blog_item=self,
+                               blog_entry_items=blog_entry_items,
+                               tag=tag,
+                              )
 
 @register
 class BlogEntry(Default):
@@ -709,6 +738,21 @@
         meta_form = BlogEntryMetaForm
         meta_template = 'modify_blog_entry_meta.html'
 
+    def do_show(self, revid):
+        blog_item_name = self.name.rsplit('/', 1)[0]
+        try:
+            blog_item = Item.create(blog_item_name)
+        except AccessDenied:
+            abort(403)
+        if not isinstance(blog_item, Blog):
+            # The parent item of this blog entry item is not a Blog item.
+            abort(403)
+        return render_template('blog_entry.html',
+                               item_name=self.name,
+                               blog_item=blog_item,
+                               blog_entry_item=self,
+                              )
+
 
 from ..util.pysupport import load_package_modules
 load_package_modules(__name__, __path__)
--- a/MoinMoin/templates/blog.html	Mon Aug 13 17:08:16 2012 +0800
+++ b/MoinMoin/templates/blog.html	Mon Aug 13 13:50:18 2012 +0200
@@ -1,19 +1,19 @@
 {% extends theme("blog_layout.html") %}
 
 {% set no_entries_msg = _("There are no entries in this blog.") %}
-{% if supertag %}
-    {% set no_entries_msg = _("There are no entries in the \"%(supertag)s\" blog category.", supertag=supertag) %}
+{% if tag %}
+    {% set no_entries_msg = _("There are no entries in the '%(tag)s' blog category.", tag=tag) %}
 {% endif %}
 
 {% block pagepath %}
     {{ super() }}
-    {% if supertag %}
+    {% if tag %}
         <span class="sep">/</span>
         {{ _("Category:") }}
         {% if blog_name %}
-            <a href="{{ url_for('frontend.show_blog', item_name=blog_name, supertag=supertag) }}">{{ supertag }}</a>
+            <a href="{{ url_for('frontend.show_item', item_name=blog_name, tag=tag) }}">{{ tag }}</a>
         {% else %}
-            {{ supertag }}
+            {{ tag }}
         {% endif %}
     {% endif %}
 {% endblock %}
--- a/MoinMoin/templates/blog_layout.html	Mon Aug 13 17:08:16 2012 +0800
+++ b/MoinMoin/templates/blog_layout.html	Mon Aug 13 13:50:18 2012 +0200
@@ -46,7 +46,7 @@
         <h2>{{ _("Categories") }}</h2>
         <ul>
             {% for supertag in supertags %}
-                <li><a href="{{ url_for('frontend.show_blog', item_name=blog_name, supertag=supertag) }}">{{ supertag }}</a></li>
+                <li><a href="{{ url_for('frontend.show_item', item_name=blog_name, tag=supertag) }}">{{ supertag }}</a></li>
             {% endfor %}
         </ul>
     </div>