From 93cba698e440ed7a5f5b784f743641c7c007b0bc Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sun, 1 Apr 2018 01:51:25 -0400 Subject: [PATCH] Instead of throwing an error, display an empty form is there are not event types to display. Signed-off-by: Roberto Rosario --- docs/topics/pending_work.rst | 1 + mayan/apps/events/forms.py | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/topics/pending_work.rst b/docs/topics/pending_work.rst index 6445ace184..9f69c1e509 100644 --- a/docs/topics/pending_work.rst +++ b/docs/topics/pending_work.rst @@ -75,6 +75,7 @@ Other libraries. - Automatically capture license information from installed Python packages. +- Unify all **RelationshipForms into a common class. Permissions ~~~~~~~~~~~ diff --git a/mayan/apps/events/forms.py b/mayan/apps/events/forms.py index a9617c909e..dced610120 100644 --- a/mayan/apps/events/forms.py +++ b/mayan/apps/events/forms.py @@ -29,18 +29,19 @@ class EventTypeUserRelationshipForm(forms.Form): *args, **kwargs ) - self.fields['namespace'].initial = self.initial['stored_event_type'].namespace - self.fields['label'].initial = self.initial['stored_event_type'].label + if 'stored_event_type' in self.initial: + self.fields['namespace'].initial = self.initial['stored_event_type'].namespace + self.fields['label'].initial = self.initial['stored_event_type'].label - subscription = EventSubscription.objects.get_for( - stored_event_type=self.initial['stored_event_type'], - user=self.initial['user'], - ) + subscription = EventSubscription.objects.get_for( + stored_event_type=self.initial['stored_event_type'], + user=self.initial['user'], + ) - if subscription.exists(): - self.fields['subscription'].initial = 'subscribed' - else: - self.fields['subscription'].initial = 'none' + if subscription.exists(): + self.fields['subscription'].initial = 'subscribed' + else: + self.fields['subscription'].initial = 'none' def save(self): subscription = EventSubscription.objects.get_for(