Commits

Alessandro Molina committed 556451c

Make tagcloud a partial

  • Participants
  • Parent commits dba00ee

Comments (0)

Files changed (10)

smallpress/controllers/root.py

 from tw.forms import DataGrid
 from datetime import datetime
 from tgext.ajaxforms.ajaxform import formexpose, spinner_icon
-from tgext.tagging import TaggingController, TagCloud
+from tgext.tagging import TaggingController
 
 article_form = ArticleForm()
 upload_form = UploadForm()
     tagging = TaggingController(model=Article, session=DBSession, allow_edit=None)
     tagging.search = before_render(inject_css)(tagging.search)
 
-    def _before(self, *args, **kw):
-        tmpl_context.smallpress_mount_point = self.mount_point
-
     @expose('genshi:smallpress.templates.index')
     def index(self, *args, **kw):
         articles = Article.get_published().all()
         tags = Tagging.tag_cloud_for_set(Article, articles)
-        return dict(articles=articles, tags=tags, mount_point=self.mount_point,
-                    tagcloud=TagCloud(tagging_url=self.mount_point+'/tagging'))
+        return dict(articles=articles, tags=tags)
 
     @expose('genshi:smallpress.templates.article')
     @validate(dict(article=SQLAEntityConverter(Article)), error_handler=index)
     def view(self, article):
-        tags = Tagging.tag_cloud_for_set(Article)
-        return dict(article=article, tags=tags, mount_point=self.mount_point,
-                    tagcloud=TagCloud(tagging_url=self.mount_point+'/tagging'))
+        return dict(article=article)
 
     @require(predicates.in_group('smallpress'))
     @expose('genshi:smallpress.templates.manage')
 
     @require(predicates.in_group('smallpress'))
     @expose('genshi:smallpress.templates.edit')
-    def edit(self, *args, **kw):
+    def edit(self, uid, *args, **kw):
         attachments_table.register_resources()
 
-        article = DBSession.query(Article).get(kw['uid'])
+        article = DBSession.query(Article).get(uid)
         value = {
             'uid':article.uid,
             'title':article.title,

smallpress/lib/forms.py

 from tw.forms.validators import UnicodeString, FieldStorageUploadConverter
 from tg.i18n import lazy_ugettext as l_
 from tgext.ajaxforms import ajaxloaded
+from tgext.pluggable import plug_url
 
 class ArticleForm(ListForm):
     class fields(WidgetsList):
                            attrs=dict(id='article_content'))
         publish_date = TextField(label_text='Publish Date')
 
-class LazyAjaxUrl(object):
-    def __init__(self, subpath):
-        self.subpath = subpath
-
-    def __str__(self):
-        return request.controller_state.controller.mount_point + self.subpath
-
 @ajaxloaded
 class UploadForm(ListForm):
     class fields(WidgetsList):
         name = TextField(label_text='Name', validator=UnicodeString(not_empty=True))
         file = FileField(label_text='File', validator=FieldStorageUploadConverter(not_empty=True))
 
-    action = LazyAjaxUrl('/attach')
-    ajaxurl = LazyAjaxUrl('/upload_form_show')
+    action = plug_url('smallpress', '/attach', lazy=True)
+    ajaxurl = plug_url('smallpress', '/upload_form_show', lazy=True)
     submit_text = 'Attach'

smallpress/model/models.py

                                            .order_by(Article.publish_date.desc())
         return articles
 
-    def tagging_display(self, mount_point=None):
-        if not mount_point:
-            mount_point=request.controller_state.controller.mount_steps[-2][1].mount_point
-        return call_partial('smallpress.partials:article_preview', article=self, mount_point=mount_point)
+    def tagging_display(self):
+        return call_partial('smallpress.partials:article_preview', article=self)
 
     def is_owner(self, identity):
         if not identity:

smallpress/partials.py

 from tg import expose
 from model import Article, Tagging
+from tgext.pluggable import plug_url
+from tgext.tagging import TagCloud
 
 @expose('genshi:smallpress.templates.articles')
-def articles(articles=None, mount_point=None):
+def articles(articles=None):
     if articles is None:
         articles=Article.get_published()
-    return dict(articles=articles, mount_point=mount_point)
+    return dict(articles=articles)
 
 @expose('genshi:smallpress.templates.article_preview')
-def article_preview(article, mount_point=None):
-    return dict(article=article, mount_point=mount_point)
+def article_preview(article):
+    return dict(article=article)
+
+@expose('genshi:smallpress.templates.tagcloud')
+def tagcloud(tags=None):
+    tagcloud=TagCloud(tagging_url=plug_url('smallpress', '/tagging'))
+    if not tags:
+        tags = Tagging.tag_cloud_for_set(Article)
+    return dict(tagcloud=tagcloud, tags=tags)

smallpress/templates/article.html

         <div id="smallpress_search">
             <h3>Search</h3>
         </div>
-        <div id="smallpress_tags">
-            <h3>Tags</h3>
-            ${tagcloud(tags)}
-        </div>
+        ${h.call_partial('smallpress.partials:tagcloud')}
         <div id="smallpress_history">
             <h3>Archive</h3>
         </div>
     </div>
     <div id="smallpress_articles_box">
-        <div>${h.call_partial('smallpress.partials:article_preview', mount_point=mount_point, article=article)}</div>
+        <div>${h.call_partial('smallpress.partials:article_preview', article=article)}</div>
     </div>
     <div style="clear:right;"></div>
 </body>

smallpress/templates/article_preview.html

 <div xmlns:py="http://genshi.edgewall.org/" class="smallpress_article">
-    <h2><a href="${tg.url(mount_point+'/view/%s'%article.uid)}">${article.title}</a></h2>
+    <h2>
+        <a href="${h.plug_url('smallpress', '/view/%s'%article.uid)}">${article.title}</a>
+    </h2>
     <h4>
         <span py:if="article.is_owner(request.identity)">
-            <a href="${tg.url(mount_point+'/edit/%s'%article.uid)}">edit</a> |
+            <a href="${h.plug_url('smallpress', '/edit/%s'%article.uid)}">edit</a> |
         </span>
         ${article.author} | ${h.smallpress.format_date(article)} | ${h.smallpress.comma_separated_tags(article)}
     </h4>

smallpress/templates/articles.html

 <div xmlns:py="http://genshi.edgewall.org/" id="smallpress_articles">
     <py:for each="article in articles">
-        ${article.tagging_display(mount_point=mount_point)}
+        ${article.tagging_display()}
     </py:for>
 </div>

smallpress/templates/edit.html

 
 <body>
     <div id="smallpress_new_article" class="smallpress">
-        <a href="${tg.url(tmpl_context.smallpress_mount_point+'/manage')}">back to management</a>
+        <a href="${h.plug_url('smallpress', '/manage')}">back to management</a>
         <h1>Edit Article</h1>
         ${form(value=value, action=action)}
         <div id="smallpress_attachments">

smallpress/templates/index.html

         <div id="smallpress_search">
             <h3>Search</h3>
         </div>
-        <div id="smallpress_tags">
-            <h3>Tags</h3>
-            ${tagcloud(tags)}
-        </div>
+        ${h.call_partial('smallpress.partials:tagcloud', tags=tags)}
         <div id="smallpress_history">
             <h3>Archive</h3>
         </div>
     </div>
     <div id="smallpress_articles_box">
-        <div>${h.call_partial('smallpress.partials:articles', mount_point=mount_point, articles=articles)}</div>
+        <div>${h.call_partial('smallpress.partials:articles', articles=articles)}</div>
     </div>
     <div style="clear:right;"></div>
 </body>

smallpress/templates/tagcloud.html

+<div id="smallpress_tags">
+    <h3>Tags</h3>
+    ${tagcloud(tags)}
+</div>