topic notification form validation

This commit is contained in:
nitely 2015-07-26 15:42:54 -03:00
parent 5c4d13c9e2
commit fcad3b062d

View File

@ -27,13 +27,21 @@ class NotificationCreationForm(NotificationForm):
def clean(self):
cleaned_data = super(NotificationCreationForm, self).clean()
notification = TopicNotification.objects.filter(user=self.user,
topic=self.topic)
notification = TopicNotification.objects.filter(
user=self.user,
topic=self.topic
)
if notification.exists():
# Do this since some of the unique_together fields are excluded.
raise forms.ValidationError(_("This notification already exists"))
# todo: test!
comment = self.topic.comment_set.last()
if comment is None:
raise forms.ValidationError(_("You can't subscribe to a topic with no comments"))
return cleaned_data
def save(self, commit=True):