Commit 11443d6a931a9629efb35fbc2e2f64d77dcbfc19

Authored by Gustavo
1 parent 57fef849

Modified create bulletin view to check if there's already a bulletin in the topic.

Showing 1 changed file with 12 additions and 6 deletions   Show diff stats
bulletin/views.py
... ... @@ -147,12 +147,18 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView):
147 147 slug = self.kwargs.get('slug', '')
148 148 topic = get_object_or_404(Topic, slug = slug)
149 149  
150   - existe = Goals.objects.filter(topic=topic).exists()
151   -
152   - if not existe:
153   - messages.error(request,_("The topic has no goals, so you can't create a Bulletin") )
154   - caminho = request.META['HTTP_REFERER']
155   - return redirect(caminho)
  150 + existe_meta = Goals.objects.filter(topic=topic).exists()
  151 + existe_boletim = Bulletin.objects.filter(topic=topic).exists()
  152 +
  153 + if not existe_meta:
  154 + messages.error(request,_("The topic %s has no goals, so you can't create a Bulletin.") %(topic) )
  155 + caminho1 = request.META['HTTP_REFERER']
  156 + return redirect(caminho1)
  157 +
  158 + if existe_boletim:
  159 + messages.error(request,_("The topic %s already has a Bulletin, so you can't create another.") %(topic) )
  160 + caminho2 = request.META['HTTP_REFERER']
  161 + return redirect(caminho2)
156 162  
157 163 if not has_subject_permissions(request.user, topic.subject):
158 164 return redirect(reverse_lazy('subjects:home'))
... ...