Mercurial > public > sg101
diff gpp/forums/forms.py @ 115:0ce0104c7df3
Forums: split topic.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 22 Oct 2009 02:57:18 +0000 |
parents | d1b0b86441c0 |
children | 3ae999b0c53b |
line wrap: on
line diff
--- a/gpp/forums/forms.py Sun Oct 11 20:27:07 2009 +0000 +++ b/gpp/forums/forms.py Thu Oct 22 02:57:18 2009 +0000 @@ -125,3 +125,30 @@ self.fields['forums'].label = '' self.fields['forums'].required = required + +class SplitTopicForm(forms.Form): + """ + Form for a moderator to split posts from a topic to a new topic. + """ + name = forms.CharField(label='New topic title', max_length=255, + widget=forms.TextInput(attrs={'size': 64})) + forums = forms.ModelChoiceField(label='Forum for new topic', + queryset=Forum.objects.none()) + post_ids = [] + split_at = False + + def __init__(self, user, *args, **kwargs): + super(SplitTopicForm, self).__init__(*args, **kwargs) + self.fields['forums'].queryset = \ + Forum.objects.forums_for_user(user).order_by('name') + + def clean(self): + self.post_ids = self.data.getlist('post_ids') + if len(self.post_ids) == 0: + raise forms.ValidationError('Please select some posts') + + self.split_at = 'split-at' in self.data + if self.split_at and len(self.post_ids) > 1: + raise forms.ValidationError('Please select only one post to split the topic at') + + return self.cleaned_data