Example #1
0
 def GET(self, post_url=None):
     try:
         import hashlib
         post_id = post_url
         post = Post.get_by_id(int(post_id))
         if not post:
             raise web.notfound()
     
         fullpath = web.ctx.home + web.ctx.fullpath
         check = "%s%s" % (fullpath, post.key())
         checksum = hashlib.sha1(check).hexdigest()
     
         comments_query = Comment.all().filter('post =', post)
         if blog.comment_sort == 'asc':
             comments_query.order('created')
         else:
             comments_query.order('-created')
     
         comments = comments_query.fetch(blog.comment_pagesize)
     
         return render('theme/show.html',
                       post=post,
                       checksum=checksum,
                       comments=comments)
     except:
         raise web.notfound()
Example #2
0
 def GET(self, post_id):
     if post_id:
         post = Post.get_by_id(int(post_id))
         post.delete()
         
         clear_cache()
     
     raise web.seeother('/admin/posts')
Example #3
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)
Example #4
0
    def post(self, request, post_id):
        data = request.POST
        post = Post.get_by_id(post_id)
        if data and request.user.is_authenticated:
            comment = Comment.create(content=data.get('content'),
                                     author=request.user,
                                     post=post)
            email_data = {
                'post': post.title,
                'commentator': comment.author.first_name
            }

            subject = 'VakomsBlog New Comment'
            message = 'comment'
            template = 'comment.html'
            recipient = post.author.email
            send_email(subject, message, [
                recipient,
            ], template, email_data)
            return HttpResponseRedirect(
                reverse("post:index", kwargs={'post_id': post_id}))
Example #5
0
 def POST(self, post_id=None):
     """保存日志信息"""
     import pytz
     
     if post_id:
         post = Post.get_by_id(int(post_id))
     else:
         post = Post()
     
     inp = web.input()
     
     post.title = inp.title
     post.alias = inp.alias
     post.content = inp.content
     post.excerpt = inp.excerpt
     if inp.get('date'):
         tz = pytz.timezone(blog.timezone)
         date = inp.get('date')
         date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
         date_tz = date.replace(tzinfo=tz)
         # datetime = time.mktime(date)
         post.date = date_tz
     post.allow_comment = bool(inp.get('allow_comment'))
     post.allow_ping = bool(inp.get('allow_ping'))
     post.hidden = bool(inp.get('hidden'))
     
     # 以下分类代码写的比较乱
     # 文章添加分类最简单,直接分类统计加1
     # 分类修改则取得原分类减1,新分类加1
     # 删除分类则将旧分类减1
     category_key = inp.get('category')
     if category_key:
         category = Category.get(category_key)
     if post.category:
         if unicode(post.category.key()) != unicode(category_key):
             post.category.count = post.category.count - 1
             post.category.save()
             if category_key:
                 post.category = category
                 category.count = category.count + 1
                 category.save()
             else:
                 post.category = None
     elif category_key:
         post.category = category
         category.count = category.count + 1
         category.save()
     
     tags = inp.tags
     if tags:
         tags = tags.split(',')
         post.tags = tags
         for tag in tags:
             Tag.add(tag)
     post.save()
     
     clear_cache()
     
     from google.appengine.api import taskqueue
     queue = taskqueue.Queue()
     url = '/task/ping_sites'
     ping_task = taskqueue.Task(countdown=5, url=url)
     queue.add(ping_task)
     
     raise web.seeother('/admin/posts')
Example #6
0
 def test_get_by_id(self):
     test_post = Post.get_by_id(333)
     self.assertEqual(test_post, self.post)