예제 #1
0
def replayAJAX(request, topicID=None, postID=None):
    """ 通过 AJAX 方式回复 """

    if not request.user.is_authenticated():
        return HttpResponse(
            u'<h1>您没有权限!请 <a href="/account/login">登录</a></h1>')

    replayID = None  # 需要回复的 id
    parent_post = None

    if topicID:
        topic = get_object_or_404(Topic, pk=topicID)
        replayID = topicID
    elif postID:
        parent_post = get_object_or_404(Post, pk=postID)
        topic = get_object_or_404(Topic, pk=parent_post.topic.id)
        replayID = postID
    else:
        return HttpResponse(u'topicID 和 postID 必需要指定一个!')

    if request.method == 'GET':
        m = 'POST' if postID else 'TOPIC'
        ajaxFunc = 'ajax_replay(this, "%s", "%s")' % (m, replayID)
        return {'method': 'GET', 'ajaxFunc': ajaxFunc}

    else:

        if not topic.catalog.has_access(request.user):
            return HttpResponse(u'<h1>您没有权限回复此帖!</h1>')

        # 如果 topic 已锁,则重定向到显示 topic
        if topic and topic.closed:
            return HttpResponse(u'主题已锁定,不可回复!')

        ip = ylinux_get_ip(request)

        post_body = request.POST.get("body", None)
        if len(post_body) < 2:
            return {'error': u'您的回复太短,至少2个字符!'}
        post = Post(topic=topic,
                    user=request.user,
                    user_ip=ip,
                    markup='none',
                    body=post_body,
                    parent=parent_post)
        post.save()
        topic.post_count += 1
        topic.last_post = post
        topic.save()
        topic.catalog.post_count += 1
        topic.catalog.last_post = post
        topic.catalog.save()

        return {'method': 'POST', 'topic': topic, 'post': post}
예제 #2
0
파일: forms.py 프로젝트: xycfree/ylinux_old
 def save(self):
     post = Post(topic=self.topic,
                 user=self.user,
                 user_ip=self.ip,
                 markup='none',
                 body=self.cleaned_data['body'])
     self.topic.post_count += 1
     self.topic.save()
     self.topic.catalog.post_count += 1
     self.topic.catalog.save()
     post.updated = datetime.datetime.now()
     post.save()
     if ydata_settings.ATTACHMENT_SUPPORT:
         self.save_attachment(post, self.cleaned_data['attachment'])
     return post
예제 #3
0
파일: views.py 프로젝트: Czlyc/ylinux
def replayAJAX(request, topicID=None, postID=None):
    """ 通过 AJAX 方式回复 """

    if not request.user.is_authenticated():
        return HttpResponse(u'<h1>您没有权限!请 <a href="/account/login">登录</a></h1>')

    replayID = None  # 需要回复的 id
    parent_post = None

    if topicID:
        topic = get_object_or_404(Topic, pk=topicID)
        replayID = topicID
    elif postID:
        parent_post = get_object_or_404(Post, pk=postID)
        topic = get_object_or_404(Topic, pk=parent_post.topic.id)
        replayID = postID
    else:
        return HttpResponse(u"topicID 和 postID 必需要指定一个!")

    if request.method == "GET":
        m = "POST" if postID else "TOPIC"
        ajaxFunc = 'ajax_replay(this, "%s", "%s")' % (m, replayID)
        return {"method": "GET", "ajaxFunc": ajaxFunc}

    else:

        if not topic.catalog.has_access(request.user):
            return HttpResponse(u"<h1>您没有权限回复此帖!</h1>")

        # 如果 topic 已锁,则重定向到显示 topic
        if topic and topic.closed:
            return HttpResponse(u"主题已锁定,不可回复!")

        ip = ylinux_get_ip(request)

        post_body = request.POST.get("body", None)
        if len(post_body) < 2:
            return {"error": u"您的回复太短,至少2个字符!"}
        post = Post(topic=topic, user=request.user, user_ip=ip, markup="none", body=post_body, parent=parent_post)
        post.save()
        topic.post_count += 1
        topic.last_post = post
        topic.save()
        topic.catalog.post_count += 1
        topic.catalog.last_post = post
        topic.catalog.save()

        return {"method": "POST", "topic": topic, "post": post}