class EmailReportForm(forms.Form): subject = forms.CharField(required=False) send_to_owner = forms.BooleanField(required=False) attach_excel = forms.BooleanField(required=False) recipient_emails = MultiEmailField(required=False) notes = forms.CharField(required=False) def clean(self): cleaned_data = super(EmailReportForm, self).clean() _verify_email(cleaned_data) return cleaned_data
class ScheduledReportForm(forms.Form): config_ids = forms.MultipleChoiceField( label="Saved report(s)", validators=[MinLengthValidator(1)], help_text='Note: not all built-in reports support email delivery, so' ' some of your saved reports may not appear in this list') interval = forms.TypedChoiceField(label='Interval', choices=[("daily", "Daily"), ("weekly", "Weekly"), ("monthly", "Monthly")]) day = forms.TypedChoiceField(label="Day", coerce=int, required=False, choices=[(i, i) for i in range(0, 32)]) hour = forms.TypedChoiceField(label='Time', coerce=int, choices=ReportNotification.hour_choices()) send_to_owner = forms.BooleanField(label='Send to owner', required=False) attach_excel = forms.BooleanField(label='Attach Excel Report', required=False) recipient_emails = MultiEmailField(label='Other recipients', required=False) email_subject = forms.CharField( required=False, help_text= 'Translated into recipient\'s language if set to "%(default_subject)s".' % { 'default_subject': DEFAULT_REPORT_NOTIF_SUBJECT, }, ) language = forms.ChoiceField(label='Language', required=False, choices=[('', '')] + langcodes.get_all_langs_for_select(), widget=forms.Select()) def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.form_class = 'form-horizontal' self.helper.form_id = 'id-scheduledReportForm' self.helper.label_class = 'col-sm-3 col-md-2' self.helper.field_class = 'col-sm-9 col-md-8 col-lg-6' self.helper.add_layout( crispy.Layout( crispy.Fieldset( ugettext("Configure Scheduled Report"), 'config_ids', 'interval', 'day', 'hour', B3MultiField(ugettext("Send Options"), 'send_to_owner'), B3MultiField(ugettext("Excel Attachment"), 'attach_excel'), crispy.Field( 'email_subject', css_class='input-xlarge', ), 'recipient_emails', 'language', crispy.HTML( render_to_string( 'reports/partials/privacy_disclaimer.html'))), FormActions(crispy.Submit('submit_btn', 'Submit')))) super(ScheduledReportForm, self).__init__(*args, **kwargs) def clean(self): cleaned_data = super(ScheduledReportForm, self).clean() if cleaned_data["interval"] == "daily": del cleaned_data["day"] _verify_email(cleaned_data) return cleaned_data
class ScheduledReportForm(forms.Form): INTERVAL_CHOICES = [("daily", _("Daily")), ("weekly", _("Weekly")), ("monthly", _("Monthly"))] config_ids = forms.MultipleChoiceField( label=_("Saved report(s)"), validators=[MinLengthValidator(1)], help_text='Note: not all built-in reports support email delivery, so' ' some of your saved reports may not appear in this list') interval = forms.TypedChoiceField(label=_('Interval'), widget=SelectToggle( choices=INTERVAL_CHOICES, apply_bindings=True), choices=INTERVAL_CHOICES) day = forms.TypedChoiceField(label=_("Day"), coerce=int, required=False, choices=[(i, i) for i in range(0, 32)]) hour = forms.TypedChoiceField(label=_('Time'), coerce=int, choices=ReportNotification.hour_choices()) start_date = forms.DateField(label=_('Report Start Date'), required=False) send_to_owner = forms.BooleanField(label=_('Send to owner'), required=False) attach_excel = forms.BooleanField(label=_('Attach Excel Report'), required=False) recipient_emails = MultiEmailField(label=_('Other recipients'), required=False) email_subject = forms.CharField( required=False, help_text= 'Translated into recipient\'s language if set to "%(default_subject)s".' % { 'default_subject': DEFAULT_REPORT_NOTIF_SUBJECT, }, ) language = forms.ChoiceField(label=_('Language'), required=False, choices=[('', '')] + langcodes.get_all_langs_for_select(), widget=forms.Select()) def __init__(self, *args, **kwargs): super(ScheduledReportForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_class = 'form-horizontal' self.helper.form_id = 'id-scheduledReportForm' self.helper.label_class = 'col-sm-3 col-md-2' self.helper.field_class = 'col-sm-9 col-md-8 col-lg-6' domain = kwargs.get('initial', {}).get('domain', None) if domain is not None and HOURLY_SCHEDULED_REPORT.enabled( domain, NAMESPACE_DOMAIN): self.fields['interval'].choices.insert( 0, ("hourly", gettext("Hourly"))) self.fields['interval'].widget.choices.insert( 0, ("hourly", gettext("Hourly"))) self.helper.add_layout( crispy.Layout( crispy.Fieldset( gettext("Configure Scheduled Report"), 'config_ids', 'interval', 'day', 'hour', 'start_date', crispy.Field( 'email_subject', css_class='input-xlarge', ), crispy.Field('send_to_owner'), crispy.Field('attach_excel'), 'recipient_emails', 'language', crispy.HTML( render_to_string( 'reports/partials/privacy_disclaimer.html'))), FormActions(crispy.Submit('submit_btn', 'Submit')))) def clean(self): cleaned_data = super(ScheduledReportForm, self).clean() if cleaned_data.get("interval") == "daily": del cleaned_data["day"] if cleaned_data.get("interval") == "hourly": del cleaned_data["day"] del cleaned_data["hour"] _verify_email(cleaned_data) return cleaned_data