diff --git a/pendencies/forms.py b/pendencies/forms.py index 4791cba..5681664 100644 --- a/pendencies/forms.py +++ b/pendencies/forms.py @@ -13,12 +13,6 @@ class PendenciesForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(PendenciesForm, self).__init__(*args, **kwargs) - - if kwargs.get('initial'): - subject = kwargs['initial'].get('subject', None) - - if subject: - self.initial['subject'] = subject.id begin_date_check = forms.BooleanField(required = False) end_date_check = forms.BooleanField(required = False) @@ -30,12 +24,19 @@ class PendenciesForm(forms.ModelForm): def clean(self): cleaned_data = super(PendenciesForm, self).clean() + pend_id = cleaned_data.get('id', None) + + action = cleaned_data.get('action', None) begin_date = cleaned_data.get('begin_date', None) end_date = cleaned_data.get('end_date', None) begin_check = cleaned_data.get('begin_date_check', False) end_check = cleaned_data.get('end_date_check', False) subject_id = cleaned_data.get('subject', None) + if begin_check or end_check: + if not action: + self.add_error('action', _('This field is required.')) + if not begin_date and begin_check: self.add_error('begin_date', _('This field is required.')) @@ -52,7 +53,7 @@ class PendenciesForm(forms.ModelForm): subject = Subject.objects.get(id = subject_id) if not begin_date == ValueError and begin_date: - if begin_date.date() < datetime.datetime.today().date(): + if not pend_id and begin_date.date() < datetime.datetime.today().date(): self.add_error('begin_date', _("This input should be filled with a date equal or after today's date.")) if begin_date.date() < subject.init_date: @@ -62,7 +63,7 @@ class PendenciesForm(forms.ModelForm): self.add_error('begin_date', _('This input should be filled with a date equal or after the subject end date.')) if not end_date == ValueError and end_date: - if end_date.date() < datetime.datetime.today().date(): + if not pend_id and end_date.date() < datetime.datetime.today().date(): self.add_error('end_date', _("This input should be filled with a date equal or after today's date.")) if end_date.date() < subject.init_date: diff --git a/pendencies/migrations/0004_auto_20170124_0128.py b/pendencies/migrations/0004_auto_20170124_0128.py new file mode 100644 index 0000000..50bda4b --- /dev/null +++ b/pendencies/migrations/0004_auto_20170124_0128.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-01-24 04:28 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('pendencies', '0003_pendencies_limit_date'), + ] + + operations = [ + migrations.AlterField( + model_name='pendencies', + name='action', + field=models.CharField(blank=True, choices=[('view', 'Visualize'), ('create', 'Create'), ('answer', 'Answer'), ('access', 'Access')], max_length=100, verbose_name='Action'), + ), + ] diff --git a/pendencies/models.py b/pendencies/models.py index 0073fac..396f79d 100644 --- a/pendencies/models.py +++ b/pendencies/models.py @@ -5,7 +5,7 @@ from django.utils.translation import ugettext_lazy as _ from topics.models import Resource class Pendencies(models.Model): - action = models.CharField(_('Action'), max_length = 100, choices = (("view", _("Visualize")), ("create", _("Create")), ("answer", _("Answer")), ("access", _("Access")))) + action = models.CharField(_('Action'), max_length = 100, choices = (("view", _("Visualize")), ("create", _("Create")), ("answer", _("Answer")), ("access", _("Access"))), blank = True) begin_date = models.DateTimeField(_('Begin Date'), null = True, blank = True) end_date = models.DateTimeField(_('End Date'), null = True, blank = True) limit_date = models.DateTimeField(_('Limit Date'), null = True, blank = True) diff --git a/webpage/templates/webpages/_form.html b/webpage/templates/webpages/_form.html index 24a91b4..c053d8b 100644 --- a/webpage/templates/webpages/_form.html +++ b/webpage/templates/webpages/_form.html @@ -109,7 +109,10 @@
{% if notify.instance.pk %}{{ notify.DELETE }}{% endif %} - {% render_field notify.subject %} + {% render_field notify.id %} + {% render_field notify.resource %} + {% render_field notify.subject class='pend_subj' %} +
+
+ {{ notify.action.help_text }} {% if notify.action.errors %}