Commit 7e97da39a1daa5a1005a07f410f77f4b8e486835
1 parent
d0dd81e0
Exists in
master
and in
3 other branches
Adjusts in create goal and added update goal (not 100% finished)
Showing
13 changed files
with
267 additions
and
50 deletions
Show diff stats
amadeus/settings.py
... | ... | @@ -172,7 +172,7 @@ USE_L10N = True |
172 | 172 | |
173 | 173 | USE_TZ = True |
174 | 174 | |
175 | - | |
175 | +FORMAT_MODULE_PATH = 'amadeus.formats' | |
176 | 176 | # Static files (CSS, JavaScript, Images) |
177 | 177 | # https://docs.djangoproject.com/en/1.9/howto/static-files/ |
178 | 178 | |
... | ... | @@ -269,10 +269,6 @@ OAUTH2_PROVIDER = { |
269 | 269 | |
270 | 270 | |
271 | 271 | #For date purposes |
272 | -DATETIME_INPUT_FORMATS.append('%d/%m/%y') | |
273 | -DATETIME_INPUT_FORMATS.append('%m/%d/%y') | |
274 | -DATETIME_INPUT_FORMATS.append('%m/%d/%Y %I:%M %p') | |
275 | -DATETIME_INPUT_FORMATS.append('%d/%m/%Y %H:%M') | |
276 | 272 | DATE_INPUT_FORMATS.append('%d/%m/%y') |
277 | 273 | DATE_INPUT_FORMATS.append('%m/%d/%y') |
278 | 274 | ... | ... |
goals/forms.py
1 | 1 | # coding=utf-8 |
2 | 2 | from django import forms |
3 | +from datetime import datetime | |
3 | 4 | from django.conf import settings |
4 | 5 | from django.utils.translation import ugettext_lazy as _ |
5 | 6 | from django.forms.models import inlineformset_factory |
... | ... | @@ -13,21 +14,23 @@ from .models import Goals, GoalItem |
13 | 14 | |
14 | 15 | class GoalsForm(forms.ModelForm): |
15 | 16 | subject = None |
17 | + topic = None | |
16 | 18 | control_subject = forms.CharField(widget = forms.HiddenInput()) |
17 | 19 | |
18 | 20 | def __init__(self, *args, **kwargs): |
19 | 21 | super(GoalsForm, self).__init__(*args, **kwargs) |
20 | 22 | |
21 | 23 | self.subject = kwargs['initial'].get('subject', None) |
24 | + self.topic = kwargs['initial'].get('topic', None) | |
22 | 25 | |
23 | 26 | if self.instance.id: |
24 | 27 | self.subject = self.instance.topic.subject |
28 | + self.topic = self.instance.topic | |
25 | 29 | self.initial['tags'] = ", ".join(self.instance.tags.all().values_list("name", flat = True)) |
26 | 30 | |
27 | 31 | self.initial['control_subject'] = self.subject.id |
28 | 32 | |
29 | 33 | tags = forms.CharField(label = _('Tags'), required = False) |
30 | - #limit_submission_date = forms.DateTimeField(input_formats = settings.DATETIME_INPUT_FORMATS) | |
31 | 34 | |
32 | 35 | class Meta: |
33 | 36 | model = Goals |
... | ... | @@ -43,16 +46,27 @@ class GoalsForm(forms.ModelForm): |
43 | 46 | def clean(self): |
44 | 47 | cleaned_data = super(GoalsForm, self).clean() |
45 | 48 | |
46 | - topic = cleaned_data.get('topic', None) | |
49 | + limit_submission_date = cleaned_data.get('limit_submission_date', None) | |
47 | 50 | |
48 | - if topic: | |
51 | + if self.topic: | |
49 | 52 | if self.instance.id: |
50 | - exist = topic.resource_topic.filter(goals__isnull = False).exclude(id = self.instance.id).exists() | |
53 | + exist = self.topic.resource_topic.filter(goals__isnull = False).exclude(id = self.instance.id).exists() | |
51 | 54 | else: |
52 | - exist = topic.resource_topic.filter(goals__isnull = False).exists() | |
55 | + exist = self.topic.resource_topic.filter(goals__isnull = False).exists() | |
53 | 56 | |
54 | 57 | if exist: |
55 | - self.add_error('name', _('There already is another resource with the goals specification for the Topic %s')%(str(topic))) | |
58 | + self.add_error('name', _('There already is another resource with the goals specification for the Topic %s')%(str(self.topic))) | |
59 | + | |
60 | + if limit_submission_date: | |
61 | + if not limit_submission_date == ValueError: | |
62 | + if not self.instance.id and limit_submission_date.date() < datetime.today().date(): | |
63 | + self.add_error('limit_submission_date', _("This input should be filled with a date equal or after today's date.")) | |
64 | + | |
65 | + if limit_submission_date.date() < self.subject.init_date: | |
66 | + self.add_error('limit_submission_date', _('This input should be filled with a date equal or after the subject begin date.')) | |
67 | + | |
68 | + if limit_submission_date.date() > self.subject.end_date: | |
69 | + self.add_error('limit_submission_date', _('This input should be filled with a date equal or after the subject end date.')) | |
56 | 70 | |
57 | 71 | return cleaned_data |
58 | 72 | |
... | ... | @@ -90,5 +104,18 @@ class GoalItemForm(forms.ModelForm): |
90 | 104 | model = GoalItem |
91 | 105 | fields = ['description', 'ref_value'] |
92 | 106 | |
107 | + def clean(self): | |
108 | + cleaned_data = super(GoalItemForm, self).clean() | |
109 | + | |
110 | + description = cleaned_data.get('description', None) | |
111 | + ref_value = cleaned_data.get('ref_value', None) | |
112 | + | |
113 | + if ref_value and ref_value != "0": | |
114 | + if not description: | |
115 | + self.add_error('description', _('This field is required.')) | |
116 | + | |
117 | + return cleaned_data | |
118 | + | |
119 | + | |
93 | 120 | InlinePendenciesFormset = inlineformset_factory(Goals, Pendencies, form = PendenciesLimitedForm, extra = 1, max_num = 3, validate_max = True, can_delete = True) |
94 | 121 | InlineGoalItemFormset = inlineformset_factory(Goals, GoalItem, form = GoalItemForm, extra = 1, can_delete = True) |
95 | 122 | \ No newline at end of file | ... | ... |
goals/models.py
... | ... | @@ -20,7 +20,7 @@ class Goals(Resource): |
20 | 20 | return reverse_lazy('file_links:download', args = (), kwargs = {'slug': self.slug}) |
21 | 21 | |
22 | 22 | def update_link(self): |
23 | - return 'file_links:update' | |
23 | + return 'goals:update' | |
24 | 24 | |
25 | 25 | def delete_link(self): |
26 | 26 | return 'file_links:delete' |
... | ... | @@ -29,7 +29,7 @@ class Goals(Resource): |
29 | 29 | return _('Are you sure you want delete the goals') |
30 | 30 | |
31 | 31 | class GoalItem(models.Model): |
32 | - description = models.CharField(_('Description'), max_length = 255) | |
32 | + description = models.CharField(_('Description'), max_length = 255, blank = True) | |
33 | 33 | ref_value = models.IntegerField(_('Referential Value')) |
34 | 34 | order = models.PositiveSmallIntegerField(_('Order'), null = True) |
35 | 35 | goal = models.ForeignKey(Goals, verbose_name = _('Goal'), related_name = 'item_goal') |
36 | 36 | \ No newline at end of file | ... | ... |
goals/templates/goals/_form.html
... | ... | @@ -102,7 +102,9 @@ |
102 | 102 | </label> |
103 | 103 | <div class="col-md-9"> |
104 | 104 | <span class="label">0%</span> |
105 | - {% render_field item.ref_value class='slider_value' data-slider-min="0" data-slider-max="100" %} | |
105 | + {% with item.ref_value.value|default:"0" as item_value %} | |
106 | + {% render_field item.ref_value class='slider_value' data-slider-value=item_value data-slider-min="0" data-slider-max="100" %} | |
107 | + {% endwith %} | |
106 | 108 | <span class="label">100%</span> |
107 | 109 | </div> |
108 | 110 | |
... | ... | @@ -192,7 +194,7 @@ |
192 | 194 | </div> |
193 | 195 | {% endif %} |
194 | 196 | </div> |
195 | - | |
197 | + | |
196 | 198 | <div class="panel panel-info"> |
197 | 199 | <div class="panel-heading"> |
198 | 200 | <div class="row"> |
... | ... | @@ -212,6 +214,7 @@ |
212 | 214 | {% for notify in pendencies_form %} |
213 | 215 | <div class="notifies"> |
214 | 216 | <div style="text-align:left"> |
217 | + {{ notify.errors }} | |
215 | 218 | {% render_field notify.id %} |
216 | 219 | {% render_field notify.resource %} |
217 | 220 | {% render_field notify.subject class='pend_subj' %} |
... | ... | @@ -390,7 +393,6 @@ |
390 | 393 | $(function() { |
391 | 394 | $(".slider_value").bootstrapSlider({ |
392 | 395 | tooltip: 'always', |
393 | - value: '0' | |
394 | 396 | }); |
395 | 397 | |
396 | 398 | $('.goalitems').formset({ |
... | ... | @@ -477,6 +479,10 @@ |
477 | 479 | {% if not pendencies_form.is_valid and pendencies_form.is_bound %} |
478 | 480 | $("#notifications").collapse('toggle'); |
479 | 481 | {% endif %} |
482 | + | |
483 | + {% if not goalitems_form.is_valid and goalitems_form.is_bound %} | |
484 | + $("#goal_items").collapse('toggle'); | |
485 | + {% endif %} | |
480 | 486 | }); |
481 | 487 | </script> |
482 | 488 | <script type="text/javascript" src="{% static 'js/resources.js' %}"></script> |
483 | 489 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +{% extends 'subjects/view.html' %} | |
2 | + | |
3 | +{% load static i18n django_bootstrap_breadcrumbs %} | |
4 | + | |
5 | +{% block style %} | |
6 | + {{block.super}} | |
7 | + <link rel="stylesheet" type="text/css" href="{% static "css/bootstrap-tagsinput.css" %}"> | |
8 | + <link rel="stylesheet" type="text/css" href="{% static "css/bootstrap-slider.css" %}"> | |
9 | +{% endblock %} | |
10 | + | |
11 | +{% block javascript %} | |
12 | + {{block.super}} | |
13 | + <script type="text/javascript" src="{% static "js/bootstrap-tagsinput.js" %} "></script> | |
14 | + <script type="text/javascript" src="{% static "js/bootstrap-slider.js" %} "></script> | |
15 | + <script type="text/javascript" src="{% static "js/jquery.formset.js" %} "></script> | |
16 | +{% endblock %} | |
17 | + | |
18 | +{% block breadcrumbs %} | |
19 | + {{ block.super }} | |
20 | + | |
21 | + {% breadcrumb topic 'subjects:topic_view' topic.subject.slug topic.slug %} | |
22 | + | |
23 | + {% trans 'Edit: Topic Goals ' as bread %} | |
24 | + {% breadcrumb bread 'goals:update' topic.slug goal.slug %} | |
25 | +{% endblock %} | |
26 | + | |
27 | +{% block content %} | |
28 | + <div class="card"> | |
29 | + <div class="card-content"> | |
30 | + <div class="card-body"> | |
31 | + {% include 'goals/_form.html' %} | |
32 | + </div> | |
33 | + </div> | |
34 | + </div> | |
35 | + <br clear="all" /> | |
36 | + <br clear="all" /> | |
37 | +{% endblock %} | ... | ... |
goals/urls.py
goals/views.py
... | ... | @@ -90,7 +90,7 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
90 | 90 | if not self.object.topic.visible and not self.object.topic.repository: |
91 | 91 | self.object.visible = False |
92 | 92 | |
93 | - #self.object.save() | |
93 | + self.object.save() | |
94 | 94 | |
95 | 95 | pendencies_form.instance = self.object |
96 | 96 | pendencies_form.save(commit = False) |
... | ... | @@ -98,11 +98,22 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
98 | 98 | for pform in pendencies_form.forms: |
99 | 99 | pend_form = pform.save(commit = False) |
100 | 100 | |
101 | - #if not pend_form.action == "": | |
102 | - #pend_form.save() | |
101 | + if not pend_form.action == "": | |
102 | + pend_form.save() | |
103 | 103 | |
104 | 104 | goalitems_form.instance = self.object |
105 | 105 | goalitems_form.save(commit = False) |
106 | + | |
107 | + g_order = 1 | |
108 | + | |
109 | + for gform in goalitems_form.forms: | |
110 | + goal_form = gform.save(commit = False) | |
111 | + | |
112 | + if not goal_form.description == "": | |
113 | + goal_form.order = g_order | |
114 | + goal_form.save() | |
115 | + | |
116 | + g_order += 1 | |
106 | 117 | |
107 | 118 | return redirect(self.get_success_url()) |
108 | 119 | |
... | ... | @@ -131,4 +142,119 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
131 | 142 | |
132 | 143 | success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) |
133 | 144 | |
145 | + return success_url | |
146 | + | |
147 | +class UpdateView(LoginRequiredMixin, generic.UpdateView): | |
148 | + login_url = reverse_lazy("users:login") | |
149 | + redirect_field_name = 'next' | |
150 | + | |
151 | + template_name = 'goals/update.html' | |
152 | + model = Goals | |
153 | + form_class = GoalsForm | |
154 | + context_object_name = 'goal' | |
155 | + | |
156 | + def dispatch(self, request, *args, **kwargs): | |
157 | + slug = self.kwargs.get('topic_slug', '') | |
158 | + topic = get_object_or_404(Topic, slug = slug) | |
159 | + | |
160 | + if not has_subject_permissions(request.user, topic.subject): | |
161 | + return redirect(reverse_lazy('subjects:home')) | |
162 | + | |
163 | + return super(UpdateView, self).dispatch(request, *args, **kwargs) | |
164 | + | |
165 | + def get(self, request, *args, **kwargs): | |
166 | + self.object = self.get_object() | |
167 | + | |
168 | + form_class = self.get_form_class() | |
169 | + form = self.get_form(form_class) | |
170 | + | |
171 | + slug = self.kwargs.get('topic_slug', '') | |
172 | + topic = get_object_or_404(Topic, slug = slug) | |
173 | + | |
174 | + pendencies_form = InlinePendenciesFormset(instance = self.object, initial = [{'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize")), ("submit", _("Submit"))]}]) | |
175 | + goalitems_form = InlineGoalItemFormset(instance = self.object) | |
176 | + | |
177 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form, goalitems_form = goalitems_form)) | |
178 | + | |
179 | + def post(self, request, *args, **kwargs): | |
180 | + self.object = self.get_object() | |
181 | + | |
182 | + form_class = self.get_form_class() | |
183 | + form = self.get_form(form_class) | |
184 | + | |
185 | + slug = self.kwargs.get('topic_slug', '') | |
186 | + topic = get_object_or_404(Topic, slug = slug) | |
187 | + | |
188 | + pendencies_form = InlinePendenciesFormset(self.request.POST, instance = self.object, initial = [{'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize")), ("submit", _("Submit"))]}]) | |
189 | + goalitems_form = InlineGoalItemFormset(self.request.POST, instance = self.object) | |
190 | + | |
191 | + if (form.is_valid() and pendencies_form.is_valid() and goalitems_form.is_valid()): | |
192 | + return self.form_valid(form, pendencies_form, goalitems_form) | |
193 | + else: | |
194 | + return self.form_invalid(form, pendencies_form, goalitems_form) | |
195 | + | |
196 | + def form_invalid(self, form, pendencies_form, goalitems_form): | |
197 | + for p_form in pendencies_form.forms: | |
198 | + p_form.fields['action'].choices = [("", "-------"),("view", _("Visualize")), ("submit", _("Submit"))] | |
199 | + | |
200 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form, goalitems_form = goalitems_form)) | |
201 | + | |
202 | + def form_valid(self, form, pendencies_form, goalitems_form): | |
203 | + self.object = form.save(commit = False) | |
204 | + | |
205 | + if not self.object.topic.visible and not self.object.topic.repository: | |
206 | + self.object.visible = False | |
207 | + | |
208 | + self.object.save() | |
209 | + | |
210 | + pendencies_form.instance = self.object | |
211 | + pendencies_form.save(commit = False) | |
212 | + | |
213 | + for form in pendencies_form.forms: | |
214 | + pend_form = form.save(commit = False) | |
215 | + | |
216 | + if not pend_form.action == "": | |
217 | + pend_form.save() | |
218 | + | |
219 | + goalitems_form.instance = self.object | |
220 | + goalitems_form.save(commit = False) | |
221 | + | |
222 | + g_order = self.object.item_goal.count() + 1 | |
223 | + | |
224 | + for gform in goalitems_form.forms: | |
225 | + goal_form = gform.save(commit = False) | |
226 | + | |
227 | + if not goal_form.description == "": | |
228 | + goal_form.order = g_order | |
229 | + goal_form.save() | |
230 | + | |
231 | + g_order += 1 | |
232 | + | |
233 | + return redirect(self.get_success_url()) | |
234 | + | |
235 | + def get_context_data(self, **kwargs): | |
236 | + context = super(UpdateView, self).get_context_data(**kwargs) | |
237 | + | |
238 | + context['title'] = _('Update Topic Goals') | |
239 | + | |
240 | + slug = self.kwargs.get('topic_slug', '') | |
241 | + topic = get_object_or_404(Topic, slug = slug) | |
242 | + | |
243 | + context['topic'] = topic | |
244 | + context['subject'] = topic.subject | |
245 | + | |
246 | + return context | |
247 | + | |
248 | + def get_success_url(self): | |
249 | + messages.success(self.request, _('The YouTube Video "%s" was updated successfully!')%(self.object.name)) | |
250 | + | |
251 | + #success_url = reverse_lazy('youtube:view', kwargs = {'slug': self.object.slug}) | |
252 | + | |
253 | + #if self.object.show_window: | |
254 | + # self.request.session['resources'] = {} | |
255 | + # self.request.session['resources']['new_page'] = True | |
256 | + # self.request.session['resources']['new_page_url'] = reverse('youtube:window_view', kwargs = {'slug': self.object.slug}) | |
257 | + | |
258 | + success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
259 | + | |
134 | 260 | return success_url |
135 | 261 | \ No newline at end of file | ... | ... |
pendencies/forms.py
... | ... | @@ -4,6 +4,8 @@ import datetime |
4 | 4 | from django import forms |
5 | 5 | from django.conf import settings |
6 | 6 | from django.utils.translation import ugettext_lazy as _ |
7 | +from django.utils.formats import get_format | |
8 | +from django.utils import timezone | |
7 | 9 | |
8 | 10 | from subjects.models import Subject |
9 | 11 | |
... | ... | @@ -18,8 +20,10 @@ class PendenciesForm(forms.ModelForm): |
18 | 20 | if kwargs.get('initial', None): |
19 | 21 | self.fields['action'].choices = kwargs['initial'].get('actions', []) |
20 | 22 | |
21 | - self.fields['begin_date'].input_formats = settings.DATETIME_INPUT_FORMATS | |
22 | - self.fields['end_date'].input_formats = settings.DATETIME_INPUT_FORMATS | |
23 | + datetime_formats = get_format('DATETIME_INPUT_FORMATS') | |
24 | + | |
25 | + self.fields['begin_date'].input_formats = datetime_formats | |
26 | + self.fields['end_date'].input_formats = datetime_formats | |
23 | 27 | |
24 | 28 | begin_date_check = forms.BooleanField(required = False) |
25 | 29 | end_date_check = forms.BooleanField(required = False) |
... | ... | @@ -89,21 +93,23 @@ class PendenciesLimitedForm(forms.ModelForm): |
89 | 93 | |
90 | 94 | if kwargs.get('initial', None): |
91 | 95 | self.fields['action'].choices = kwargs['initial'].get('actions', []) |
96 | + | |
97 | + datetime_formats = get_format('DATETIME_INPUT_FORMATS') | |
98 | + | |
99 | + self.fields['begin_date'].input_formats = datetime_formats | |
100 | + self.fields['end_date'].input_formats = datetime_formats | |
101 | + self.fields['limit_date'].input_formats = datetime_formats | |
92 | 102 | |
93 | 103 | begin_date_check = forms.BooleanField(required = False) |
94 | 104 | end_date_check = forms.BooleanField(required = False) |
95 | 105 | limit_date_check = forms.BooleanField(required = False) |
96 | - begin_date = forms.DateTimeField(input_formats = settings.DATETIME_INPUT_FORMATS) | |
97 | - end_date = forms.DateTimeField(input_formats = settings.DATETIME_INPUT_FORMATS) | |
98 | - limit_date = forms.DateTimeField(input_formats = settings.DATETIME_INPUT_FORMATS) | |
99 | - | |
106 | + | |
100 | 107 | class Meta: |
101 | 108 | model = Pendencies |
102 | - fields = ['action'] | |
109 | + fields = ['action', 'begin_date', 'end_date', 'limit_date'] | |
103 | 110 | |
104 | 111 | def clean(self): |
105 | 112 | cleaned_data = super(PendenciesLimitedForm, self).clean() |
106 | - print(self.data) | |
107 | 113 | |
108 | 114 | pend_id = cleaned_data.get('id', None) |
109 | 115 | |
... | ... | @@ -111,14 +117,12 @@ class PendenciesLimitedForm(forms.ModelForm): |
111 | 117 | action = cleaned_data.get('action', None) |
112 | 118 | begin_date = cleaned_data.get('begin_date', None) |
113 | 119 | end_date = cleaned_data.get('end_date', None) |
114 | - #limit_date = cleaned_data.get('limit_date', None) | |
120 | + limit_date = cleaned_data.get('limit_date', None) | |
115 | 121 | begin_check = cleaned_data.get('begin_date_check', False) |
116 | 122 | end_check = cleaned_data.get('end_date_check', False) |
117 | - #limit_check = cleaned_data.get('limit_date_check', False) | |
123 | + limit_check = cleaned_data.get('limit_date_check', False) | |
118 | 124 | subject_id = cleaned_data.get('subject', None) |
119 | 125 | |
120 | - print(limit_submission_date) | |
121 | - | |
122 | 126 | if begin_check or end_check or limit_date: |
123 | 127 | if not action: |
124 | 128 | self.add_error('action', _('This field is required.')) |
... | ... | @@ -129,8 +133,8 @@ class PendenciesLimitedForm(forms.ModelForm): |
129 | 133 | if not end_date and end_check: |
130 | 134 | self.add_error('end_date', _('This field is required.')) |
131 | 135 | |
132 | - #if not limit_date and limit_check: | |
133 | - # self.add_error('limit_date', _('This field is required.')) | |
136 | + if not limit_date and limit_check: | |
137 | + self.add_error('limit_date', _('This field is required.')) | |
134 | 138 | |
135 | 139 | if begin_date and end_date: |
136 | 140 | if not begin_date == ValueError and not end_date == ValueError: |
... | ... | @@ -138,17 +142,17 @@ class PendenciesLimitedForm(forms.ModelForm): |
138 | 142 | self.add_error('begin_date', _('This input should be filled with a date equal or before the End Date.')) |
139 | 143 | self.add_error('end_date', _('This input should be filled with a date equal or after the Begin Date.')) |
140 | 144 | |
141 | - #if begin_date and limit_date: | |
142 | - # if not begin_date == ValueError and not limit_date == ValueError: | |
143 | - # if begin_date > limit_date: | |
144 | - # self.add_error('begin_date', _('This input should be filled with a date equal or before the Limit Date.')) | |
145 | - # self.add_error('limit_date', _('This input should be filled with a date equal or after the Begin Date.')) | |
145 | + if begin_date and limit_date: | |
146 | + if not begin_date == ValueError and not limit_date == ValueError: | |
147 | + if begin_date > limit_date: | |
148 | + self.add_error('begin_date', _('This input should be filled with a date equal or before the Limit Date.')) | |
149 | + self.add_error('limit_date', _('This input should be filled with a date equal or after the Begin Date.')) | |
146 | 150 | |
147 | - #if end_date and limit_date: | |
148 | - # if not end_date == ValueError and not limit_date == ValueError: | |
149 | - # if end_date > limit_date: | |
150 | - # self.add_error('end_date', _('This input should be filled with a date equal or before the Limit Date.')) | |
151 | - # self.add_error('limit_date', _('This input should be filled with a date equal or after the End Date.')) | |
151 | + if end_date and limit_date: | |
152 | + if not end_date == ValueError and not limit_date == ValueError: | |
153 | + if end_date > limit_date: | |
154 | + self.add_error('end_date', _('This input should be filled with a date equal or before the Limit Date.')) | |
155 | + self.add_error('limit_date', _('This input should be filled with a date equal or after the End Date.')) | |
152 | 156 | |
153 | 157 | if subject_id: |
154 | 158 | subject = Subject.objects.get(id = subject_id) |
... | ... | @@ -173,14 +177,30 @@ class PendenciesLimitedForm(forms.ModelForm): |
173 | 177 | if end_date.date() > subject.end_date: |
174 | 178 | self.add_error('end_date', _('This input should be filled with a date equal or before the subject end date.')) |
175 | 179 | |
176 | - #if not limit_date == ValueError and limit_date: | |
177 | - # if not self.instance.id and limit_date.date() < datetime.datetime.today().date(): | |
178 | - # self.add_error('limit_date', _("This input should be filled with a date equal or after today's date.")) | |
180 | + if not limit_date == ValueError and limit_date: | |
181 | + if not self.instance.id and limit_date.date() < datetime.datetime.today().date(): | |
182 | + self.add_error('limit_date', _("This input should be filled with a date equal or after today's date.")) | |
179 | 183 | |
180 | - # if limit_date.date() < subject.init_date: | |
181 | - # self.add_error('limit_date', _('This input should be filled with a date equal or after the subject begin date.')) | |
184 | + if limit_date.date() < subject.init_date: | |
185 | + self.add_error('limit_date', _('This input should be filled with a date equal or after the subject begin date.')) | |
186 | + | |
187 | + if limit_date.date() > subject.end_date: | |
188 | + self.add_error('limit_date', _('This input should be filled with a date equal or before the subject end date.')) | |
189 | + | |
190 | + if limit_submission_date: | |
191 | + limit_submission_date = datetime.datetime.strptime(limit_submission_date, get_format('DATETIME_FORMAT')) | |
192 | + limit_submission_date = timezone.make_aware(limit_submission_date, timezone.get_current_timezone()) | |
193 | + | |
194 | + if not begin_date == ValueError and begin_date: | |
195 | + if begin_date > limit_submission_date: | |
196 | + self.add_error('begin_date', _('This input should be filled with a date equal or before the goals submission limit date.')) | |
197 | + | |
198 | + if not end_date == ValueError and end_date: | |
199 | + if end_date > limit_submission_date: | |
200 | + self.add_error('end_date', _('This input should be filled with a date equal or before the goals submission limit date.')) | |
182 | 201 | |
183 | - # if limit_date.date() > subject.end_date: | |
184 | - # self.add_error('limit_date', _('This input should be filled with a date equal or before the subject end date.')) | |
202 | + if not limit_date == ValueError and limit_date: | |
203 | + if limit_date > limit_submission_date: | |
204 | + self.add_error('limit_date', _('This input should be filled with a date equal or before the goals submission limit date.')) | |
185 | 205 | |
186 | 206 | return cleaned_data | ... | ... |