From 11443d6a931a9629efb35fbc2e2f64d77dcbfc19 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 27 Jul 2017 20:37:33 -0300 Subject: [PATCH] Modified create bulletin view to check if there's already a bulletin in the topic. --- bulletin/views.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bulletin/views.py b/bulletin/views.py index 835574f..cf5ea04 100644 --- a/bulletin/views.py +++ b/bulletin/views.py @@ -147,12 +147,18 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): slug = self.kwargs.get('slug', '') topic = get_object_or_404(Topic, slug = slug) - existe = Goals.objects.filter(topic=topic).exists() - - if not existe: - messages.error(request,_("The topic has no goals, so you can't create a Bulletin") ) - caminho = request.META['HTTP_REFERER'] - return redirect(caminho) + existe_meta = Goals.objects.filter(topic=topic).exists() + existe_boletim = Bulletin.objects.filter(topic=topic).exists() + + if not existe_meta: + messages.error(request,_("The topic %s has no goals, so you can't create a Bulletin.") %(topic) ) + caminho1 = request.META['HTTP_REFERER'] + return redirect(caminho1) + + if existe_boletim: + messages.error(request,_("The topic %s already has a Bulletin, so you can't create another.") %(topic) ) + caminho2 = request.META['HTTP_REFERER'] + return redirect(caminho2) if not has_subject_permissions(request.user, topic.subject): return redirect(reverse_lazy('subjects:home')) -- libgit2 0.21.2