mirror of
https://github.com/QingdaoU/Spirit.git
synced 2025-01-07 12:32:42 +00:00
topic notification form validation
This commit is contained in:
parent
5c4d13c9e2
commit
fcad3b062d
@ -27,13 +27,21 @@ class NotificationCreationForm(NotificationForm):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data = super(NotificationCreationForm, self).clean()
|
cleaned_data = super(NotificationCreationForm, self).clean()
|
||||||
|
|
||||||
notification = TopicNotification.objects.filter(user=self.user,
|
notification = TopicNotification.objects.filter(
|
||||||
topic=self.topic)
|
user=self.user,
|
||||||
|
topic=self.topic
|
||||||
|
)
|
||||||
|
|
||||||
if notification.exists():
|
if notification.exists():
|
||||||
# Do this since some of the unique_together fields are excluded.
|
# Do this since some of the unique_together fields are excluded.
|
||||||
raise forms.ValidationError(_("This notification already exists"))
|
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
|
return cleaned_data
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
|
Loading…
Reference in New Issue
Block a user