changeset 1449:b472a506db2e

Fix supertags widget. Clicking on supertags modify the filter for the blog entries main listing.
author Pavel Sviderski <pavel@psviderski.name>
date Wed, 25 Jul 2012 15:14:04 +0200
parents 9ab2ca1f385b
children 90d02867e144
files MoinMoin/apps/frontend/views.py MoinMoin/constants/keys.py MoinMoin/storage/middleware/indexing.py MoinMoin/templates/blog.html MoinMoin/templates/blog_layout.html MoinMoin/templates/layout.html
diffstat 6 files changed, 65 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Tue Jul 24 17:16:41 2012 +0200
+++ b/MoinMoin/apps/frontend/views.py	Wed Jul 25 15:14:04 2012 +0200
@@ -469,6 +469,13 @@
 @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 consist 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)
@@ -479,18 +486,22 @@
     # TODO: move to BlogItem class
     prefix = item_name + u'/'
     current_timestamp = int(time.time())
-    query = And([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))
-                ])
+    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',
-                           title_name=item.name,
+                           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'])
@@ -510,7 +521,7 @@
     if isinstance(blog_item, NonExistent):
         abort(404, blog_item_name)
     return render_template('blog_entry.html',
-                           title_name=item.name,
+                           item_name=item.name,
                            blog_item=blog_item,
                            blog_entry_item=item,
                           )
--- a/MoinMoin/constants/keys.py	Tue Jul 24 17:16:41 2012 +0200
+++ b/MoinMoin/constants/keys.py	Wed Jul 25 15:14:04 2012 +0200
@@ -82,10 +82,10 @@
 DISABLED = "disabled"
 
 # keys for blog homepages
-LOGO = "logo"
-SUPERTAGS = "supertags"
-# keys for blog posts
-PTIME = "ptime"
+LOGO = u"logo"
+SUPERTAGS = u"supertags"
+# keys for blog entries
+PTIME = u"ptime"
 
 # index names
 LATEST_REVS = 'latest_revs'
--- a/MoinMoin/storage/middleware/indexing.py	Tue Jul 24 17:16:41 2012 +0200
+++ b/MoinMoin/storage/middleware/indexing.py	Wed Jul 25 15:14:04 2012 +0200
@@ -271,11 +271,11 @@
         }
         latest_revs_fields.update(**userprofile_fields)
 
-        blogpost_fields = {
+        blog_entry_fields = {
             # publish time from metadata (converted to UTC datetime)
             PTIME: DATETIME(stored=True)
         }
-        latest_revs_fields.update(**blogpost_fields)
+        latest_revs_fields.update(**blog_entry_fields)
 
         all_revs_fields = {
             ITEMID: ID(stored=True),
--- a/MoinMoin/templates/blog.html	Tue Jul 24 17:16:41 2012 +0200
+++ b/MoinMoin/templates/blog.html	Wed Jul 25 15:14:04 2012 +0200
@@ -1,11 +1,29 @@
 {% 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) %}
+{% endif %}
+
+{% block pagepath %}
+    {{ super() }}
+    {% if supertag %}
+        <span class="sep">/</span>
+        {{ _("Category:") }}
+        {% if blog_name %}
+            <a href="{{ url_for('frontend.show_blog', item_name=blog_name, supertag=supertag) }}">{{ supertag }}</a>
+        {% else %}
+            {{ supertag }}
+        {% endif %}
+    {% endif %}
+{% endblock %}
+
 {% block blog_content %}
     {% if blog_entry_items %}
         {% for entry_item in blog_entry_items %}
             {{ show_blog_entry(entry_item) }}
         {% endfor %}
     {% else %}
-        {{ _("There are no entries in this blog.") }}
+        {{ no_entries_msg }}
     {% endif %}
 {% endblock %}
--- a/MoinMoin/templates/blog_layout.html	Tue Jul 24 17:16:41 2012 +0200
+++ b/MoinMoin/templates/blog_layout.html	Wed Jul 25 15:14:04 2012 +0200
@@ -10,8 +10,13 @@
     <h1><a href="{{ url_for('frontend.show_item', item_name=entry_item.name) }}"
         title="{{ title }}" class="moin-blog-entry-link">{{ title }}</a></h1>
     <div class="moin-blog-entry-info">
-        {{ _("Published on") }} {{ entry_item.meta['ptime']|datetimeformat }}
-        {{ _("by") }} {{ utils.editor_info(entry_item.meta) }}
+        {% set publish_time = entry_item.meta['ptime'] %}
+        {% if publish_time %}
+            {{ _("Published on") }} {{ entry_item.meta['ptime']|datetimeformat }}
+            {{ _("by") }} {{ utils.editor_info(entry_item.meta) }}
+        {% else %}
+            {{ _("It is not published yet.") }}
+        {% endif %}
     </div>
     <div class="moin-blog-entry-content">
         {{ entry_item._render_data()|safe }} {# rendered blog entry content #}
@@ -35,12 +40,12 @@
     </div>
 {% endmacro %}
 
-{% macro widget_categories(categories) %}
+{% macro widget_supertags(blog_name, supertags) %}
     <div id="moin-blog-categories">
         <h2>{{ _("Categories") }}</h2>
         <ul>
-            {% for category in categories %}
-                <li><a href="{{ url_for('frontend.tagged_items', tag=category) }}">{{ category }}</a></li>
+            {% for supertag in supertags %}
+                <li><a href="{{ url_for('frontend.show_blog', item_name=blog_name, supertag=supertag) }}">{{ supertag }}</a></li>
             {% endfor %}
         </ul>
     </div>
@@ -48,7 +53,8 @@
 
 {% if blog_item %}
     {% set blog_header = blog_item._render_data()|safe %}
-    {% set categories = blog_item.meta['supertags'] %}
+    {% set blog_name = blog_item.name %}
+    {% set supertags = blog_item.meta['supertags'] %}
 {% endif %}
 
 {% block content %}
@@ -62,11 +68,11 @@
             <div id="moin-blog-content">
             {% block blog_content %}<br />{% endblock %}
             </div>
-            {% if categories %}
+            {% if blog_name and supertags %}
                 <div id="moin-blog-sidebar">
-                    {{ widget_categories(categories) }}
+                    {{ widget_supertags(blog_name, supertags) }}
                 </div>
-            {% endif %} 
+            {% endif %}
         </div>
     {% endblock %}
 {% endblock %}
--- a/MoinMoin/templates/layout.html	Tue Jul 24 17:16:41 2012 +0200
+++ b/MoinMoin/templates/layout.html	Wed Jul 25 15:14:04 2012 +0200
@@ -36,7 +36,7 @@
 
     <div id="moin-username">
         {% if user.valid -%}
-	    {% set avatar = user.avatar(20) %}
+            {% set avatar = user.avatar(20) %}
             {% if avatar %}
                 <img id="moin-avatar" rel="noreferrer" src="{{ avatar }}" />
             {%- endif %}
@@ -76,22 +76,24 @@
         {%- endif %}
         <span id="moin-pagelocation">
             <span class="moin-pagepath">
+            {% block pagepath %}
                 {% for segment_name, segment_path, exists in theme_supp.location_breadcrumbs(item_name) -%}
                     {% if not loop.last -%}
                         <a href="{{ url_for('frontend.show_item', item_name=segment_path) }}" {% if not exists %}class="moin-nonexistent"{% endif %}>
                             {{ segment_name|shorten_item_name }}
                         </a>
-			<span class="sep">/</span>
+                        <span class="sep">/</span>
                     {% else %}
-		        {% if title_name %}
+                        {% if title_name %}
                             {{ title_name }}
                         {% else %}
                         <a href="{{ url_for('frontend.show_item', item_name=segment_path) }}" {% if not exists %}class="moin-nonexistent"{% endif %}>
                             {{ segment_name|shorten_item_name }}
                         </a>
-		        {%- endif %}
+                        {%- endif %}
                     {%- endif %}
                 {%- endfor %}
+            {% endblock %}
             </span>
         </span>
     </div>