예제 #1
0
 def body(self):
     content = memcache.get('widget_category_list')
     if not content:
         category_list = Category.all().order('sort')
     
         content = []
         write = content.append
         write('<ul>')
         for category in category_list:
             write('<li><a href="%s">%s</a>(%s)</li>' % 
                     (category.getUrl(), category.name, category.count))
         write('</ul>')
         content = '\n'.join(content)
         memcache.set('widget_category_list', content)
     
     return content
예제 #2
0
 def GET(self, post_id=None):
     post = {}
     if post_id:
         # post = Post.get(db.Key.from_path(Post.kind(), int(post_id)))
         post = Post.get_by_id(int(post_id))
         title = u'修改日志'
     else:
         title = u'写新日志'
         post['date'] = datetime.now()
     
     categories = Category.all().order('sort')
     
     return render('admin/post.html',
                   post=post,
                   title=title,
                   categories=categories)
예제 #3
0
 def GET(self, category_name):
     if category_name.isdigit():
         category = Category.get_by_id(int(category_name))
     else:
         category = Category.all().filter('alias =', category_name).get()
     
     inp = web.input()
     # bookmark = inp.get('bookmark')
     # 
     # query = PagerQuery(Post).filter('hidden =', False)
     # query.filter('category =', category)
     # query.order('-date')
     # prev, posts, next = query.fetch(blog.post_pagesize, bookmark)
     page = inp.get('page')
     if not page:
         page = 1
     pager = Pager(Post, blog.post_pagesize).order('-date')
     pager.filter('hidden =', False)
     pager.filter('category =', category)
     posts = pager.fetch(page)
     
     return render('theme/index.html',posts=posts,pager=pager)#prev=prev,next=next)
예제 #4
0
 def POST(self, category_id=None):
     if category_id:
         category = Category.get_by_id(int(category_id))
     else:
         category = Category()
         max_sort_category = Category.all().order('-sort').get()
         if max_sort_category:
             # max_sort_category = max_sort_category.pop()
             max_sort = max_sort_category.sort
             if not max_sort:
                 max_sort = 0
         else:
             max_sort = 0
         category.sort = max_sort + 1
     
     inp = web.input()
     category.name = inp.name
     category.alias = inp.get('alias')
     category.save()
     
     clear_cache()
     return web.seeother('/admin/categories')
예제 #5
0
 def GET(self):
     categories = Category.all().order('sort')
     
     return render('admin/categories.html',categories=categories)