def update(request, pk): notification = get_object_or_404(TopicNotification, pk=pk, user=request.user) form = NotificationForm(data=request.POST, instance=notification) if form.is_valid(): form.save() else: messages.error(request, utils.render_form_errors(form)) return redirect( request.POST.get('next', notification.topic.get_absolute_url()))
def create(request, topic_id): topic = get_object_or_404(Topic.objects.for_access(request.user), pk=topic_id) form = NotificationCreationForm(user=request.user, topic=topic, data=request.POST) if form.is_valid(): form.save() else: messages.error(request, utils.render_form_errors(form)) return redirect(request.POST.get('next', topic.get_absolute_url()))
def create(request, topic_id): topic = get_object_or_404(Topic, pk=topic_id) form = FavoriteForm(user=request.user, topic=topic, data=request.POST) if form.is_valid(): form.save() else: messages.error(request, utils.render_form_errors(form)) return safe_redirect(request, 'next', topic.get_absolute_url(), method='POST')
def move(request, topic_id): topic = get_object_or_404(Topic, pk=topic_id) form = CommentMoveForm(topic=topic, data=request.POST) if form.is_valid(): comments = form.save() for comment in comments: comment_posted(comment=comment, mentions=None) topic.decrease_comment_count() else: messages.error(request, render_form_errors(form)) return redirect(request.POST.get('next', topic.get_absolute_url()))
def create_access(request, topic_id): topic_private = TopicPrivate.objects.for_create_or_404(topic_id, request.user) form = TopicPrivateInviteForm( topic=topic_private.topic, data=post_data(request)) if form.is_valid(): form.save() notify_access(user=form.get_user(), topic_private=topic_private) else: messages.error(request, utils.render_form_errors(form)) return safe_redirect( request, 'next', topic_private.get_absolute_url(), method='POST')
def vote(request, pk): # TODO: check if user has access to this topic/poll poll = get_object_or_404(CommentPoll.objects.unremoved(), pk=pk) if not request.user.is_authenticated: return redirect_to_login(next=poll.get_absolute_url()) form = PollVoteManyForm(user=request.user, poll=poll, data=request.POST) if form.is_valid(): CommentPollChoice.decrease_vote_count(poll=poll, voter=request.user) form.save_m2m() CommentPollChoice.increase_vote_count(poll=poll, voter=request.user) return safe_redirect(request, 'next', poll.get_absolute_url(), method='POST') messages.error(request, utils.render_form_errors(form)) return safe_redirect(request, 'next', poll.get_absolute_url(), method='POST')