示例#1
0
    def init_form_helper(self):
        fields = []
        channel_fields = []

        for channel in whistle_settings.CHANNELS:
            if NotificationManager.is_channel_available(self.user, channel):
                channel_fields.append(
                    Div(Field(channel, css_class='switch'), css_class='channel fw-bold col-md mb-3')
                )

        fields.append(Div(
                Div(HTML('<p>{}</p>'.format(_(''))), css_class='col-md-6'),
                *channel_fields,
                css_class='row'
            )
        )

        for event, label in self.labels.items():
            field_names = self.field_names(event)
            event_fields = []

            for channel in whistle_settings.CHANNELS:
                if NotificationManager.is_notification_available(self.user, channel, event):
                    event_fields.append(
                        Div(Field(field_names[channel], css_class='switch'), css_class='col-md')
                    )

            if len(event_fields) > 0:
                fields.append(Div(
                        Div(HTML('<p>{}</p>'.format(label)), css_class='col-md-6'),
                        *event_fields,
                        css_class='row'
                    )
                )

        fields.append(
            FormActions(
                Submit('submit', _('Save'), css_class='btn-lg')
            )
        )

        self.helper = FormHelper()
        self.helper.form_class = 'notification-settings'
        self.helper.layout = Layout(*fields)
示例#2
0
    def init_fields(self):
        for channel in whistle_settings.CHANNELS:
            if NotificationManager.is_channel_available(self.user, channel):
                self.fields.update({
                    channel: forms.BooleanField(
                        label=self.channel_labels(channel),
                        required=False,
                        initial=self.get_initial_value(channel)),
                })

        for event, label in self.labels.items():
            field_names = self.field_names(event)

            for channel in whistle_settings.CHANNELS:
                if NotificationManager.is_notification_available(self.user, channel, event):
                    self.fields.update({
                        field_names[channel]: forms.BooleanField(
                            label=self.channel_labels(channel),
                            required=False,
                            initial=self.get_initial_value(channel, event)),
                    })
示例#3
0
    def clean(self):
        settings = {'channels': {}, 'events': {}}

        for channel in whistle_settings.CHANNELS:
            if NotificationManager.is_channel_available(self.user, channel):
                settings['channels'][channel] = self.cleaned_data.get(channel)

        # events
        for event in self.labels.keys():
            field_names = self.field_names(event)
            event_identifier = event.lower()

            for channel in whistle_settings.CHANNELS:
                if NotificationManager.is_channel_available(self.user, channel) and \
                        NotificationManager.is_notification_available(self.user, channel, event):
                    if channel not in settings['events']:
                        settings['events'][channel] = {}

                    settings['events'][channel][event_identifier] = self.cleaned_data.get(field_names[channel])

        return settings