示例#1
0
文件: main.py 项目: perol/xblog
 def _add(cls, post, content, ip, author_email = None, author_nickname = None, link = None):
     u = get_user()
     if author_email is None:
         #登录用户发帖
         c = cls(parent = post, email = u.email, nickname = u.nickname, author = u, post = post, \
                 content = content, ip = ip, add_time = datetime.datetime.utcnow())
         if link and u.link != link:
             u.link = link
         if author_nickname and author_nickname != u.nickname:
             u.nickname = author_nickname
             c.nickname = author_nickname
     else:
         c = cls(parent = post, email = author_email, nickname = author_nickname, post = post, \
                 content = content, ip = ip, add_time = datetime.datetime.utcnow())
     if link:
         c.link = link
     
     def txn():
         c.put()
         post.comment_count += 1
         if author_email is None:
             u.comment_count += 1
             u.put()
         post.put()
     db.run_in_transaction(txn)
示例#2
0
文件: main.py 项目: perol/xblog
def add_comment(request):
    post_key = request.POST["post_key"].strip()
    post = db.get(post_key)
    author = get_user()

    nickname = request.POST["nickname"].strip()
    email = request.POST["email"].strip()
    link = request.POST["link"].strip()
    if not link:
        link = None
    content = request.POST["content"].strip()

    if not nickname or not email or not content:
        return HttpResponse(simplejson.dumps({"state": "err", "msg": u"请完整填写昵称、电子邮件和内容"}))

    if not re.match(r"^\w+((_-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$", email):
        return HttpResponse(simplejson.dumps({"state": "err", "msg": u"邮箱地址格式不正确"}))

    ip = request.META["REMOTE_ADDR"]

    if author:
        Comment.auth_add(post, content, ip, author_nickname=nickname, link=link)
    else:
        Comment.anonymous_add(post, content, ip, email, nickname, link=link)

    return HttpResponse(simplejson.dumps({"state": "ok", "msg": u"评论发表成功"}))
示例#3
0
文件: main.py 项目: perol/xblog
 def modify(self, title, content, summary = None, add_time = None):
     u = get_user()
     self.title = title
     self.content = content
     self.summary = summary
     if add_time:
         self.add_time = add_time
     
     self.modify_time = datetime.datetime.utcnow()
     self.modify_user = u
     self.put()
示例#4
0
文件: main.py 项目: perol/xblog
    def delete(self):
        u = get_user()
        def txn():
            #super(Post, self).delete()
            self.is_delete = True
            self.delete_user = u
            self.author.post_count -= 1
            self.put()
            self.author.put()

        db.run_in_transaction(txn)
        generalcounter.decrement('post')
示例#5
0
文件: main.py 项目: perol/xblog
    def delete(self):
        u = get_user()
        def txn():
            self.is_delete = True
            self.delete_user = u
           
            self.post.comment_count -= 1

            self.put()
            self.post.put()
            if self.author:
                self.author.comment_count -= 1
                self.author.put()
        db.run_in_transaction(txn)
示例#6
0
 def check_login(request, *args, **kwargs):
     user = get_user()
     if not user:
         if request.method != 'GET':
             return HttpResponseForbidden()
         else:
             return HttpResponseRedirect(users.create_login_url(request.path))
     elif role == "user" or (role == "admin" and user.level == 10):
         return handler_method(request, *args, **kwargs)
     else:
         if request.method == 'GET':
             return HttpResponseForbidden()
         else:
             return HttpResponseForbidden()   # User didn't meet role.
示例#7
0
文件: main.py 项目: perol/xblog
    def add(cls, title, content, summary = None, add_time = None):
        u = get_user()
        count = cls.count()
        if add_time is None:
            add_time = datetime.datetime.utcnow()
        p = cls(parent =u, offset = count+1, title = title, content = content, \
                author = u, add_time = add_time)
        if summary:
            p.summary = summary
        
        u.post_count += 1

        def txn():
            p.put()
            u.put()
        db.run_in_transaction(txn)
        generalcounter.increment('post')
示例#8
0
文件: main.py 项目: perol/xblog
def show_post(request, post_key):
    post = db.get(post_key)
    # 上一篇 和 下一篇
    pre_post = Post.all().order("offset").filter("offset > ", post.offset).get()
    next_post = Post.all().order("-offset").filter("offset < ", post.offset).get()

    return render_to_response(
        "show_post.html",
        {
            "post": post,
            "pre_post": pre_post,
            "next_post": next_post,
            "user": get_user(),
            "comment_list": post.get_comment_list(),
        },
        RequestContext(request),
    )
示例#9
0
文件: rpc.py 项目: perol/xblog
def upload_image(request):
    img = Images()

    img_file = request.FILES.get('img')
    if not img_file:
        return HttpResponse('{status:"Please select your image."}')

    img.uploader = get_user()
    img.add_time = datetime.datetime.utcnow()

    if get_django_version() >= 1:
        content = img_file.read()
        file_path = img_file.name
    else:
        content = img_file['content']
        file_path = img_file['filename']

    img.content = db.Blob(content) 
    img.image_type = ai.get_content_type(file_path)
    key = img.put()
    return HttpResponse('{status:"UPLOADED",image_url: "/rpc/img/?img_id=%s"}' % (key))