Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     super(ReminderForm, self).__init__(*args, **kwargs)
     deadline_month = ChoiceField(
         choices=(tuple([(n, convert_to_ordinal(n)) for n in range(1, 31)] +
                        [(31, ugettext_lazy('Last Day'))])),
         widget=forms.Select,
         required=False)
     self.fields["deadline_month"] = deadline_month
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        data = kwargs.get("data")
        if data is not None:
            deadline_type = data.get('deadline_type')
            data.update({
                "deadline_type_week": deadline_type,
                "deadline_type_month": deadline_type
            })
            kwargs.update({"data": data})

        super(ReminderForm, self).__init__(*args, **kwargs)
        deadline_month = ChoiceField(choices=(tuple([(n, convert_to_ordinal(n))
                                                     for n in range(1, 8)])),
                                     widget=forms.Select,
                                     required=False)
        self.fields["deadline_month"] = deadline_month
Ejemplo n.º 3
0
 def description(self, mode):
     if mode == 'Following':
         return convert_to_ordinal(self.day) + ' of the ' + mode + ' Month'
     return convert_to_ordinal(self.day) + ' of the Month'
Ejemplo n.º 4
0
class ReminderForm(Form):
    frequency_period = ChoiceField(
        choices=(('week', _('Week')), ('month', _('Month'))),
        widget=forms.Select,
        required=False,
    )
    deadline_month = ChoiceField(
        choices=(tuple([(n, convert_to_ordinal(n)) for n in range(1, 31)] +
                       [(31, ugettext_lazy('Last Day'))])),
        widget=forms.Select,
        required=False)
    deadline_week = ChoiceField(
        choices=(get_translated_weekdays()),
        widget=forms.Select(attrs={'data-bind': 'random'}),
        required=False)
    deadline_type_week = ChoiceField(
        choices=(('Same', _('Same week')), ('Following', _('Following week'))),
        widget=forms.Select(attrs={'class': 'deadline_type'}),
        required=False)

    deadline_type_month = ChoiceField(
        choices=(('Same', _('Same month')), ('Following',
                                             _('Following month'))),
        widget=forms.Select(attrs={'class': 'deadline_type'}),
        required=False)

    deadline_type = ChoiceField(choices=(('Same', _('Same')),
                                         ('Following', _('Following'))),
                                widget=forms.Select,
                                required=False)

    should_send_reminders_before_deadline = BooleanField(required=False,
                                                         initial=False)
    number_of_days_before_deadline = DecimalField(
        label=ugettext_lazy("days before deadline"), required=False)
    reminder_text_before_deadline = CharField(widget=forms.Textarea,
                                              required=False,
                                              label=ugettext_lazy("SMS Text"))

    should_send_reminders_on_deadline = BooleanField(
        label=ugettext_lazy("The day of the deadline"),
        required=False,
        initial=False)
    reminder_text_on_deadline = CharField(widget=forms.Textarea,
                                          required=False,
                                          label=ugettext_lazy("SMS Text"))

    should_send_reminders_after_deadline = BooleanField(
        label=ugettext_lazy("days after the deadline"),
        required=False,
        initial=False)
    number_of_days_after_deadline = DecimalField(
        required=False, label=ugettext_lazy("number of days after deadline"))
    reminder_text_after_deadline = CharField(widget=forms.Textarea,
                                             required=False,
                                             label=ugettext_lazy("SMS Text"))

    whom_to_send_message = BooleanField(label=ugettext_lazy(
        "Only send reminders to senders who have not already submitted data for the current deadline."
    ),
                                        required=False,
                                        initial=True)

    def __init__(self, *args, **kwargs):
        super(ReminderForm, self).__init__(*args, **kwargs)
        deadline_month = ChoiceField(
            choices=(tuple([(n, convert_to_ordinal(n)) for n in range(1, 31)] +
                           [(31, ugettext_lazy('Last Day'))])),
            widget=forms.Select,
            required=False)
        self.fields["deadline_month"] = deadline_month

    def clean(self):

        msg = _("This field is required")

        if self.cleaned_data.get('should_send_reminders_before_deadline'):
            if self.cleaned_data.get('number_of_days_before_deadline') is None:
                self._errors[
                    'number_of_days_before_deadline'] = self.error_class([msg])
            if self.cleaned_data.get('reminder_text_before_deadline') == '':
                self.errors[
                    'reminder_text_before_deadline'] = self.error_class([msg])

        if self.cleaned_data.get(
                'should_send_reminders_on_deadline') and self.cleaned_data.get(
                    'reminder_text_on_deadline') == '':
            self.errors['reminder_text_on_deadline'] = self.error_class([msg])

        if self.cleaned_data.get('should_send_reminders_after_deadline'):
            if self.cleaned_data.get('number_of_days_after_deadline') is None:
                self.errors[
                    'number_of_days_after_deadline'] = self.error_class([msg])
            if self.cleaned_data.get('reminder_text_after_deadline') == '':
                self.errors['reminder_text_after_deadline'] = self.error_class(
                    [msg])

        return self.cleaned_data
Ejemplo n.º 5
0
class ReminderForm(Form):
    frequency_period = ChoiceField(
        choices=(('week', _('Week')), ('month', _('Month'))),
        widget=forms.Select,
        required=False,
    )
    deadline_month = ChoiceField(choices=(tuple([(n, convert_to_ordinal(n))
                                                 for n in range(1, 8)])),
                                 widget=forms.Select,
                                 required=False)
    deadline_week = ChoiceField(
        choices=(get_translated_weekdays()),
        widget=forms.Select(attrs={'data-bind': 'random'}),
        required=False)
    deadline_type_week = ChoiceField(
        choices=(('Same', _('Same week')), ('Following', _('Following week'))),
        widget=forms.Select(attrs={'class': 'deadline_type'}),
        required=False)

    deadline_type_month = ChoiceField(
        choices=(('Same', _('Same month')), ('Following',
                                             _('Following month'))),
        widget=forms.Select(attrs={'class': 'deadline_type'}),
        required=False)

    deadline_type = ChoiceField(choices=(('Same', _('Same')),
                                         ('Following', _('Following'))),
                                widget=forms.Select,
                                required=False)

    should_send_reminders_before_deadline = BooleanField(
        required=False,
        initial=False,
        widget=forms.CheckboxInput(attrs={"hidden": True}))
    number_of_days_before_deadline_month = ChoiceField(
        choices=(tuple([(n, convert_to_ordinal(n)) for n in range(1, 8)])),
        label=ugettext_lazy("day(s) before deadline"),
        required=False)
    number_of_days_before_deadline_week = ChoiceField(
        choices=(tuple([(n, convert_to_ordinal(n)) for n in range(1, 4)])),
        label=ugettext_lazy("day(s) before deadline"),
        required=False)
    reminder_text_before_deadline = CharField(
        label=ugettext_lazy("Reminder text before deadline"),
        widget=forms.Textarea,
        required=False)

    should_send_reminders_on_deadline = BooleanField(
        label=ugettext_lazy("The day of the deadline"),
        required=False,
        initial=False,
        widget=forms.CheckboxInput(attrs={"hidden": True}))
    reminder_text_on_deadline = CharField(
        label=ugettext_lazy("Reminder text on deadline"),
        widget=forms.Textarea,
        required=False)

    should_send_reminders_after_deadline = BooleanField(
        label=ugettext_lazy("day(s) after the deadline"),
        required=False,
        initial=False,
        widget=forms.CheckboxInput(attrs={"hidden": True}))
    number_of_days_after_deadline_month = ChoiceField(
        choices=(tuple([(n, convert_to_ordinal(n)) for n in range(1, 8)])),
        label=ugettext_lazy("day(s) after deadline"),
        required=False)
    number_of_days_after_deadline_week = ChoiceField(
        choices=(tuple([(n, convert_to_ordinal(n)) for n in range(1, 4)])),
        label=ugettext_lazy("day(s) after deadline"),
        required=False)
    reminder_text_after_deadline = CharField(
        label=ugettext_lazy("Reminder text after deadline"),
        widget=forms.Textarea,
        required=False)

    whom_to_send_message = BooleanField(label=ugettext_lazy(
        "Only send Reminders to registered Data Senders who have not yet submitted data for the current deadline."
    ),
                                        required=False,
                                        initial=True)

    def __init__(self, *args, **kwargs):
        data = kwargs.get("data")
        if data is not None:
            deadline_type = data.get('deadline_type')
            data.update({
                "deadline_type_week": deadline_type,
                "deadline_type_month": deadline_type
            })
            kwargs.update({"data": data})

        super(ReminderForm, self).__init__(*args, **kwargs)
        deadline_month = ChoiceField(choices=(tuple([(n, convert_to_ordinal(n))
                                                     for n in range(1, 8)])),
                                     widget=forms.Select,
                                     required=False)
        self.fields["deadline_month"] = deadline_month

    def clean(self):

        msg = _("This field is required")

        if self.cleaned_data.get('should_send_reminders_before_deadline'):
            if self.cleaned_data.get('number_of_days_before_deadline') is None:
                self._errors[
                    'number_of_days_before_deadline'] = self.error_class([msg])
            if self.cleaned_data.get('reminder_text_before_deadline') == '':
                self.errors[
                    'reminder_text_before_deadline'] = self.error_class([msg])

        if self.cleaned_data.get(
                'should_send_reminders_on_deadline') and self.cleaned_data.get(
                    'reminder_text_on_deadline') == '':
            self.errors['reminder_text_on_deadline'] = self.error_class([msg])

        if self.cleaned_data.get('should_send_reminders_after_deadline'):
            if self.cleaned_data.get('number_of_days_after_deadline') is None:
                self.errors[
                    'number_of_days_after_deadline'] = self.error_class([msg])
            if self.cleaned_data.get('reminder_text_after_deadline') == '':
                self.errors['reminder_text_after_deadline'] = self.error_class(
                    [msg])

        return self.cleaned_data