def topic_moderate(request, pk, value, remove=False, lock=False, pin=False): # TODO: move to topic_moderate and split it in many views topic = get_object_or_404(Topic, pk=pk) if request.method == 'POST': not_value = not value if remove: Topic.objects.filter(pk=pk, is_removed=not_value)\ .update(is_removed=value) if lock: count = Topic.objects.filter(pk=pk, is_closed=not_value)\ .update(is_closed=value) if count: action = CLOSED if value else UNCLOSED topic_post_moderate.send(sender=topic.__class__, user=request.user, topic=topic, action=action) if pin: count = Topic.objects.filter(pk=pk, is_pinned=not_value)\ .update(is_pinned=value) if count: action = PINNED if value else UNPINNED topic_post_moderate.send(sender=topic.__class__, user=request.user, topic=topic, action=action) return redirect(request.POST.get('next', topic.get_absolute_url())) return render(request, 'spirit/topic/topic_moderate.html', {'topic': topic, })
def topic_update(request, pk): topic = Topic.objects.for_update_or_404(pk, request.user) if request.method == 'POST': form = TopicForm(user=request.user, data=request.POST, instance=topic) category_id = topic.category_id if form.is_valid(): topic = form.save() if topic.category_id != category_id: topic_post_moderate.send(sender=topic.__class__, user=request.user, topic=topic, action=MOVED) return redirect(request.POST.get('next', topic.get_absolute_url())) else: form = TopicForm(user=request.user, instance=topic) return render(request, 'spirit/topic/topic_update.html', {'form': form, })
def topic_moderate(request, pk, value, remove=False, lock=False, pin=False): # TODO: move to topic_moderate and split it in many views # delete TopicUnread on remove topic = get_object_or_404(Topic, pk=pk) if request.method == 'POST': not_value = not value if remove: Topic.objects.filter(pk=pk, is_removed=not_value)\ .update(is_removed=value) if lock: count = Topic.objects.filter(pk=pk, is_closed=not_value)\ .update(is_closed=value) if count: action = CLOSED if value else UNCLOSED topic_post_moderate.send(sender=topic.__class__, user=request.user, topic=topic, action=action) if pin: count = Topic.objects.filter(pk=pk, is_pinned=not_value)\ .update(is_pinned=value) if count: action = PINNED if value else UNPINNED topic_post_moderate.send(sender=topic.__class__, user=request.user, topic=topic, action=action) return redirect(request.POST.get('next', topic.get_absolute_url())) return render(request, 'spirit/topic/topic_moderate.html', { 'topic': topic, })
def topic_update(request, pk): topic = Topic.objects.for_update_or_404(pk, request.user) if request.method == 'POST': form = TopicForm(user=request.user, data=request.POST, instance=topic) category_id = topic.category_id if form.is_valid(): topic = form.save() if topic.category_id != category_id: topic_post_moderate.send(sender=topic.__class__, user=request.user, topic=topic, action=MOVED) return redirect(request.POST.get('next', topic.get_absolute_url())) else: form = TopicForm(user=request.user, instance=topic) return render(request, 'spirit/topic/topic_update.html', { 'form': form, })