changeset 1442:11a61fb8d985

Add simple +blog view and blog template (with tags listing). SUMMARY meta is used as a title link of each blog post.
author Pavel Sviderski <pavel@psviderski.name>
date Thu, 21 Jun 2012 02:56:28 +0400
parents f87452b408df
children 7e52a847d5ff
files MoinMoin/apps/frontend/views.py MoinMoin/templates/blog.html MoinMoin/themes/modernized/static/css/common.css
diffstat 3 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sat Jun 09 00:04:57 2012 +0400
+++ b/MoinMoin/apps/frontend/views.py	Thu Jun 21 02:56:28 2012 +0400
@@ -461,6 +461,33 @@
     return item.do_modify(contenttype, template_name)
 
 
+@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):
+    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)
+    # 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))
+                ])
+    revs = flaskg.storage.search(query, sortedby=[PTIME], reverse=True, limit=None)
+    blog_post_items = [Item.create(rev.meta[NAME], rev_id=rev.revid) for rev in revs]
+    return render_template('blog.html',
+                           item=item, item_name=item.name,
+                           blog_post_items=blog_post_items,
+                          )
+
+
 class CommentForm(TextChaizedForm):
     comment = String.using(label=L_('Comment'), optional=True).with_properties(placeholder=L_("Comment about your change"))
     submit = String.using(default=L_('OK'), optional=True)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/templates/blog.html	Thu Jun 21 02:56:28 2012 +0400
@@ -0,0 +1,35 @@
+{% extends theme("layout.html") %}
+{% import "utils.html" as utils %}
+
+{% block content %}
+    {% block content_data %}
+        <div id="moin-content-data">
+            {{ item._render_data()|safe }} {# rendered blog header #}
+            {% for post_item in blog_post_items %}
+                {% if post_item.meta['summary'] %}
+                    {% set title = post_item.meta['summary'] %}
+                {% else %}
+                    {% set title = post_item.name %}
+                {% endif %}
+                <h1><a href="{{ url_for('frontend.show_item', item_name=post_item.name) }}"
+                    title="{{ title }}" class="moin-post-link">{{ title }}</a></h1>
+                <p class="moin-post-info">
+                    {{ _("Posted on") }} {{ post_item.meta['ptime']|datetimeformat }}
+                    {{ _("by") }} {{ utils.editor_info(post_item.meta) }}
+                </p>
+                {{ post_item._render_data()|safe }} {# rendered post content #}
+                {% if post_item.meta['tags'] %} {# display a post's tags as a list if they existed #}
+                    {% set tags = post_item.meta['tags']|sort %}
+                    <div class="moin-post-tags">
+                        {{ _("Tags:") }}
+                        <ul class="moin-post-tags">
+                            {% for tag in tags %}
+                                <li><a href="{{ url_for('frontend.tagged_items', tag=tag) }}">{{ tag }}</a></li>
+                            {% endfor %}
+                        </ul>
+                    </div>
+                {% endif %}
+            {% endfor %}
+        </div>
+    {% endblock %}
+{% endblock %}
--- a/MoinMoin/themes/modernized/static/css/common.css	Sat Jun 09 00:04:57 2012 +0400
+++ b/MoinMoin/themes/modernized/static/css/common.css	Thu Jun 21 02:56:28 2012 +0400
@@ -288,6 +288,13 @@
 .moin-drag { font-size: 0.7em; color: #6C7680; }
 a.moin-conflict:before { content: url(../img/moin-conflict.png); margin: 0 0.2em; }
 
+/* blog page */
+.moin-post-info { font-size: 0.8em; color: #888888; }
+ul.moin-post-tags { list-style: none; display: inline; margin: 0; }
+ul.moin-post-tags li { display: inline; }
+ul.moin-post-tags li:after { content: ","; } 
+ul.moin-post-tags li:last-child:after { content: ""; }
+
 /* popup */
 #popup { background: transparent url("../img/moin-transparent-bg.png") repeat; padding: 5px; width: 40%; position: absolute; top: 10%; left: 30%; display: none; z-index: 10; }
 .popup-header { background-color: #4477FF; color: #FFFFFF; font-size: 1em; padding: 10px; margin: 0; }