Commit 97fc3606d47b9124c64acd64430d198164d19ed8
1 parent
4cdc5327
Exists in
master
and in
2 other branches
Verification for bulletin creation and adjustments to properly display the infor…
…mations of the bulletin
Showing
1 changed file
with
24 additions
and
12 deletions
Show diff stats
bulletin/views.py
@@ -20,6 +20,7 @@ from topics.models import Topic | @@ -20,6 +20,7 @@ from topics.models import Topic | ||
20 | from django.conf import settings | 20 | from django.conf import settings |
21 | import os | 21 | import os |
22 | from os.path import join | 22 | from os.path import join |
23 | +from django.utils import timezone | ||
23 | 24 | ||
24 | from pendencies.forms import PendenciesForm | 25 | from pendencies.forms import PendenciesForm |
25 | 26 | ||
@@ -159,21 +160,24 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -159,21 +160,24 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
159 | meta_geral = Goals.objects.get(topic=topic) | 160 | meta_geral = Goals.objects.get(topic=topic) |
160 | metas = GoalItem.objects.filter(goal = meta_geral) | 161 | metas = GoalItem.objects.filter(goal = meta_geral) |
161 | metas_pessoais = [] | 162 | metas_pessoais = [] |
162 | - ''' | 163 | + n_submeteu = False |
163 | for m in metas: | 164 | for m in metas: |
164 | - if MyGoals.objects.filter(item = m).exists(): | ||
165 | - metas_pessoais.append(MyGoals.objects.get(item = m)) | ||
166 | - ''' | 165 | + if MyGoals.objects.filter(item = m, user = self.request.user).exists(): |
166 | + metas_pessoais.append(MyGoals.objects.get(item = m, user = self.request.user)) | ||
167 | + n_submeteu = False | ||
168 | + else: | ||
169 | + n_submeteu = True | ||
167 | 170 | ||
168 | itens_da_meta = sorted(list(metas), key = lambda met: met.id) | 171 | itens_da_meta = sorted(list(metas), key = lambda met: met.id) |
169 | metas_pessoais = sorted(list(metas_pessoais), key = lambda me: me.id) | 172 | metas_pessoais = sorted(list(metas_pessoais), key = lambda me: me.id) |
170 | lista_metas = [{'description':geral.description, 'desejada':geral.ref_value} for geral in itens_da_meta ] | 173 | lista_metas = [{'description':geral.description, 'desejada':geral.ref_value} for geral in itens_da_meta ] |
171 | - ''' | ||
172 | - for x in range(0,len(metas_pessoais)): | ||
173 | - lista_metas[x]['estabelecida'] = metas_pessoais[x].value | ||
174 | - print(metas_pessoais) | ||
175 | - print(lista_metas) | ||
176 | - ''' | 174 | + |
175 | + for x in range(len(lista_metas)): | ||
176 | + if n_submeteu: | ||
177 | + lista_metas[x]['estabelecida'] = lista_metas[x]['desejada'] | ||
178 | + else: | ||
179 | + lista_metas[x]['estabelecida'] = metas_pessoais[x].value | ||
180 | + | ||
177 | context['metas'] = lista_metas | 181 | context['metas'] = lista_metas |
178 | 182 | ||
179 | return context | 183 | return context |
@@ -202,10 +206,18 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | @@ -202,10 +206,18 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | ||
202 | caminho1 = request.META['HTTP_REFERER'] | 206 | caminho1 = request.META['HTTP_REFERER'] |
203 | return redirect(caminho1) | 207 | return redirect(caminho1) |
204 | 208 | ||
209 | + if existe_meta: | ||
210 | + meta_geral = Goals.objects.get(topic=topic) | ||
211 | + now = timezone.now() | ||
212 | + if meta_geral.limit_submission_date > now: | ||
213 | + messages.error(request,_("The deadline to submit the goals of the topic %s has not yet closed, so you can't create a Bulletin.") %(topic) ) | ||
214 | + caminho2 = request.META['HTTP_REFERER'] | ||
215 | + return redirect(caminho2) | ||
216 | + | ||
205 | if existe_boletim: | 217 | if existe_boletim: |
206 | messages.error(request,_("The topic %s already has a Bulletin, so you can't create another.") %(topic) ) | 218 | messages.error(request,_("The topic %s already has a Bulletin, so you can't create another.") %(topic) ) |
207 | - caminho2 = request.META['HTTP_REFERER'] | ||
208 | - return redirect(caminho2) | 219 | + caminho3 = request.META['HTTP_REFERER'] |
220 | + return redirect(caminho3) | ||
209 | 221 | ||
210 | if not has_subject_permissions(request.user, topic.subject): | 222 | if not has_subject_permissions(request.user, topic.subject): |
211 | return redirect(reverse_lazy('subjects:home')) | 223 | return redirect(reverse_lazy('subjects:home')) |