Commits

Jaiditya committed 067a8a0 Merge

merged

Comments (0)

Files changed (5)

MoinMoin/forms.py

             dt = utctimestamp(dt)
         return dt
 
-DateTime = (DateTimeUNIX.with_properties(widget=WIDGET_DATETIME, placeholder=_("YYYY-MM-DD HH:MM:SS (example: 2999-12-31 23:59:59)"))
+DateTime = (DateTimeUNIX.with_properties(widget=WIDGET_DATETIME, placeholder=_("YYYY-MM-DD HH:MM:SS (example: 2013-12-31 23:59:59)"))
             .validated_by(Converted(incorrect=L_("Please use the following format: YYYY-MM-DD HH:MM:SS"))))
 
 File = FileStorage.with_properties(widget=WIDGET_FILE)

MoinMoin/items/__init__.py

 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, DateRange
+from whoosh.query import Term, And, Prefix
 
-from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags, DateTime, Submit
+from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags, Submit
 
 from MoinMoin.security.textcha import TextCha, TextChaizedForm
 from MoinMoin.signalling import item_modified
 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, PTIME, SYSITEM_VERSION, ITEMTYPE,
+    NAME, NAME_OLD, NAME_EXACT, WIKINAME, MTIME, SYSITEM_VERSION, ITEMTYPE,
     CONTENTTYPE, SIZE, TAGS, ACTION, ADDRESS, HOSTNAME, USERID, COMMENT,
     HASH_ALGORITHM, ITEMID, REVID, DATAID, CURRENT, PARENTID
     )
                               )
 
 
-# TODO: move into a separate items/blog.py module
-class BlogMetaForm(BaseMetaForm):
-    supertags = (Tags.using(label=L_('Supertags (Categories)'))
-                 .with_properties(placeholder=L_("Ordered comma separated list of tags")))
-
-class BlogEntryMetaForm(BaseMetaForm):
-    summary = (OptionalText.using(label=L_("Title"))
-               .with_properties(placeholder=L_("One-line title of the blog entry")))
-    ptime = DateTime.using(label=L_('Publication time (UTC)'), optional=True)
-
-@register
-class Blog(Default):
-    itemtype = u'blog'
-
-    class _ModifyForm(Default._ModifyForm):
-        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):
-    itemtype = u'blogentry'
-
-    class _ModifyForm(Default._ModifyForm):
-        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__)

MoinMoin/items/blog.py

+# Copyright: 2012 MoinMoin:PavelSviderski
+# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
+
+"""
+MoinMoin - Blog itemtype
+"""
+
+
+import time
+from datetime import datetime
+
+from flask import request, abort
+from flask import g as flaskg
+from flask import current_app as app
+
+from whoosh.query import Term, And, Prefix, DateRange
+
+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, PTIME, TAGS
+from MoinMoin.items import Item, Default, register, BaseMetaForm
+
+
+ITEMTYPE_BLOG = u'blog'
+ITEMTYPE_BLOG_ENTRY = u'blogentry'
+
+
+class BlogMetaForm(BaseMetaForm):
+    supertags = (Tags.using(label=L_('Supertags (Categories)'))
+                 .with_properties(placeholder=L_("Ordered comma separated list of tags")))
+
+class BlogEntryMetaForm(BaseMetaForm):
+    summary = (OptionalText.using(label=L_("Title"))
+               .with_properties(placeholder=L_("One-line title of the blog entry")))
+    ptime = DateTime.using(label=L_('Publication time (UTC)'), optional=True)
+
+@register
+class Blog(Default):
+    itemtype = ITEMTYPE_BLOG
+
+    class _ModifyForm(Default._ModifyForm):
+        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):
+    itemtype = ITEMTYPE_BLOG_ENTRY
+
+    class _ModifyForm(Default._ModifyForm):
+        meta_form = BlogEntryMetaForm
+        meta_template = 'modify_blog_entry_meta.html'
+
+        @classmethod
+        def from_item(cls, item):
+            form = super(BlogEntry._ModifyForm, cls).from_item(item)
+            # preload PTIME with the current datetime
+            if not form['meta_form']['ptime']:
+                form['meta_form']['ptime'].set(datetime.utcnow())
+            return form
+
+    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,
+                              )

MoinMoin/templates/blog_layout.html

 {% extends theme("layout.html") %}
 {% import "forms.html" as forms %}
 {% import "utils.html" as utils %}
+{% import "itemviews.html" as itemviews with context %}
 
 {% macro show_blog_entry(entry_item) %}
     {% if entry_item.meta['summary'] %}
     {% endmacro %}
 {% endif %}
 
+{% block header_itemviews %}
+    {{ itemviews }}
+{% endblock %}
+
 {% block content %}
     {% block content_data %}
         <div id="moin-content-data">
         </div>
     {% endblock %}
 {% endblock %}
+
+{% block footer_itemviews %}
+    {{ itemviews }}
+{% endblock %}

MoinMoin/templates/common.js

             "text/plain" : function (x) {return x + " "; }
         },
         ctype = guessContentType(),
-        input_element = $("#f_data_text"),
+        input_element = $("#f_content_form_data_text"),
         ctype_format = transclude_formats[ctype];
     if (!ctype_format) {
         ctype_format = transclude_formats["text/plain"];
             "text/plain" : function (x) {return x + " "; }
         },
         ctype = guessContentType(),
-        input_element = $("#f_data_text"),
+        input_element = $("#f_content_form_data_text"),
         ctype_format = link_formats[ctype];
     if (!ctype_format) {
         ctype_format = link_formats["text/plain"];