def edit(request, id): breadcrumb = (('Community', '/community/'), ('Discuss', None)) thread = get_object_or_404(DiscussionThread, pk=id, is_removed=False) comment = thread.content_object form = EditDiscussForm(instance=comment) if request.method == 'POST': form = EditDiscussForm(request.POST, instance=comment) if form.is_valid(): form.save() if request.POST['status'] in ['preview', 'unpublish']: thread.is_public = False else: thread.is_public = True thread.save() if not moderator.process(thread, request): if thread.is_public: send_to_discuss_mailing_list(thread.content_object, request) update_discuss_activity_stream(thread.content_object, request) return redirect('discuss-post-detail', id=thread.id) if not thread.can_edit(request.user): return redirect('discuss-index') return render(request, 'discuss/edit.html', { 'breadcrumb': breadcrumb, 'form': form, 'thread': thread })
def new(request): breadcrumb = (('Community', '/community/'), ('Discuss', None)) form = EditDiscussForm() if request.method == 'POST': form = EditDiscussForm(request.POST) if form.is_valid(): discussion_thread_type = ContentType.objects.get(app_label='discuss', model='discussionthread') threadedcomment_type = ContentType.objects.get(app_label='threadedcomments', model='threadedcomment') # use placeholder data for now thread = DiscussionThread(object_pk=1, content_type=threadedcomment_type, last_comment_id=1) thread.save() comment = form.save(commit=False) comment.content_type = discussion_thread_type comment.object_pk = thread.pk comment.site = get_current_site(request) comment.user = request.user comment.save() # now we have real data thread.object_pk = comment.pk thread.last_comment_id = comment.id if request.POST['status'] in ['preview']: thread.is_public = False else: thread.is_public = True thread.save() if not moderator.process(thread, request): if thread.is_public: send_to_discuss_mailing_list(thread.content_object, request) update_discuss_activity_stream(thread.content_object, request) return redirect('discuss-post-detail', id=thread.id) return render(request, 'discuss/new.html', { 'breadcrumb': breadcrumb, 'form': form, })