def test_topic_delete_form(self): form = TopicDeleteForm(topic=self.topic, data={ 'topic': self.topic.pk, 'confirm': True }) self.assertTrue(form.is_valid()) form.save() self.assertTrue(self.topic.deleted)
def topic_delete(request, pk): topic = get_object_or_404(Topic, pk=pk) if not request.user.is_superuser: messages.error(request, _("You're not allowed to delete topic")) return reverse('pybb:home_page') if request.method == 'POST': form = TopicDeleteForm(request.POST) else: form = TopicDeleteForm() if form.is_valid(): topic.delete() messages.success(request, _('Topic deleted')) return redirect('pybb:home_page') context = {'topic': topic, 'form': form, } return render(request, 'pybb/topic_delete.html', context)
def topic_delete(request, pk): topic = get_object_or_404(Topic, pk=pk) if not request.user.is_superuser: messages.error(request, u'У вас нет права на удаление темы') return reverse('pybb:home_page') if request.method == 'POST': form = TopicDeleteForm(request.POST) else: form = TopicDeleteForm() if form.is_valid(): topic.delete() messages.success(request, u'Тема удалена') return redirect('pybb:home_page') context = {'topic': topic, 'form': form, } return render(request, 'pybb/topic_delete.html', context)
def topic_delete(request, pk): topic = get_object_or_404(Topic, pk=pk) if not request.user.is_superuser: messages.error(request, u'У вас нет права на удаление темы') return reverse('pybb:home_page') if request.method == 'POST': form = TopicDeleteForm(request.POST) else: form = TopicDeleteForm() if form.is_valid(): topic.delete() messages.success(request, u'Тема удалена') return redirect('pybb:home_page') context = { 'topic': topic, 'form': form, } return render(request, 'pybb/topic_delete.html', context)