예제 #1
0
파일: views.py 프로젝트: CodeAltos/Dinette
def postReply(request):
    mlogger.info("in post reply.................")
    freply = ReplyForm(request.POST, request.FILES)

    if not freply.is_valid():
        d = {"is_valid": "false", "response_html": freply.as_table()}
        if request.FILES:
            json_data = "<textarea>" + json.dumps(d) + "</textarea>"
        else:
            json_data = json.dumps(d)
        return HttpResponse(json_data, content_type=json_mimetype)

    #code which checks for flood control
    if (datetime.now() - (request.user.dinette_profile.last_posttime)
        ).seconds <= settings.FLOOD_TIME:
        #oh....... user trying to flood us Stop him
        d2 = {
            "is_valid":
            "flood",
            "errormessage":
            "You have posted message too recently. Please wait a while before trying again."
        }
        if request.FILES:
            json_data = "<textarea>" + json.dumps(d2) + "</textarea>"
        else:
            json_data = json.dumps(d2)
        return HttpResponse(json_data, content_type=json_mimetype)

    reply = freply.save(commit=False)
    #only if there is any file
    if len(request.FILES.keys()) == 1:
        if (request.FILES['file'].content_type.find("image") >= 0):
            reply.attachment_type = "image"
        else:
            reply.attachment_type = "text"

        reply.filename = request.FILES['file'].name

    reply.posted_by = request.user
    mlogger.debug("toipcid= %s" % request.POST['topicid'])
    reply.topic = Ftopics.objects.get(pk=request.POST['topicid'])
    #Assigning user rank
    mlogger.debug("Assigning an user rank, and last posted datetime")
    assignUserElements(request.user)
    reply.save()
    payload = {'reply': reply}
    mlogger.debug("what is the replymesage = %s" % reply.message)
    response_html = render_to_string('dinette/replydetail_frag.html', payload,
                                     RequestContext(request))
    mlogger.debug("what is the response = %s " % response_html)

    d2 = {"is_valid": "true", "response_html": response_html}

    #     if request.FILES :
    #         #this the required for ajax file uploads
    #         json_data = "<textarea>"+json.dumps(d2)+"</textarea>"
    #     else:
    json_data = json.dumps(d2)

    return HttpResponse(json_data, content_type=json_mimetype)
예제 #2
0
파일: views.py 프로젝트: jgruca/Dinette
def postReply(request):
    mlogger.info("in post reply.................")
    freply = ReplyForm(request.POST,request.FILES)

    if not freply.is_valid():
        d = {"is_valid":"false","response_html":freply.as_table()}
        json = simplejson.dumps(d)
        if request.FILES :
            json = "<textarea>"+simplejson.dumps(d)+"</textarea>"
        else:
            json = simplejson.dumps(d)
        return HttpResponse(json, content_type=json_mimetype)



    #code which checks for flood control
    if (timezone.now() -(request.user.get_profile().last_posttime)).seconds <= settings.FLOOD_TIME:
    #oh....... user trying to flood us Stop him
        d2 = {"is_valid":"flood","errormessage":"You have posted message too recently. Please wait a while before trying again."}
        if request.FILES :
            json = "<textarea>"+simplejson.dumps(d2)+"</textarea>"
        else :
            json = simplejson.dumps(d2)
        return HttpResponse(json, content_type=json_mimetype)


    reply = freply.save(commit=False)
     #only if there is any file
    if len(request.FILES.keys()) == 1 :
        if(request.FILES['file'].content_type.find("image") >= 0 ) :
            reply.attachment_type = "image"
        else :
            reply.attachment_type = "text"

        reply.filename = request.FILES['file'].name

    reply.posted_by = request.user
    mlogger.debug("toipcid= %s" %request.POST['topicid'])
    reply.topic = Ftopics.objects.get(pk = request.POST['topicid'])
    #Assigning user rank
    mlogger.debug("Assigning an user rank, and last posted datetime")
    assignUserElements(request.user)
    reply.save()
    payload = {'reply':reply}
    mlogger.debug("what is the replymesage = %s" %reply.message)
    response_html = render_to_string('dinette/replydetail_frag.html', payload ,RequestContext(request))
    mlogger.debug("what is the response = %s " % response_html)

    d2 = {"is_valid":"true","response_html":response_html}

    if request.FILES :
        #this the required for ajax file uploads
        json = "<textarea>"+simplejson.dumps(d2)+"</textarea>"
    else:
        json = simplejson.dumps(d2)

    return HttpResponse(json, content_type=json_mimetype)
예제 #3
0
파일: views.py 프로젝트: jgruca/Dinette
def editReply(request, reply_id):
    reply = get_object_or_404(Reply, pk=reply_id)
    if not (reply.posted_by == request.user or request.user in reply.topic.category.moderated_by.all()):
        return HttpResponseForbidden()

    if request.POST:
        form = ReplyForm(request.POST, request.FILES, instance=reply)
        if form.is_valid():
            form.save()
            #redirect to prev page
            return HttpResponseRedirect(reply.get_url_with_fragment())
    else:
        # message should be original input, not the rendered one
        form = ReplyForm(instance=reply, initial={'message': reply.message.raw})

    return render_to_response('dinette/edit_reply.html', {'replyform': form, 'reply_id': reply_id}, context_instance=RequestContext(request))
예제 #4
0
def editReply(request, reply_id):
    reply = get_object_or_404(Reply, pk=reply_id)
    if not (reply.posted_by == request.user or request.user in reply.topic.category.moderated_by.all()):
        return HttpResponseForbidden()

    if request.POST:
        form = ReplyForm(request.POST, request.FILES, instance=reply)
        if form.is_valid():
            form.save()
            #redirect to prev page
            return HttpResponseRedirect(reply.get_url_with_fragment())
    else:
        # message should be original input, not the rendered one
        form = ReplyForm(instance=reply, initial={'message': reply.message.raw})

    return render_to_response('dinette/edit_reply.html', {'replyform': form, 'reply_id': reply_id}, context_instance=RequestContext(request))