示例#1
0
文件: page.py 项目: bdrydyk/wurdig
 def view(self, slug=None):
     if slug is None:
         abort(404)
     page_q = meta.Session.query(model.Page)
     c.page = page_q.filter_by(slug=slug).first()
     if c.page is None:
         abort(404)
     if c.page.slug == 'search':
         return render('/derived/page/search.html')
     return render('/derived/page/view.html')
示例#2
0
文件: post.py 项目: leveille/blog.v1
 def edit(self, id=None):
         
     try:
         id = int(id)
     except:
         abort(400)
         
     post_q = meta.Session.query(model.Post)
     c.post = post_q.filter_by(id=id).first()
     if c.post is None:
         abort(404)
     
     tag_q = meta.Session.query(model.Tag)
     c.available_tags = [(tag.id, tag.name) for tag in tag_q]
     c.selected_tags = [str(tag.id) for tag in c.post.tags]
     
     values = {
         'id':c.post.id,
         'title':c.post.title,
         'slug':c.post.slug,
         'content':c.post.content,
         'draft':c.post.draft,
         'comments_allowed':c.post.comments_allowed,
         'tags':c.selected_tags
     }
     return htmlfill.render(render('/derived/post/edit.html'), values)
示例#3
0
文件: tag.py 项目: amesmich/wurdig
 def archive(self, slug=None):   
     if slug is None:
         abort(404)
     tag_q = meta.Session.query(model.Tag)
     c.tag = tag_q.filter(model.Tag.slug==slug).first()
     
     if(c.tag is None):
         c.tagname = slug
     else:
         c.tagname = c.tag.name
         
     query = meta.Session.query(model.Post).filter(
         and_(
              model.Post.tags.any(slug=slug), 
              model.Post.posted_on != None
         )
     ).all()
         
     c.paginator = paginate.Page(
         query,
         page=int(request.params.get('page', 1)),
         items_per_page = 2,
         controller='tag',
         action='archive',
         slug=slug
     )
             
     return render('/derived/tag/archive.html')
示例#4
0
文件: post.py 项目: bdrydyk/wurdig
 def archive(self, year=None, month=None):   
     if year is None:
         abort(404)
     
     (c.date, year_i, month_start, month_end, day_end) = (year, int(year), 1, 12, 31)
     
     if month is not None:
         c.date = calendar.month_name[month_start] + ', ' + year
         (month_start, month_end) = (int(month), int(month))
         day_end = calendar.monthrange(year_i, month_start)[1]
     
     posts_q = meta.Session.query(model.Post).filter(
         and_(
             model.Post.posted_on >= d.datetime(year_i, month_start, 1), 
             model.Post.posted_on <= d.datetime(year_i, month_end, day_end), 
             model.Post.draft == False
         )
     )
     
     c.paginator = paginate.Page(
         posts_q,
         page=int(request.params.get('page', 1)),
         items_per_page = 10,
         controller='post',
         action='archive',
         year=year,
         month=month,
     )
             
     return render('/derived/post/archive.html')
示例#5
0
文件: post.py 项目: bdrydyk/wurdig
 def delete_confirm(self, id=None):
     if id is None:
         abort(404)
     post_q = meta.Session.query(model.Post)
     c.post = post_q.filter_by(id=id).first()
     if c.post is None:
         abort(404)
     return render('/derived/post/delete_confirm.html')
示例#6
0
文件: page.py 项目: bdrydyk/wurdig
 def delete_confirm(self, id=None):
     if id is None:
         abort(404)
     page_q = meta.Session.query(model.Page)
     c.page = page_q.filter_by(id=id).first()
     if c.page is None:
         abort(404)
     return render('/derived/page/delete_confirm.html')
示例#7
0
文件: post.py 项目: amesmich/wurdig
    def home(self):
        posts_q = meta.Session.query(model.Post).filter(model.Post.draft == False)

        c.paginator = paginate.Page(
            posts_q, page=int(request.params.get("page", 1)), items_per_page=2, controller="post", action="home"
        )

        return render("/derived/post/home.html")
示例#8
0
文件: comment.py 项目: bdrydyk/wurdig
 def new(self, action, post_id=None):
     if post_id is None:
         abort(404)
     post_q = meta.Session.query(model.Post)
     c.post = post_id and post_q.filter_by(id=int(post_id)).first() or None
     if c.post is None:
         abort(404)
     return render('/derived/comment/new.html')
示例#9
0
文件: tag.py 项目: bdrydyk/wurdig
 def delete_confirm(self, id=None):
     if id is None:
         abort(404)
     tag_q = meta.Session.query(model.Tag)
     c.tag = tag_q.filter_by(id=id).first()
     if c.tag is None:
         abort(404)
     return render('/derived/tag/delete_confirm.html')
示例#10
0
 def dashboard(self):
     if not request.environ.get('REMOTE_USER'):
         # This triggers the AuthKit middleware into displaying the sign-in form
         abort(401)
     else:
         self._recent_comments()
         self._drafts()
         self._settings()
         return render('/derived/account/dashboard.html')
示例#11
0
文件: movie.py 项目: bdrydyk/wurdig
 def movie(self, id=None):
     # Return a rendered template
     #return render('/movie.mako')
     # or, return a response
     movie = id is not None and db.Movie.get(id)
     if id is not None and not movie:
         raise Exception('Movie ID not found')
     
     return dict(movie_form=movie_form, movie=movie)
     return render('/movie.mako')
示例#12
0
文件: tag.py 项目: amesmich/wurdig
 def list(self):
     tags_q = meta.Session.query(model.Tag)
     c.paginator = paginate.Page(
         tags_q,
         page=int(request.params.get('page', 1)),
         items_per_page = 10,
         controller='tag',
         action='list',
     )
     return render('/derived/tag/list.html')
示例#13
0
文件: post.py 项目: bdrydyk/wurdig
 def list(self):
     posts_q = meta.Session.query(model.Post).order_by([model.Post.draft.desc(),model.Post.posted_on.desc()])
     c.paginator = paginate.Page(
         posts_q,
         page=int(request.params.get('page', 1)),
         items_per_page = 50,
         controller='post',
         action='list',
     )
     return render('/derived/post/list.html')
示例#14
0
文件: comment.py 项目: bdrydyk/wurdig
 def delete_confirm(self, id=None):
     if id is None:
         abort(404)
     comment_q = meta.Session.query(model.Comment)
     c.comment = comment_q.filter_by(id=id).first()
     if c.comment is None:
         abort(404)
     post_q = meta.Session.query(model.Post)
     c.post = c.comment.post_id and post_q.filter_by(id=int(c.comment.post_id)).first() or None
     if c.post is None:
         abort(404)
     return render('/derived/comment/delete_confirm.html')
示例#15
0
文件: post.py 项目: bdrydyk/wurdig
 def home(self):
     posts_q = meta.Session.query(model.Post).filter(
         model.Post.draft == False
     )
     c.paginator = paginate.Page(
         posts_q,
         page=int(request.params.get('page', 1)),
         items_per_page = 10,
         controller='post',
         action='home'
     )
     return render('/derived/post/home.html')
示例#16
0
 def list(self):
     comments_q = meta.Session.query(model.Comment).order_by(
                                                model.Comment.approved
                                                ).order_by(model.Comment.created_on)
     comments_q = comments_q.all()
     c.paginator = paginate.Page(
         comments_q,
         page=int(request.params.get('page', 1)),
         items_per_page=20,
         controller='comment',
         action='list'
     )
     return render('/derived/comment/list.html')
示例#17
0
文件: tag.py 项目: amesmich/wurdig
 def edit(self, id=None):
     if id is None:
         abort(404)
     tag_q = meta.Session.query(model.Tag)
     tag = tag_q.filter_by(id=id).first()
     if tag is None:
         abort(404)
     values = {
         'id':tag.id,
         'name':tag.name,
         'slug':tag.slug
     }
     return htmlfill.render(render('/derived/tag/edit.html'), values)
示例#18
0
文件: error.py 项目: leveille/blog.v1
 def document(self):
     """Render the error document"""
     resp = request.environ.get('pylons.original_response')
     code = cgi.escape(request.GET.get('code', ''))
     content = cgi.escape(request.GET.get('message', ''))
     if resp:
         content = literal(resp.status)
         code = code or cgi.escape(str(resp.status_int))
     if not code:
         raise Exception(_('No status code was found'))
     c.code = code
     c.message = content
     return render('/derived/error/document.html')
示例#19
0
文件: post.py 项目: bdrydyk/wurdig
 def view(self, year, month, slug):
     (year_i, month_i) = (int(year), int(month))
     c.post = meta.Session.query(model.Post).filter(
         and_(model.Post.posted_on >= d.datetime(year_i, month_i, 1), 
              model.Post.posted_on <= d.datetime(year_i, month_i, calendar.monthrange(year_i, month_i)[1]),
              model.Post.draft == False,
              model.Post.slug == slug)
     ).first()
                              
     if c.post is None:
         abort(404)
         
     return render('/derived/post/view.html')
示例#20
0
文件: page.py 项目: bdrydyk/wurdig
 def edit(self, id=None):
     if id is None:
         abort(404)
     page_q = meta.Session.query(model.Page)
     page = page_q.filter_by(id=id).first()
     if page is None:
         abort(404)
     values = {
         'id':page.id,
         'title':page.title,
         'slug':page.slug,
         'content':page.content
     }
     return htmlfill.render(render('/derived/page/edit.html'), values)
示例#21
0
 def edit(self, id=None):
     if id is None:
         abort(404)
     comment_q = meta.Session.query(model.Comment)
     comment = comment_q.filter_by(id=id).first()
     if comment is None:
         abort(404)
     values = {
         'name': comment.name,
         'email': comment.email,
         'url': comment.url,
         'content': comment.content,
         'approved' : comment.approved
     }
     return htmlfill.render(render('/derived/comment/edit.html'), values)
示例#22
0
文件: page.py 项目: leveille/blog.v1
 def list(self):
     pages_q = meta.Session.query(model.Page)
     
     try:
         page = int(request.params.get('page', 1))
     except:
         abort(400)
     
     c.paginator = paginate.Page(
         pages_q,
         page=page,
         items_per_page = 10,
         controller='page',
         action='list',
     )
     return render('/derived/page/list.html')
示例#23
0
 def list(self):
     
     settings_q = meta.Session.query(model.Setting).order_by([model.Setting.id])
     
     try:
         settings_page = int(request.params.get('settings_page', 1))
     except:
         abort(400)
         
     c.paginator = paginate.Page(
         settings_q,
         page=settings_page,
         items_per_page = 25,
         controller='setting',
         action='list',
     )
     return render('/derived/setting/list.html')
示例#24
0
文件: post.py 项目: leveille/blog.v1
 def blog(self):
     def load_page():
         posts_q = meta.Session.query(model.Post).filter(
             and_( 
                 model.Post.draft == False
             )
         ).group_by([model.Post.created_on, model.Post.posted_on]).all()
         # ).group_by([model.Post.created_on]).fetchall()
         # posts_q = posts_q.distinct().group_by([model.Post.posted_on])
         return posts_q
         
     try:
         c.foo = load_page()
     except:
         abort(400)
                 
     return render('/derived/post/blog.html')
示例#25
0
文件: post.py 项目: leveille/blog.v1
 def archive(self, year=None, month=None):  
      
     try:
         year_i = int(year)
     except:
         abort(400)
     
     (c.date, month_start, month_end, day_end) = (year, 1, 12, 31)
     
     if month is not None:
         try:
             month_i = int(month)
         except:
             abort(400)
         
         import calendar
         (month_start, month_end) = (month_i, month_i)
         day_end = calendar.monthrange(year_i, month_start)[1]
         c.date = calendar.month_name[month_start] + ', ' + year
     
     @app_globals.cache.region('short_term', 'post.archive.load_page')
     def load_page(page):
         posts_q = meta.Session.query(model.Post).filter(
             and_(
                 model.Post.posted_on >= d.datetime(year_i, month_start, 1), 
                 model.Post.posted_on <= d.datetime(year_i, month_end, day_end), 
                 model.Post.draft == False
             )
         )
         return paginate.Page(
             posts_q,
             page=page,
             items_per_page = 10,
             controller='post',
             action='archive',
             year=year,
             month=month,
         )
         
     try:
         c.paginator = load_page(int(request.params.get('page', 1)))
     except:
         abort(400)
                 
     return render('/derived/post/archive.html')
示例#26
0
    def edit(self, id=None):

        try:
            id = int(id)
        except:
            abort(400)
            
        setting_q = meta.Session.query(model.Setting)
        c.setting = setting_q.filter_by(id=id).first()
        if c.setting is None:
            abort(404)
        values = {
            'id': c.setting.id,
            'key': c.setting.key,
            'value': c.setting.value
        }
        if c.setting.type == 'b':
            values['value'] = asbool(c.setting.value)
        return htmlfill.render(render('/derived/setting/edit.html'), values)
示例#27
0
文件: post.py 项目: leveille/blog.v1
 def home(self): 
     @app_globals.cache.region('short_term', 'post.home.load_page')
     def load_page(page):
         return paginate.Page(
             meta.Session.query(model.Post).filter(
                 model.Post.draft == False
             ),
             page=page,
             items_per_page = 10,
             controller='post',
             action='home'
         )
         
     try:
         c.page = int(request.params.get('posts_page', 1))
         c.paginator = load_page(c.page)
     except:
         abort(400)
         
     return render('/derived/post/home.html')
示例#28
0
文件: page.py 项目: leveille/blog.v1
    def view(self, slug=None):
        if slug is None:
            abort(404)
            
        # @app_globals.cache.region('long_term')
        def load_page(slug):
            page_q = meta.Session.query(model.Page)
            return page_q.filter_by(slug=slug).first()
        
        c.page = load_page(slug)
        if c.page is None:
            abort(404)

        template = '/derived/page/%s.html'
        if os.path.isfile(config['pylons.paths']['templates'][0] + template % slug):
            template = template % slug
        else:
            template = template % 'view'
            
        return render(template)
示例#29
0
    def disapprove_confirm(self, id=None):

        try:
            id = int(id)
        except:
            abort(400)
            
        comment_q = meta.Session.query(model.Comment)
        c.comment = comment_q.filter_by(id=id).first()
        if c.comment is None:
            abort(404)
        post_q = meta.Session.query(model.Post)
        
        try:
            post_id = int(c.comment.post_id)
        except:
            abort(400)
        
        c.post = c.comment.post_id and post_q.filter_by(id=post_id).first() or None
        if c.post is None:
            abort(404)
        return render('/derived/comment/disapprove_confirm.html')
示例#30
0
文件: post.py 项目: amesmich/wurdig
    def edit(self, id=None):
        if id is None:
            abort(404)
        post_q = meta.Session.query(model.Post)
        c.post = post_q.filter_by(id=id).first()
        if c.post is None:
            abort(404)
        import pprint

        tag_q = meta.Session.query(model.Tag)
        c.available_tags = [(tag.id, tag.name) for tag in tag_q]
        c.selected_tags = [str(tag.id) for tag in c.post.tags]

        values = {
            "id": c.post.id,
            "title": c.post.title,
            "slug": c.post.slug,
            "content": c.post.content,
            "draft": c.post.draft,
            "comments_allowed": c.post.comments_allowed,
            "tags": c.selected_tags,
        }
        return htmlfill.render(render("/derived/post/edit.html"), values)