def create_topic(request, forum_id): id_forum = Forum.objects.get(id=forum_id) msg = [] if request.method == 'GET': form = TopicUEditorForm(initial={'content': u'测试'}) ctx = {'forum': id_forum, 'title': 'create_new_topic', 'form': form} if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('user:login')) return render(request, 'deepin/topic_create.html', ctx) if request.method == 'POST': topic = Topic() form = TopicUEditorForm(request.POST) if form.is_valid(): content = form.cleaned_data['Content'] name = form.cleaned_data['Name'] user = request.user topic.content = content topic.title = name topic.forum = id_forum topic.author = user topic.save() id_forum.topic_count += 1 id_forum.save() # if not topic.title: # msg.append('title cannot be empty') # return render(request, 'bbs/topic_create.html', {'msg': msg}) return HttpResponseRedirect( reverse('bb:forum_view', kwargs={'forum_id': forum_id}))
def create_topic(request, forum_id): id_forum = Forum.objects.get(id=forum_id) msg = [] if request.method == 'GET': form = TopicUEditorForm(initial={'content': u'测试'}) ctx = {'forum': id_forum, 'title': 'create_new_topic', 'form': form} if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('user:login')) return render(request, 'deepin/topic_create.html', ctx) if request.method == 'POST': topic = Topic() form = TopicUEditorForm(request.POST) if form.is_valid(): content = form.cleaned_data['Content'] name = form.cleaned_data['Name'] user = request.user topic.content = content topic.title = name topic.forum = id_forum topic.author = user topic.save() id_forum.topic_count += 1 id_forum.save() # if not topic.title: # msg.append('title cannot be empty') # return render(request, 'bbs/topic_create.html', {'msg': msg}) return HttpResponseRedirect(reverse('bb:forum_view', kwargs={'forum_id': forum_id}))
def edit_topic(request, topic_id): topic = Topic.objects.get(id=topic_id) if request.method == 'GET': form = TopicUEditorForm(initial={'Content': topic.content, 'Name': topic.title} ) ctx = { 'topic': topic, 'form': form, } return render(request, 'deepin/topic_edit.html', ctx) if request.method == 'POST': form = TopicUEditorForm(request.POST, request.FILES) if form.is_valid(): topic.title = form.cleaned_data['Name'] topic.content = form.cleaned_data['Content'] topic.forum = topic.forum topic.updated = time_zone_now() topic.save() return HttpResponseRedirect(reverse('bb:topic_view', kwargs={'pk': topic.pk}))
def edit_topic(request, topic_id): topic = Topic.objects.get(id=topic_id) if request.method == 'GET': form = TopicUEditorForm(initial={ 'Content': topic.content, 'Name': topic.title }) ctx = { 'topic': topic, 'form': form, } return render(request, 'deepin/topic_edit.html', ctx) if request.method == 'POST': form = TopicUEditorForm(request.POST, request.FILES) if form.is_valid(): topic.title = form.cleaned_data['Name'] topic.content = form.cleaned_data['Content'] topic.forum = topic.forum topic.updated = time_zone_now() topic.save() return HttpResponseRedirect( reverse('bb:topic_view', kwargs={'pk': topic.pk}))