Exemplo n.º 1
0
class PlanScenarioForm(forms.Form):
    messagestarttime = forms.DateTimeField(label=_("Begin"), initial=now)
    messageendtime = forms.DateTimeField(label=_("Einde"),
                                         initial=get_end_service)

    def clean(self):
        data = super(PlanScenarioForm, self).clean()
        if 'messagestarttime' not in data and 'messageendtime' not in data:
            raise ValidationError(_("Voer een geldige begin- en eindtijd in"))

        if 'messagestarttime' not in data:
            raise ValidationError(_("Voer een geldige begintijd in"))

        if 'messageendtime' not in data:
            raise ValidationError(_("Voer een geldige eindtijd in"))

        if data['messageendtime'] <= data['messagestarttime']:
            raise ValidationError(_("Einde bericht moet na begin zijn"))
        return data

    def __init__(self, *args, **kwargs):
        super(PlanScenarioForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = 'scenario_plan'
        self.helper.layout = Layout(
            # Put in two columns
            Div(Div(Field('messagestarttime'), css_class="col-sm-6 col-lg-6"),
                Div(Field('messageendtime'), css_class="col-sm-6 col-lg-6"),
                css_class="row"),
            Submit('submit', _("Plan alle berichten in")))
Exemplo n.º 2
0
class MessageSearchForm(forms.Form):
    """ Formulaire de recherche de messages """

    query = forms.CharField(max_length=128, required=False)
    ip = forms.GenericIPAddressField(required=False)
    q = forms.CharField(max_length=48, required=False)
    when = forms.DateTimeField(widget=SelectDateWidget(
        years=range(2010, 2012)))
Exemplo n.º 3
0
class TaskFetchForm(forms.Form):
    task = forms.ModelChoiceField(queryset=Task.objects.filter(parent=None),
                                  empty_label=None)

    open = forms.DateTimeField(initial=now)
    deadline = forms.DateTimeField(initial=(lambda: now() + timedelta(days=7)))
    close = forms.DateTimeField(initial=(lambda: now() + timedelta(days=14)))

    def clean(self):
        cleaned_data = super(TaskFetchForm, self).clean()

        date_open = cleaned_data.get('open')
        date_deadline = cleaned_data.get('deadline')
        date_close = cleaned_data.get('close')

        if not date_open < date_deadline < date_close:
            raise forms.ValidationError('Dates must be in order: open < ' +
                                        'deadline < close.')
Exemplo n.º 4
0
 class SampleForm(DjangoForm):
     datetime_field = forms.DateTimeField()
Exemplo n.º 5
0
 class SampleForm(forms.Form):
     datetime_field = forms.DateTimeField()
Exemplo n.º 6
0
 def test_parse_datetime(self):
     field = forms.DateTimeField()
     result = field.clean('2000-01-01')
     self.assertEqual(result, datetime(2000, 1, 1))