views.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:closedverse 作者: ariankordi 项目源码 文件源码
def post_create(request, community):
    if request.method == 'POST' and request.is_ajax():
        # Wake
        request.user.wake(request.META['REMOTE_ADDR'])
        # Required
        if not (request.POST.get('community')):
            return HttpResponseBadRequest()
        try:
            community = Community.objects.get(id=community, unique_id=request.POST['community'])
        except (Community.DoesNotExist, ValueError):
            return HttpResponseNotFound()
        # Method of Community
        new_post = community.create_post(request)
        if not new_post:
            return HttpResponseBadRequest()
        if isinstance(new_post, int):
            # If post limit 
            if new_post == 8:
                # then do meme
                return json_response("You have already exceeded the number of posts that you can contribute in a single day. Please try again tomorrow.", 1215919)
            return json_response({
            1: "Your post is too long ("+str(len(request.POST['body']))+" characters, 2200 max).",
            2: "The image you've uploaded is invalid.",
            3: "You're making posts too fast, wait a few seconds and try again.",
            4: "Apparently, you're not allowed to post here.",
            5: "Uh-oh, that URL wasn't valid..",
            6: "Not allowed.",
            7: "Please don't spam.",
            }.get(new_post))
        # Render correctly whether we're posting to Activity Feed
        if community.is_activity():
            return render(request, 'closedverse_main/elements/community_post.html', { 
            'post': new_post,
            'with_community_container': True,
            'type': 2,
            })
        else:
            return render(request, 'closedverse_main/elements/community_post.html', { 'post': new_post })
    else:
        raise Http404()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号