Exemple #1
0
class NotificationTemplate(models.Model):
    event = models.CharField(max_length=60, choices=registry.get_event_choices(), verbose_name=_('event'))
    business_lines = models.ManyToManyField('incidents.BusinessLine', related_name='+', blank=True,
                                            verbose_name=_('business line'))
    subject = models.CharField(max_length=200, blank=True, default="", verbose_name=_('subject'))
    short_description = models.TextField(blank=True, default="", verbose_name=_('short description'))
    description = models.TextField(blank=True, default="", verbose_name=_('description'))

    class Meta:
        verbose_name = _('notification template')
        verbose_name_plural = _('notification templates')
Exemple #2
0
class NotificationPreferenceForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user', None)
        instance = kwargs.get('instance', None)
        if self.user is None and instance is not None:
            self.user = instance.user
        if instance is None and kwargs.get('data', None) is not None:
            data = kwargs.get('data')
            event = data.get('event', None)
            method = data.get('method', None)
            if event and method and self.user:
                try:
                    kwargs['instance'] = NotificationPreference.objects.get(
                        user=self.user, event=event, method=method)
                except (NotificationPreference.DoesNotExist,
                        NotificationPreference.MultipleObjectsReturned):
                    pass
        super(NotificationPreferenceForm, self).__init__(*args, **kwargs)
        self.fields[
            'business_lines'].queryset = BusinessLine.authorization.for_user(
                self.user, 'incidents.view_incidents')
        if instance is not None:
            self.fields['event'].disabled = True
            self.fields['method'].disabled = True

    def clean_user(self):
        if self.user is None:
            raise forms.ValidationError(
                _("Notification preference must be linked to a user."))
        return self.user

    user = forms.ModelChoiceField(queryset=get_user_model().objects.all(),
                                  widget=forms.HiddenInput(),
                                  required=False)
    event = forms.ChoiceField(choices=registry.get_event_choices(),
                              label=_('Event'))
    method = forms.ChoiceField(choices=registry.get_method_choices(),
                               label=_('Method'))
    business_lines = forms.ModelMultipleChoiceField(BusinessLine.objects.all(),
                                                    label=_('Business lines'))

    class Meta:
        fields = '__all__'
        model = NotificationPreference
Exemple #3
0
class NotificationTemplateForm(forms.ModelForm):
    event = forms.ChoiceField(choices=registry.get_event_choices())

    class Meta:
        fields = '__all__'