comparison 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
comparison
equal deleted inserted replaced
114:535d02d1c017 115:0ce0104c7df3
123 Forum.objects.forums_for_user(user).order_by('name') 123 Forum.objects.forums_for_user(user).order_by('name')
124 if hide_label: 124 if hide_label:
125 self.fields['forums'].label = '' 125 self.fields['forums'].label = ''
126 self.fields['forums'].required = required 126 self.fields['forums'].required = required
127 127
128
129 class SplitTopicForm(forms.Form):
130 """
131 Form for a moderator to split posts from a topic to a new topic.
132 """
133 name = forms.CharField(label='New topic title', max_length=255,
134 widget=forms.TextInput(attrs={'size': 64}))
135 forums = forms.ModelChoiceField(label='Forum for new topic',
136 queryset=Forum.objects.none())
137 post_ids = []
138 split_at = False
139
140 def __init__(self, user, *args, **kwargs):
141 super(SplitTopicForm, self).__init__(*args, **kwargs)
142 self.fields['forums'].queryset = \
143 Forum.objects.forums_for_user(user).order_by('name')
144
145 def clean(self):
146 self.post_ids = self.data.getlist('post_ids')
147 if len(self.post_ids) == 0:
148 raise forms.ValidationError('Please select some posts')
149
150 self.split_at = 'split-at' in self.data
151 if self.split_at and len(self.post_ids) > 1:
152 raise forms.ValidationError('Please select only one post to split the topic at')
153
154 return self.cleaned_data