|
@@ -42,11 +42,12 @@ class MergeThreadsForm(Form, ValidateThreadNameMixin):
|
|
|
self.fields['new_forum'] = ForumChoiceField(queryset=Forum.objects.get(special='root').get_descendants().filter(pk__in=self.request.acl.forums.acl['can_browse']), initial=self.threads[0].forum)
|
|
|
self.fields['thread_name'] = forms.CharField(
|
|
|
max_length=self.request.settings['thread_name_max'],
|
|
|
- initial=self.threads[0].name,
|
|
|
+ initial=self.threads[-1].name,
|
|
|
validators=[validate_sluggable(
|
|
|
_("Thread name must contain at least one alpha-numeric character."),
|
|
|
_("Thread name is too long. Try shorter name.")
|
|
|
)])
|
|
|
+
|
|
|
self.layout = [
|
|
|
[
|
|
|
None,
|
|
@@ -55,35 +56,10 @@ class MergeThreadsForm(Form, ValidateThreadNameMixin):
|
|
|
('new_forum', {'label': _("Thread Forum"), 'help_text': _("Select forum you want to put new thread in.")}),
|
|
|
],
|
|
|
],
|
|
|
- [
|
|
|
- _("Merge Order"),
|
|
|
- [
|
|
|
- ],
|
|
|
- ],
|
|
|
]
|
|
|
|
|
|
- choices = []
|
|
|
- for i, thread in enumerate(self.threads):
|
|
|
- choices.append((str(i), i + 1))
|
|
|
- for i, thread in enumerate(self.threads):
|
|
|
- self.fields['thread_%s' % thread.pk] = forms.ChoiceField(choices=choices, initial=str(i))
|
|
|
- self.layout[1][1].append(('thread_%s' % thread.pk, {'label': thread.name}))
|
|
|
-
|
|
|
def clean_new_forum(self):
|
|
|
new_forum = self.cleaned_data['new_forum']
|
|
|
- # Assert its forum
|
|
|
if new_forum.type != 'forum':
|
|
|
raise forms.ValidationError(_("This is not forum."))
|
|
|
return new_forum
|
|
|
-
|
|
|
- def clean(self):
|
|
|
- cleaned_data = super(MergeThreadsForm, self).clean()
|
|
|
- self.merge_order = {}
|
|
|
- lookback = []
|
|
|
- for thread in self.threads:
|
|
|
- order = int(cleaned_data['thread_%s' % thread.pk])
|
|
|
- if order in lookback:
|
|
|
- raise forms.ValidationError(_("One or more threads have same position in merge order."))
|
|
|
- lookback.append(order)
|
|
|
- self.merge_order[order] = thread
|
|
|
- return cleaned_data
|