Ejemplo n.º 1
0
    def clean(self):
        data = super(DeleteForumFormBase, self).clean()

        if data.get('move_threads_to'):
            if data['move_threads_to'].pk == self.instance.pk:
                message = _("You are trying to move this forum threads to "
                            "itself.")
                raise forms.ValidationError(message)

            if data['move_threads_to'].role == 'category':
                message = _("Threads can't be moved to category.")
                raise forms.ValidationError(message)

            if data['move_threads_to'].role == 'redirect':
                message = _("Threads can't be moved to redirect.")
                raise forms.ValidationError(message)

            moving_to_child = self.instance.has_child(data['move_threads_to'])
            if moving_to_child and not data.get('move_children_to'):
                message = _("You are trying to move this forum threads to a "
                            "child forum that will be deleted together with "
                            "this forum.")
                raise forms.ValidationError(message)

        if data.get('move_children_to'):
            if data['move_children_to'].special_role == 'root_category':
                for child in self.instance.get_children().iterator():
                    if child.role != 'category':
                        message = _("One or more child forums in forum are "
                                    "not categories and thus cannot be made "
                                    "root categories.")
                        raise forms.ValidationError(message)

        return data
Ejemplo n.º 2
0
 def clean_copy_permissions(self):
     data = self.cleaned_data['copy_permissions']
     if data and data.pk == self.instance.pk:
         message = _(
             "Permissions cannot be copied from category into itself.")
         raise forms.ValidationError(message)
     return data
Ejemplo n.º 3
0
    def clean(self):
        data = super(DeleteCategoryFormBase, self).clean()

        if data.get('move_threads_to'):
            if data['move_threads_to'].pk == self.instance.pk:
                message = _("You are trying to move this category threads to "
                            "itself.")
                raise forms.ValidationError(message)

            moving_to_child = self.instance.has_child(data['move_threads_to'])
            if moving_to_child and not data.get('move_children_to'):
                message = _(
                    "You are trying to move this category threads to a "
                    "child category that will be deleted together with "
                    "this category.")
                raise forms.ValidationError(message)

        return data
Ejemplo n.º 4
0
    def clean(self):
        data = super(ForumFormBase, self).clean()

        self.instance.set_name(data.get('name'))

        if data['role'] != 'category':
            if not data['new_parent'].level:
                message = _("Only categories can have no parent category.")
                raise forms.ValidationError(message)

        if data['role'] == 'redirect':
            if not data.get('redirect_url'):
                message = _("This forum is redirect, yet you haven't "
                            "specified URL to which it should redirect "
                            "after click.")
                raise forms.ValidationError(message)

        return data
Ejemplo n.º 5
0
 def clean_archive_pruned_in(self):
     data = self.cleaned_data['archive_pruned_in']
     if data and data.pk == self.instance.pk:
         message = _("Category cannot act as archive for itself.")
         raise forms.ValidationError(message)
     return data