1. Simone Marzola
  2. tgapp-smallpress

Commits

Simone Marzola  committed fc32acb

static pages support

  • Participants
  • Parent commits f91abfc
  • Branches default

Comments (0)

Files changed (5)

File smallpress/controllers/root.py

View file
                                   (l_('Blog'), lambda row:row.blog and row.blog.name),
                                   (l_('Title'), lambda row:HTML.a(row.title,
                                                                   href=plug_url('smallpress', '/view/%s'%row.uid,
-                                                                                lazy=True))),
+                                                                                lazy=True),
+                                                                  class_='static_page' if row.static else '')),
                                   (l_('Tags'), comma_separated_tags),
                                   (l_('Author'), 'author'),
                                   (l_('Publishing'), lambda row:format_published(row) + ', ' + format_date(row))])
     def manage(self, blog='', *args, **kw):
         articles = Article.get_all(blog)
         return dict(table=articles_table, articles=articles,
-                    create_action=self.mount_point+'/new/'+blog)
+                    title='Article', create_action=self.mount_point+'/new/'+blog)
+
+    @require(predicates.in_group('smallpress'))
+    @expose('genshi:smallpress.templates.manage')
+    @paginate('articles')
+    def manage_static(self, blog='', *args, **kw):
+        articles = Article.get_statics()
+        return dict(table=articles_table, articles=articles,
+                    title='Page', create_action=self.mount_point+'/new?static=1')
 
     @require(predicates.in_group('smallpress'))
     @expose('genshi:smallpress.templates.edit')
         if 'uid' not in kw:
             if blog:
                 blog = DBSession.query(Blog).filter_by(name=blog).first()
-            article = Article(author=request.identity['user'], blog=blog and blog)
+
+            article = Article(author=request.identity['user'], blog=blog and blog, static=bool(kw.get('static')))
 
             hooks = config['hooks'].get('smallpress.before_create_article', [])
             for func in hooks:
             'description':article.description,
             'tags':comma_separated_tags(article),
             'publish_date':format_date(article),
-            'content':article.content
+            'content':article.content,
+            'static':bool(article.static)
         }
 
         hooks = config['hooks'].get('smallpress.before_edit_article', [])
         article.content = kw['content']
         article.publish_date = kw['publish_date']
         article.update_date = datetime.now()
+        article.static = kw['static']
         app_model.Tagging.set_tags(article, kw['tags'])
 
         flash(_('Articles successfully saved'))

File smallpress/lib/forms.py

View file
     from tw2.core import CSSLink, Required
     from tw2.forms import DataGrid
     from tw2.forms import ListForm, TextField, TextArea, HiddenField, FileField, SubmitButton
-    from formencode.validators import UnicodeString, FieldStorageUploadConverter
+    from formencode.validators import UnicodeString, FieldStorageUploadConverter, StringBool
 
     def inject_datagrid_resources(dg):
         resources = [r.req() for r in dg.resources]
 
     class ArticleForm(ListForm):
         uid = HiddenField()
+        static = HiddenField(value=False, validator=StringBool(not_empty=True))
         title = TextField(label='Title', validator=UnicodeString(not_empty=True, outputEncoding=None))
         description = TextField(label='Description', validator=UnicodeString(outputEncoding=None),
                                 placeholder=l_('If empty will be extracted from the content'))
     from tw.forms import ListForm, TextField, TextArea, HiddenField, FileField
     from tw.forms import DataGrid
     from tw.core import WidgetsList
-    from tw.forms.validators import UnicodeString, FieldStorageUploadConverter
+    from tw.forms.validators import UnicodeString, FieldStorageUploadConverter, StringBool
 
     def inject_datagrid_resources(dg):
         dg.register_resources()
     class ArticleForm(ListForm):
         class fields(WidgetsList):
             uid = HiddenField()
+            static = HiddenField(value=False, validator=StringBool(not_empty=True))
             title = TextField(label_text='Title', validator=UnicodeString(not_empty=True))
             description = TextField(label_text='Description', validator=UnicodeString(),
                                     attrs=dict(placeholder=l_('If empty will be extracted from the content')))

File smallpress/model/models.py

View file
 
 import tg
 from sqlalchemy import Table, ForeignKey, Column
-from sqlalchemy.types import Unicode, Integer, DateTime
+from sqlalchemy.types import Unicode, Integer, DateTime, Boolean
 from sqlalchemy.orm import backref, relation
 from sqlalchemy.orm.interfaces import MapperExtension
 
     description = Column(Unicode(150), nullable=False, default=u'Empty article, edit or delete this')
     content = Column(Unicode(32000), nullable=False, default=u'')
 
+    static = Column(Boolean, nullable=False, default=False)
+
     def refresh_whoosh(self, action=0):
         index_path = config.get('smallpress_whoosh_index', '/tmp/smallpress_whoosh')
         ix = whoosh.index.open_dir(index_path)
     def get_published(blog=None):
         now = datetime.now()
         articles = DBSession.query(Article).filter_by(published=True)\
+                                           .filter_by(static=False)\
                                            .filter(Article.publish_date<=now)
 
         if blog:
 
     @staticmethod
     def get_all(blog=None):
-        articles = DBSession.query(Article)
+        articles = DBSession.query(Article).filter_by(static=False)
         if blog:
             try:
                 blog = blog.name
         articles = articles.order_by(Article.publish_date.desc())
         return articles
 
+    @staticmethod
+    def get_statics():
+        articles = DBSession.query(Article).filter_by(static=True).order_by(Article.publish_date.desc())
+        return articles
+
     @property
     def blog_name(self):
         blog = self.blog

File smallpress/public/css/style.css

View file
     color: black;
 }
 
+#smallpress_manage .static_page{
+    font-weight: bold;
+    text-decoration: underline;
+    color: red;
+}
+
 #smallpress_search #text_container {
     float: left;
 }

File smallpress/templates/manage.html

View file
 <div id="smallpress_manage" class="smallpress">
     <div id="smallpress_create_box">
         <div class="smallpress_text_button">
-            <a href="${tg.url(create_action)}">Write New Article</a>
+            <a href="${tg.url(create_action)}">Write New ${title}</a>
         </div>
-        <h1>Articles</h1>
+        <h1>${title}s</h1>
     </div>
     ${table.display(articles)}
     <div>