changeset 1444:34069422fde1

Add blog_layout template, blog sidebar with 'Categories' widget, simple +post view.
author Pavel Sviderski <pavel@psviderski.name>
date Wed, 04 Jul 2012 21:51:39 +0400
parents 7e52a847d5ff
children 73901c32f75e
files MoinMoin/apps/frontend/views.py MoinMoin/templates/blog.html MoinMoin/templates/blog_layout.html MoinMoin/templates/post.html MoinMoin/themes/modernized/static/css/common.css
diffstat 5 files changed, 116 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Thu Jun 21 03:33:59 2012 +0400
+++ b/MoinMoin/apps/frontend/views.py	Wed Jul 04 21:51:39 2012 +0400
@@ -483,10 +483,33 @@
     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,
+                           title_name=item.name,
+                           blog_item=item,
                            blog_post_items=blog_post_items,
                           )
 
+@frontend.route('/+post/+<rev>/<itemname:item_name>', methods=['GET'])
+@frontend.route('/+post/<itemname:item_name>', defaults=dict(rev=CURRENT), methods=['GET'])
+def show_post(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('post.html',
+                           title_name=item.name,
+                           blog_item=blog_item,
+                           blog_post_item=item,
+                          )
+
 
 class CommentForm(TextChaizedForm):
     comment = String.using(label=L_('Comment'), optional=True).with_properties(placeholder=L_("Comment about your change"))
--- a/MoinMoin/templates/blog.html	Thu Jun 21 03:33:59 2012 +0400
+++ b/MoinMoin/templates/blog.html	Wed Jul 04 21:51:39 2012 +0400
@@ -1,35 +1,11 @@
-{% extends theme("layout.html") %}
-{% import "utils.html" as utils %}
+{% extends theme("blog_layout.html") %}
 
-{% 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 %}
+{% block blog_content %}
+    {% if blog_post_items %}
+        {% for post_item in blog_post_items %}
+            {{ show_post(post_item) }}
+        {% endfor %}
+    {% else %}
+        {{ _("There are no posts in this blog.") }}
+    {% endif %}
 {% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/templates/blog_layout.html	Wed Jul 04 21:51:39 2012 +0400
@@ -0,0 +1,72 @@
+{% extends theme("layout.html") %}
+{% import "utils.html" as utils %}
+
+{% macro show_post(post_item) %}
+    {% 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>
+    <div class="moin-post-info">
+        {{ _("Posted on") }} {{ post_item.meta['ptime']|datetimeformat }}
+        {{ _("by") }} {{ utils.editor_info(post_item.meta) }}
+    </div>
+    <div class="moin-post-content">
+        {{ post_item._render_data()|safe }} {# rendered post content #}
+    </div>
+    <div class="moin-post-bottominfo">
+        {% set tags = post_item.meta['tags']|sort %}
+        {% if tags %} {# display post's tags as a list if they existed #}
+            <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 %}
+        <div class="moin-post-comments">
+            {% set discussion_item_name = '{0}/{1}'.format(post_item.name, 'Discussion') %}
+            <a href="{{ url_for('frontend.show_item', item_name=discussion_item_name) }}">Discussion page</a>
+        </div>
+    </div>
+{% endmacro %}
+
+{% macro widget_categories(categories) %}
+    <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>
+            {% endfor %}
+        </ul>
+    </div>
+{% endmacro %}
+
+{% if blog_item %}
+    {% set blog_header = blog_item._render_data()|safe %}
+    {% set categories = blog_item.meta['supertags'] %}
+{% endif %}
+
+{% block content %}
+    {% block content_data %}
+        <div id="moin-content-data">
+            <div id="moin-blog-header">
+                {% if blog_header %}
+                    {{ blog_header }}
+                {% endif %}
+            </div>
+            <div id="moin-blog-content">
+            {% block blog_content %}<br />{% endblock %}
+            </div>
+            {% if categories %}
+                <div id="moin-blog-sidebar">
+                    {{ widget_categories(categories) }}
+                </div>
+            {% endif %} 
+        </div>
+    {% endblock %}
+{% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/templates/post.html	Wed Jul 04 21:51:39 2012 +0400
@@ -0,0 +1,7 @@
+{% extends theme("blog_layout.html") %}
+
+{% block blog_content %}
+    {% if blog_post_item %}
+        {{ show_post(blog_post_item) }}
+    {% endif %}
+{% endblock %}
--- a/MoinMoin/themes/modernized/static/css/common.css	Thu Jun 21 03:33:59 2012 +0400
+++ b/MoinMoin/themes/modernized/static/css/common.css	Wed Jul 04 21:51:39 2012 +0400
@@ -289,7 +289,11 @@
 a.moin-conflict:before { content: url(../img/moin-conflict.png); margin: 0 0.2em; }
 
 /* blog page */
+#moin-blog-header { margin: 1em 0 -1em 0; }
+#moin-blog-content { padding: 0 2em 0 0; display: table-cell }
+#moin-blog-sidebar { width: 15em; display: table-cell; }
 .moin-post-info { font-size: 0.8em; color: #888888; }
+.moin-post-bottominfo { font-size: 0.8em; color: #888888; padding: 0em 1em; border: 1px solid #DEDEDE;}
 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: ","; }