diff MoinMoin/items/__init__.py @ 1691:28cb88fcc4dd

Move Blog item implementation to a separate blog.py module.
author Pavel Sviderski <pavel@psviderski.name>
date Wed, 15 Aug 2012 17:26:25 +0200
parents 2601f623bdeb
children d697fd14e772
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Wed Aug 15 17:19:55 2012 +0200
+++ b/MoinMoin/items/__init__.py	Wed Aug 15 17:26:25 2012 +0200
@@ -23,16 +23,15 @@
 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
@@ -55,7 +54,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, 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
     )
@@ -685,84 +684,5 @@
                               )
 
 
-# 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'
-
-        @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,
-                              )
-
-
 from ..util.pysupport import load_package_modules
 load_package_modules(__name__, __path__)