예제 #1
0
def reply(request, mlist_fqdn, message_id_hash):
    """ Sends a reply to the list.
    TODO: unit tests
    """
    if request.method != 'POST':
        raise SuspiciousOperation
    form = ReplyForm(request.POST)
    if not form.is_valid():
        return HttpResponse(form.errors.as_text(),
                            content_type="text/plain", status=400)
    store = get_store(request)
    mlist = store.get_list(mlist_fqdn)
    if form.cleaned_data["newthread"]:
        subject = form.cleaned_data["subject"]
        headers = {}
    else:
        message = store.get_message_by_hash_from_list(mlist.name, message_id_hash)
        subject = message.subject
        if not message.subject.lower().startswith("re:"):
            subject = "Re: %s" % subject
        headers = {"In-Reply-To": "<%s>" % message.message_id,
                   "References": "<%s>" % message.message_id, }
    try:
        post_to_list(request, mlist, subject, form.cleaned_data["message"], headers)
    except PostingFailed, e:
        return HttpResponse(str(e), content_type="text/plain", status=500)
예제 #2
0
def reply_to_question(request, question_id):
    question = Question.objects.get(id=int(question_id))
    form = ReplyForm(request.POST)
    if form.is_valid():
        question.reply = form.cleaned_data["text"]
        question.save()
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
예제 #3
0
def view(request, pk):

    if pk > 0:

	#database queries for bulletin info
	bulletin = Bulletin.objects.get(pk=pk)
	allreplies = Reply.objects.filter(thread__bulletin=bulletin)
	replies= allreplies.filter(public=True).order_by("-timestamp")
	privatecount = allreplies.filter(public=False).exclude(sender=bulletin.creator).count()
    else: return render(request, '404.html', {})

    if request.method == 'POST':
	form = ReplyForm(request.POST)
	if form.is_valid():
	    cleaned_data = form.clean()
	    if request.POST['visibility'] == 'Public':
		public = True
	    else: public = False
	    if request.user.userdata != bulletin.creator or public:
                message = cleaned_data['message']
                outmail.replyToBulletin(bulletin, message, request.user.userdata, public)

    #update page
    form = ReplyForm()
    resolveform = ResolverCreditForm()
    if request.user.is_authenticated and request.user.userdata == bulletin.creator:
	bulletinform = UpdateBulletinForm()
    else: bulletinform = {}
    return render(request, 'bulletin.html', {'bulletin':bulletin, 'replies':replies, 'privatecount':privatecount, 'form':form, 'bulletinform':bulletinform, 'resolveform':resolveform})
예제 #4
0
def submit_reply(request, board_id, post_id):
    if not request.user.is_authenticated or request.user.username == "":
        return render(request, 'login.html', {})

    try:
        board = DefaultBoard.objects.get(pk=board_id)
        post = Post.objects.get(pk=post_id)

        if not board.access(request.user, access_type="post", default=False):
            context = {'board': board}
            return render(request, 'board_noperm.html', context)

        if request.method == "POST":
            form = ReplyForm(request.POST)
            if not form.is_valid():
                return Http404("Error submitting post.")

            text = form.cleaned_data['text']

            board.create_post(subject="Re: " + post.db_subject, text=text, author_name=request.user.username,
                              author_player=request.user, parent=post)
            return HttpResponseRedirect("/boards/" + str(board.id) + "/" + str(post.id) + "/")
        else:
            form = ReplyForm()
            context = {'board': board, 'board_id': board.id, 'post_id': post.id, 'form': form}
            return render(request, 'submit_reply.html', context)

    except (Board.DoesNotExist, Board.MultipleObjectsReturned, Post.DoesNotExist, Post.MultipleObjectsReturned):
        return Http404("Error accessing boards.")
예제 #5
0
def thread(request, pk):
    """Render a single thread's info, usually for the mailbox"""

    print 'made it!'
    thread = Reply_Thread.objects.get(id=pk)
    info={}

    #You have to belong to the thread to access it!
    if request.session['pk'] in [thread.bulletin.creator.pk, thread.replier.pk]:
	info.update({'thread':thread})
	new=[]
	for reply in thread.reply_set.exclude(sender__id=request.session['pk']).filter(read=False):
	    new.append(reply.id)
	    reply.read=True
	    reply.save()
	#Handle request to add replies to the thread
	if request.method == 'POST':
	    form = ReplyForm(request.POST)
	    if form.is_valid():
		cleaned_data = form.clean()
		if request.POST['visibility'] == 'Public':
		    public = True
		else: public = False
        #Maybe works?
		user = UserData.objects.get(pk==request.session['pk'])
		message = cleaned_data['message']
                outmail.replyWithThread(thread, message, user, public)
    #Filling out the necessary context
    form = ReplyForm()
    info.update({'form':form, 'new':new});
    return render(request, 'elements/replythread.html', info)
예제 #6
0
def view_question(request,classes,lecture_number,noteslug,qpk):
    lectures = Lecture.objects.filter(slug=classes,
        lecture_number=lecture_number)
    note = Note.objects.filter(slug=noteslug)
    question = NoteQuestion.objects.filter(pk=qpk)
    replies = NoteReply.objects.filter(question=question)
    if request.POST:
        replyform = ReplyForm(request.POST)
        if replyform.is_valid():
            newreply = replyform.save(commit=False)
            newreply.author = User.objects.get(username=request.user)
            newreply.question = question[0]
            newreply.save()

            return HttpResponseRedirect('.')
    else:
        replyform = ReplyForm(request.POST)
    args = {}
    args.update(csrf(request))
    isauthor = (question[0].author == request.user.username) or request.user.is_superuser
    isnoteauthor = (note[0].author == request.user.username) or request.user.is_superuser
    args['form'] = replyform
    args['classes'] = lectures[0].course.classes
    args['lectureslug'] = classes
    args['lecture_number'] = lecture_number
    args['note'] = note[0]
    args['question'] = question[0]
    args['replies'] = replies
    args['isauthor'] = isauthor
    args['isnoteauthor'] = isnoteauthor
    return render_to_response('view_question.html', args)
예제 #7
0
def reply(request, mlist_fqdn, message_id_hash):
    """ Sends a reply to the list.
    TODO: unit tests
    """
    if request.method != 'POST':
        raise SuspiciousOperation
    form = ReplyForm(request.POST)
    if not form.is_valid():
        return HttpResponse(form.errors.as_text(),
                            content_type="text/plain",
                            status=400)
    store = get_store(request)
    mlist = store.get_list(mlist_fqdn)
    if form.cleaned_data["newthread"]:
        subject = form.cleaned_data["subject"]
        headers = {}
    else:
        message = store.get_message_by_hash_from_list(mlist.name,
                                                      message_id_hash)
        subject = message.subject
        if not message.subject.lower().startswith("re:"):
            subject = "Re: %s" % subject
        headers = {
            "In-Reply-To": "<%s>" % message.message_id,
            "References": "<%s>" % message.message_id,
        }
    try:
        post_to_list(request,
                     mlist,
                     subject,
                     form.cleaned_data["message"],
                     headers,
                     attachments=request.FILES.getlist('attachment'))
    except PostingFailed, e:
        return HttpResponse(str(e), content_type="text/plain", status=500)
예제 #8
0
def reply_to_question(request, question_id):
    question = Question.objects.get(id=int(question_id))
    form = ReplyForm(request.POST)
    if form.is_valid():
        question.reply = form.cleaned_data["text"]
        question.save()
    return redirect_user_to_homepage(request.user.profile.user_type)
예제 #9
0
파일: views.py 프로젝트: ortutay/wikitruth
    def post(self, request, id):
        form = ReplyForm(request.POST)
        response = Response.objects.get(pk=id)
        if not form.is_valid():
            print 'errors', form.errors
            context = {
                'form': form,
                'response': response,
            }
            return render(request, 'claims/responses/detail.html', context)

        parent = None
        if form.cleaned_data['comment_id']:
            parent = Comment.objects.get(pk=form.cleaned_data['comment_id'])

        print 'trying to make...'

        Comment.objects.create(user=request.user,
                               response=response,
                               parent=parent,
                               body=form.cleaned_data['body'])

        print 'made comment, redirecting'

        return redirect('response-detail', id=response.id)
예제 #10
0
파일: views.py 프로젝트: xdlinux/mailbbs
def reply(request,target_mail_id):
	"""docstring for send_mail"""
	tmail=get_object_or_404(Mail,id=target_mail_id)
	if request.POST:
		form=ReplyForm(request.POST)
		if form.is_valid():
			send_mail(tmail,form)
			return HttpResponseRedirect('/')
	else:
		form=ReplyForm()
	return render_to_response('reply.html',locals())
예제 #11
0
파일: views.py 프로젝트: nonni/fruss
def get_thread_posts(request, thread_id):
    """
    Returns all posts in a thread, including the 'thread' post itself.
    """
    thread = get_object_or_404(Thread, pk=thread_id)
    if thread.hidden:
        raise Http404

    # Mark thread a read for user.
    read = UserRead.objects.get_or_create(user=request.user, thread=thread_id)[0]
    read.read = True
    read.save()

    if request.method == "POST":
        form = ReplyForm(request.POST)
        if form.is_valid():
            reply = form.save(commit=False)

            # TODO: Check if user is logged in
            reply.author = request.user
            reply.thread_id = thread_id
            reply.pub_date = datetime.now()
            reply.update = datetime.now()
            reply.save()
            thread.latest_post = reply
            thread.save()
            form = ReplyForm()  # Clear the form
            # Mark thread as unread for other users
            ur = UserRead.objects.all().filter(thread__exact=thread_id).exclude(user=request.user)
            for u in ur:
                u.read = False
                u.save()
            # Focus on new post after reply.
            return HttpResponseRedirect("%s?page=last#post_%s" % (reverse("thread", args=[thread.id]), reply.id))
    else:
        form = ReplyForm()

    post_list = Post.objects.all().filter(thread=thread_id, hidden=False)
    p = Paginator(post_list, 5)
    try:
        page = int(request.GET.get("page", "1"))
    except:
        page = p.num_pages
    try:
        posts = p.page(page)
    except (EmptyPage, InvalidPage):
        raise Http404

    return render_to_response(
        "dsf/thread_detail.html",
        {"thread": thread, "posts": posts, "form": form},
        context_instance=RequestContext(request),
    )
예제 #12
0
파일: views.py 프로젝트: ivy90085/forum
def reply(request, topic_id):
    if request.method == 'POST':
        form = ReplyForm(request.POST)
        if form.is_valid():
            reply = form.save(commit=False)
            reply.topic_id = topic_id
            reply.save()
            topic = Topic.objects.get(id=topic_id)
            topic.reply_date = timezone.now()
            topic.save()
            return redirect("/")
    else:
        form = ReplyForm()
        return render_to_response('form.html',{'form': form}, context_instance=RequestContext(request))
예제 #13
0
def window_comment_reply(request):
    reply_form = ReplyForm(request.POST)
    if reply_form.is_valid():
        reply_dict = reply_form.cleaned_data
        window_id = request.user_meta['window_model'].id
        order_model = order.get_order_byid_bywin(window_id, reply_dict)
        order_dish_model = orderdish.get_order_dish_byid(order_model, reply_dict)
        if order_dish_model.comment_time:  # user can only make reply on comments
            if order_dish_model.reply_time is None:
                orderdish.update_reply(order_dish_model, reply_dict)
                return json_response(OK, CODE_MESSAGE.get(OK))
            else:
                return json_response(ORDER_DISH_REPLIED, CODE_MESSAGE.get(ORDER_DISH_REPLIED))
        else:
            return json_response(ORDER_STATUS_ERROR, CODE_MESSAGE.get(ORDER_STATUS_ERROR))
    else:
        return json_response(PARAM_REQUIRED, CODE_MESSAGE.get(PARAM_REQUIRED))
예제 #14
0
파일: views.py 프로젝트: nonni/fruss
def edit_post(request, post_id):
    post = get_object_or_404(Post, pk=post_id)
    if not request.user is post.author and not request.user.is_superuser:
        return HttpResponse("Access denied!")
    if request.method == "POST":
        form = ReplyForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            body = data["body"]
            post = get_object_or_404(Post, pk=post_id)
            post.body = body
            post.markdown = data["markdown"]
            post.update = datetime.now()
            post.save()
            return HttpResponse(markdown.markdown(post.body))
    if request.user.is_superuser or post.author is request.user:
        form = ReplyForm(post.__dict__)
        return render_to_response("dsf/post_edit.html", {"form": form, "post_id": post_id})
    else:
        return HttpResponse(_("Access denied!"))
예제 #15
0
def reply(request, mlist_fqdn, message_id_hash):
    """ Sends a reply to the list.
    TODO: unit tests
    """
    if request.method != 'POST':
        raise SuspiciousOperation
    form = ReplyForm(request.POST)
    if not form.is_valid():
        return HttpResponse(form.errors.as_text(),
                            content_type="text/plain", status=400)
    store = get_store(request)
    mlist = store.get_list(mlist_fqdn)
    message = store.get_message_by_hash_from_list(mlist.name, message_id_hash)
    subject = message.subject
    if not message.subject.lower().startswith("re:"):
        subject = "Re: %s" % subject
    _send_email(request, mlist, subject, form.cleaned_data["message"], {
                    "In-Reply-To": "<%s>" % message.message_id,
                    "References": "<%s>" % message.message_id,
                })
    return HttpResponse("The reply has been sent successfully.",
                        mimetype="text/plain")
예제 #16
0
def reply_view(request, pk_forum, pk_thread):
    forum = get_object(Forum.objects.active(), pk=pk_forum)
    category = forum.category
    threads = forum.threads.active()
    thread = get_object(threads, pk=pk_thread)
    form = ReplyForm(request.POST or None)
    editor_name = MARKUP_EDITORS[MARKUP]
    editor_style = 'js/forum/markitup/sets/%s/style.css' % editor_name
    editor_set = 'js/forum/markitup/sets/%s/set.js' % editor_name

    if form.is_bound and form.is_valid():
        new_reply = form.save(request.user.forum_profile, forum, thread)
        return redirect(new_reply)

    return render(request, 'forum/reply.html', {
        'category': category,
        'forum': forum,
        'thread': thread,
        'form': form,
        'editor_name': editor_name,
        'editor_style': editor_style,
        'editor_set': editor_set,
    })
예제 #17
0
파일: views.py 프로젝트: mwotil/nuaza
def add_reply(request):
    form = ReplyForm(request.POST)
    if form.is_valid():
        reply = form.save(commit=False)
        review = request.POST.get('review')
        user_rep = request.POST.get('user')
	r1 = reply.rate_objective
	r2 = reply.rate_complete

	repute_rev = User_Reputation.objects.get(user = user_rep)

	reputation = User_Reputation.objects.filter(user = request.user)

	if reputation:
		r = User_Reputation.objects.get(user = request.user)
		repute = r.reputation
		entity_alpha = r.entity_alpha
		entity_beta =  r.entity_beta
	else:
		r = User_Reputation()
		r.user = request.user
		r.reputation = 0.5
		r.entity_alpha = 0.5
		r.entity_beta =  0.5
		r.votes = 0

		entity_alpha = 0.5
		entity_beta = 0.5
		repute = 0.5

		r.save()

	#r3 = ((r1+r2)/2) * repute/1000

	alpha = ((r1+r2)/2)

        beta = 1 - alpha
        entity_alpha += alpha
        entity_beta += beta
	entity_reputation = (entity_alpha/(entity_alpha + entity_beta))


	r4 = repute_rev.reputation

	if r4 == 1:
		repute_rev.reputation = r4
		repute_rev.entity_alpha = entity_alpha
		repute_rev.entity_beta = entity_beta
	 	repute_rev.save()

	else:
		repute_rev.reputation = (r4 + entity_reputation)/2
		repute_rev.entity_alpha = entity_alpha
		repute_rev.entity_beta = entity_beta
	 	repute_rev.save()

        review = ProductReview.objects.get(id=review)
	reply.review = review
        reply.user = request.user
	
	reply.save()
    
        template = "pdcts/reply_review.html"
        html = render_to_string(template, {'reply': reply })
        response = simplejson.dumps({'success':'True', 'html': html})
        
    else:
        html = form.errors.as_ul()
        response = simplejson.dumps({'success':'False', 'html': html})
    return HttpResponse(response, content_type='application/javascript; charset=utf-8')
예제 #18
0
def post_body_view(request, school_name, post_id, post_type):
    form_msg = {}
    ctx = {}
    print post_type

    if request.method == 'POST':
        user = request.user
        ip = get_ip_address(request)
        post = get_post_by_id(post_id)
        if post_type == "reply":
            post_form_kwargs = {
                "user": user, "post": post,
                "ip": ip}

            form = ReplyForm(
                request.POST, **post_form_kwargs)
        else:
            reply_id = request.POST['reply_id']
            print reply_id
            post_form_kwargs = {
                "user": user, "ip": ip,
                "reply_id": reply_id}

            form = CommentForm(
                request.POST, **post_form_kwargs)

        if form.is_valid():
            print form.cleaned_data
            form.save()

            if post_type == "reply":
                context = Context({'replys': [form.reply], 'commentForm': CommentForm()})
                return_str = render_block_to_string(
                    'discussion/post-body.html', 'replys', context)
            else:
                return_str = {
                    "reply_id": form.reply_id,
                    "comment": form.comment.comment_body}

            form_msg['message'] = return_str
        else:
            form_msg['errors'] = form.errors

        print form_msg
        json_ctx = json.dumps(form_msg)
        return HttpResponse(json_ctx, mimetype='application/json')

    else:
        replyForm = ReplyForm()
        commentForm = CommentForm()
        post = get_post_by_id(post_id)
        reply = get_post_reply(post_id)

        ctx = {
            "school_name": school_name,
            "post": post,
            "replys": reply,
            "commentForm": commentForm,
            "replyForm": replyForm}

    return render_to_response(
        'discussion/post-body.html', ctx,
        context_instance=RequestContext(request))
예제 #19
0
파일: views.py 프로젝트: mwotil/nuaza
def add_reply(request):
    form = ReplyForm(request.POST)
    if form.is_valid():
        reply = form.save(commit=False)
        review = request.POST.get('review')
        user_rep = request.POST.get('user')
        r1 = reply.rate_objective
        r2 = reply.rate_complete

        repute_rev = User_Reputation.objects.get(user=user_rep)

        reputation = User_Reputation.objects.filter(user=request.user)

        if reputation:
            r = User_Reputation.objects.get(user=request.user)
            repute = r.reputation
            entity_alpha = r.entity_alpha
            entity_beta = r.entity_beta
        else:
            r = User_Reputation()
            r.user = request.user
            r.reputation = 0.5
            r.entity_alpha = 0.5
            r.entity_beta = 0.5
            r.votes = 0

            entity_alpha = 0.5
            entity_beta = 0.5
            repute = 0.5

            r.save()

#r3 = ((r1+r2)/2) * repute/1000

        alpha = ((r1 + r2) / 2)

        beta = 1 - alpha
        entity_alpha += alpha
        entity_beta += beta
        entity_reputation = (entity_alpha / (entity_alpha + entity_beta))

        r4 = repute_rev.reputation

        if r4 == 1:
            repute_rev.reputation = r4
            repute_rev.entity_alpha = entity_alpha
            repute_rev.entity_beta = entity_beta
            repute_rev.save()

        else:
            repute_rev.reputation = (r4 + entity_reputation) / 2
            repute_rev.entity_alpha = entity_alpha
            repute_rev.entity_beta = entity_beta
            repute_rev.save()

        review = ProductReview.objects.get(id=review)
        reply.review = review
        reply.user = request.user

        reply.save()

        template = "pdcts/reply_review.html"
        html = render_to_string(template, {'reply': reply})
        response = simplejson.dumps({'success': 'True', 'html': html})

    else:
        html = form.errors.as_ul()
        response = simplejson.dumps({'success': 'False', 'html': html})
    return HttpResponse(response,
                        content_type='application/javascript; charset=utf-8')