mirror of
https://github.com/QingdaoU/Spirit.git
synced 2025-01-04 02:52:32 +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):
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user