class Edit(FormWidget): admin = site.get_action('attachments') id = 'edit' name = _("Edit Attachment Type") fallback = 'admin_attachments_types' form = AttachmentTypeForm target_name = 'name' notfound_message = _('Requested attachments type could not be found.') translate_target_name = True submit_fallback = True def get_link(self, model): return reverse('admin_attachments_types_edit', model) def get_edit_link(self, model): return self.get_link(model) def get_initial_data(self, model): return { 'name': model.name, 'extensions': model.extensions, 'size_limit': model.size_limit, 'roles': model.roles, } def submit_form(self, form, target): target.name = form.cleaned_data['name'] target.extensions = form.cleaned_data['extensions'] target.size_limit = form.cleaned_data['size_limit'] target.save(force_update=True) target.update_roles(form.cleaned_data['roles']) AttachmentType.objects.flush_cache() return target, Message(_('Changes in type "%(name)s" have been saved.') % {'name': self.original_name}, messages.SUCCESS)
class New(FormWidget): admin = site.get_action('ranks') id = 'new' fallback = 'admin_users_ranks' form = RankForm submit_button = _("Save Rank") def get_new_url(self, request, model): return reverse('admin_users_ranks') def get_edit_url(self, request, model): return reverse('admin_users_ranks_edit', model) def submit_form(self, request, form, target): position = 0 last_rank = Rank.objects.latest('order') new_rank = Rank(name=form.cleaned_data['name'], name_slug=slugify(form.cleaned_data['name']), description=form.cleaned_data['description'], style=form.cleaned_data['style'], title=form.cleaned_data['title'], special=form.cleaned_data['special'], as_tab=form.cleaned_data['as_tab'], order=(last_rank.order + 1 if last_rank else 0), criteria=form.cleaned_data['criteria']) new_rank.save(force_insert=True) return new_rank, BasicMessage(_('New Rank has been created.'), 'success')
class Delete(ButtonWidget): """ Delete Ban """ admin = site.get_action('bans') id = 'delete' fallback = 'admin_users_bans' notfound_message = _('Requested Ban could not be found.') def action(self, request, target): target.delete() request.monitor['bans_version'] = int( request.monitor['bans_version']) + 1 if target.type == 0: return BasicMessage( _('E-mail and username Ban "%(ban)s" has been lifted.' % {'ban': target.ban}), 'success'), False if target.type == 1: return BasicMessage( _('Username Ban "%(ban)s" has been lifted.' % {'ban': target.ban}), 'success'), False if target.type == 2: return BasicMessage( _('E-mail Ban "%(ban)s" has been lifted.' % {'ban': target.ban}), 'success'), False if target.type == 3: return BasicMessage( _('IP Ban "%(ban)s" has been lifted.' % {'ban': target.ban}), 'success'), False
class New(FormWidget): admin = site.get_action('prefixes') id = 'new' fallback = 'admin_threads_prefixes' form = PrefixForm submit_button = _("Save Prefix") def get_new_link(self, model): return reverse('admin_threads_prefixes_new') def get_edit_link(self, model): return reverse('admin_threads_prefixes_edit', model) def get_form(self, target): return self.form() def submit_form(self, form, target): new_prefix = ThreadPrefix( name=form.cleaned_data['name'], slug=slugify(form.cleaned_data['name']), style=form.cleaned_data['style'], ) new_prefix.save(force_insert=True) for forum in form.cleaned_data['forums']: new_prefix.forums.add(forum) return new_prefix, Message(_('New Prefix has been created.'), messages.SUCCESS)
class Edit(FormWidget): admin = site.get_action('roles_forums') id = 'edit' name = _("Edit Forum Role") fallback = 'admin_roles_forums' form = ForumRoleForm target_name = 'name' notfound_message = _('Requested Forum Role could not be found.') submit_fallback = True def get_link(self, model): return reverse('admin_roles_forums_edit', model) def get_edit_link(self, model): return self.get_link(model) def get_initial_data(self, model): return { 'name': model.name, } def submit_form(self, form, target): target.name = form.cleaned_data['name'] target.save(force_update=True) return target, Message( _('Changes in forum role "%(name)s" have been saved.') % {'name': self.original_name}, messages.SUCCESS)
class Delete(ButtonWidget): """ Delete Ban """ admin = site.get_action('bans') id = 'delete' fallback = 'admin_bans' notfound_message = _('Requested Ban could not be found.') def action(self, target): target.delete() self.request.monitor.increase('bans_version') if target.test == 0: return Message( _('E-mail and username Ban "%(ban)s" has been lifted.') % {'ban': target.ban}, 'success'), False if target.test == 1: return Message( _('Username Ban "%(ban)s" has been lifted.') % {'ban': target.ban}, 'success'), False if target.test == 2: return Message( _('E-mail Ban "%(ban)s" has been lifted.') % {'ban': target.ban}, 'success'), False if target.test == 3: return Message( _('IP Ban "%(ban)s" has been lifted.') % {'ban': target.ban}, 'success'), False
class New(FormWidget): """ Create Ban """ admin = site.get_action('bans') id = 'new' fallback = 'admin_bans' form = BanForm submit_button = _("Set Ban") def get_new_url(self, model): return reverse('admin_bans_new') def get_edit_url(self, model): return reverse('admin_bans_edit', model) def submit_form(self, form, target): new_ban = Ban(test=form.cleaned_data['test'], ban=form.cleaned_data['ban'], reason_user=form.cleaned_data['reason_user'], reason_admin=form.cleaned_data['reason_admin'], expires=form.cleaned_data['expires']) new_ban.save(force_insert=True) self.request.monitor.increase('bans_version') return new_ban, Message(_('New Ban has been set.'), 'success')
class List(ListWidget): admin = site.get_action('roles') id = 'list' columns=( ('role', _("Role")), ) nothing_checked_message = _('You have to check at least one role.') actions=( ('delete', _("Delete selected roles"), _("Are you sure you want to delete selected roles?")), ) def sort_items(self, page_items, sorting_method): return page_items.order_by('name') def get_item_actions(self, item): return ( self.action('list', _("Forums Permissions"), reverse('admin_roles_masks', item)), self.action('adjust', _("Role Permissions"), reverse('admin_roles_acl', item)), self.action('pencil', _("Edit Role"), reverse('admin_roles_edit', item)), self.action('remove', _("Delete Role"), reverse('admin_roles_delete', item), post=True, prompt=_("Are you sure you want to delete this role?")), ) def action_delete(self, items, checked): for item in items: if item.pk in checked: if item.special: return Message(_('You cannot delete system roles.'), messages.ERROR), reverse('admin_roles') if item.protected and not self.request.user.is_god(): return Message(_('You cannot delete protected roles.'), messages.ERROR), reverse('admin_roles') if item.user_set.count() > 0: return Message(_('You cannot delete roles that are assigned to users.'), messages.ERROR), reverse('admin_roles') Role.objects.filter(id__in=checked).delete() return Message(_('Selected roles have been deleted successfully.'), messages.SUCCESS), reverse('admin_roles')
class List(ListWidget): admin = site.get_action('prefixes') id = 'list' columns = (('prefix', _("Thread Prefix")), ) nothing_checked_message = _('You have to check at least one prefix.') actions = (('delete', _("Delete selected prefixes"), _("Are you sure you want to delete selected prefixes?")), ) def sort_items(self, page_items, sorting_method): return page_items.order_by('name') def get_item_actions(self, item): return ( self.action('pencil', _("Edit Prefix"), reverse('admin_threads_prefixes_edit', item)), self.action( 'remove', _("Delete Prefix"), reverse('admin_threads_prefixes_delete', item), post=True, prompt=_("Are you sure you want to delete this prefix?")), ) def action_delete(self, items, checked): for prefix in ThreadPrefix.objects.filter(id__in=checked): prefix.delete() return Message(_('Selected prefixes have been deleted successfully.'), messages.SUCCESS), reverse('admin_threads_prefixes')
class List(ListWidget): admin = site.get_action('roles_forums') id = 'list' columns = (('role', _("Role")), ) nothing_checked_message = _('You have to check at least one role.') actions = (('delete', _("Delete selected forum roles"), _("Are you sure you want to delete selected roles?")), ) def sort_items(self, page_items, sorting_method): return page_items.order_by('name') def get_item_actions(self, item): return ( self.action('adjust', _("Role Permissions"), reverse('admin_roles_forums_acl', item)), self.action('pencil', _("Edit Role"), reverse('admin_roles_forums_edit', item)), self.action( 'remove', _("Delete Role"), reverse('admin_roles_forums_delete', item), post=True, prompt=_("Are you sure you want to delete this role?")), ) def action_delete(self, items, checked): with UpdatingMonitor() as cm: monitor.increase('acl_version') Role.objects.filter(id__in=checked).delete() return Message( _('Selected forum roles have been deleted successfully.'), messages.SUCCESS), reverse('admin_roles_forums')
class List(ListWidget): admin = site.get_action('prune_users') id = 'list' columns = (('name', _("Pruning Policy")), ) nothing_checked_message = _('You have to check at least one policy.') actions = (('delete', _("Delete selected policies"), _("Are you sure you want to delete selected policies?")), ) def sort_items(self, page_items, sorting_method): return page_items.order_by('name') def get_item_actions(self, item): return ( self.action('filter', _("Apply Policy"), reverse('admin_prune_users_apply', item)), self.action('pencil', _("Edit Policy"), reverse('admin_prune_users_edit', item)), self.action( 'remove', _("Delete Policy"), reverse('admin_prune_users_delete', item), post=True, prompt=_("Are you sure you want to delete this policy?")), ) def action_delete(self, items, checked): if not self.request.user.is_god(): return Message( _('Only system administrators can delete pruning policies.'), 'error'), reverse('admin_prune_users') PruningPolicy.objects.filter(id__in=checked).delete() return Message( _('Selected pruning policies have been deleted successfully.'), 'success'), reverse('admin_prune_users')
class New(FormWidget): admin = site.get_action('prune_users') id = 'new' fallback = 'admin_prune_users' form = PolicyForm submit_button = _("Save Policy") def get_new_link(self, model): return reverse('admin_prune_users_new') def get_edit_link(self, model): return reverse('admin_prune_users_edit', model) def submit_form(self, form, target): new_policy = PruningPolicy( name=form.cleaned_data['name'], email=form.cleaned_data['email'], posts=form.cleaned_data['posts'], registered=form.cleaned_data['registered'], last_visit=form.cleaned_data['last_visit'], ) new_policy.clean() new_policy.save(force_insert=True) return new_policy, Message(_('New Pruning Policy has been created.'), messages.SUCCESS) def __call__(self, request, *args, **kwargs): if not request.user.is_god(): messages.error(request, _('Only system administrators can set new pruning policies.'), self.admin.id) return redirect(reverse('admin_prune_users')) return super(New, self).__call__(request, *args, **kwargs)
class New(FormWidget): admin = site.get_action('newsletters') id = 'new' fallback = 'admin_newsletters' form = NewsletterForm submit_button = _("Save Newsletter") tabbed = True def get_new_link(self, model): return reverse('admin_newsletters_new') def get_edit_link(self, model): return reverse('admin_newsletters_edit', model) def submit_form(self, form, target): new_newsletter = Newsletter( name=form.cleaned_data['name'], step_size=form.cleaned_data['step_size'], content_html=form.cleaned_data['content_html'], content_plain=form.cleaned_data['content_plain'], ignore_subscriptions=form.cleaned_data['ignore_subscriptions'], ) new_newsletter.generate_token() new_newsletter.save(force_insert=True) for rank in form.cleaned_data['ranks']: new_newsletter.ranks.add(rank) return new_newsletter, Message(_('New Newsletter has been created.'), messages.SUCCESS)
class New(FormWidget): admin = site.get_action('users') id = 'new' fallback = 'admin_users' form = NewUserForm submit_button = _("Save User") def get_new_url(self, model): return reverse('admin_users_new') def get_edit_url(self, model): return reverse('admin_users_edit', model) def submit_form(self, form, target): new_user = User.objects.create_user( form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password'], self.request.settings['default_timezone'], self.request.META['REMOTE_ADDR'], no_roles=True, request=self.request, ) new_user.title = form.cleaned_data['title'] new_user.rank = form.cleaned_data['rank'] for role in form.cleaned_data['roles']: new_user.roles.add(role) new_user.make_acl_key(True) new_user.save(force_update=True) return new_user, Message(_('New User has been created.'), 'success')
class New(FormWidget): admin = site.get_action('warning_levels') id = 'new' fallback = 'admin_warning_levels' form = WarnLevelForm submit_button = _("Save Warning Level") def get_new_link(self, model): return reverse('admin_warning_levels_new') def get_edit_link(self, model): return reverse('admin_warning_levels_edit', model) def submit_form(self, form, target): top_level = WarnLevel.objects.order_by('-warning_level')[:1] if top_level: new_warning_level = top_level[0].warning_level + 1 else: new_warning_level = 1 new_level = WarnLevel( name=form.cleaned_data['name'], slug=slugify(form.cleaned_data['name']), description=form.cleaned_data['description'], warning_level=new_warning_level, expires_after_minutes=form.cleaned_data['expires_after_minutes'], restrict_posting_replies=form.cleaned_data['restrict_posting_replies'], restrict_posting_threads=form.cleaned_data['restrict_posting_threads'] ) new_level.save(force_insert=True) WarnLevel.objects.flush_cache() return new_level, Message(_('New warning level has been defined.'), messages.SUCCESS)
class List(ListWidget): admin = site.get_action('forums') id = 'list' columns = ( ('forum', _("Forum")), ) nothing_checked_message = _('You have to select at least one forum.') actions = ( ('resync_fast', _("Resynchronize forums (fast)")), ('resync', _("Resynchronize forums")), ) empty_message = _('No forums are currently defined.') def get_items(self): return self.admin.model.objects.get(special='root').get_descendants() def sort_items(self, page_items, sorting_method): return page_items.order_by('lft') def get_item_actions(self, item): if item.type == 'category': return ( self.action('chevron-up', _("Move Category Up"), reverse('admin_forums_up', item), post=True), self.action('chevron-down', _("Move Category Down"), reverse('admin_forums_down', item), post=True), self.action('pencil', _("Edit Category"), reverse('admin_forums_edit', item)), self.action('remove', _("Delete Category"), reverse('admin_forums_delete', item)), ) if item.type == 'forum': return ( self.action('chevron-up', _("Move Forum Up"), reverse('admin_forums_up', item), post=True), self.action('chevron-down', _("Move Forum Down"), reverse('admin_forums_down', item), post=True), self.action('pencil', _("Edit Forum"), reverse('admin_forums_edit', item)), self.action('remove', _("Delete Forum"), reverse('admin_forums_delete', item)), ) return ( self.action('chevron-up', _("Move Redirect Up"), reverse('admin_forums_up', item), post=True), self.action('chevron-down', _("Move Redirect Down"), reverse('admin_forums_down', item), post=True), self.action('pencil', _("Edit Redirect"), reverse('admin_forums_edit', item)), self.action('remove', _("Delete Redirect"), reverse('admin_forums_delete', item)), ) def action_resync_fast(self, items, checked): for forum in items: if forum.pk in checked: forum.sync() forum.save(force_update=True) return Message(_('Selected forums have been resynchronized successfully.'), 'success'), reverse('admin_forums') def action_resync(self, items, checked): clean_checked = [] for item in items: if item.pk in checked and item.type == 'forum': clean_checked.append(item.pk) if not clean_checked: return Message(_('Only forums can be resynchronized.'), 'error'), reverse('admin_forums') self.request.session['sync_forums'] = clean_checked return Message('Meh', 'success'), django_reverse('admin_forums_resync')
class List(ListWidget): admin = site.get_action('warning_levels') id = 'list' columns = ( ('name', _("Level Name")), ) table_form_button = _('Change Warning Levels') nothing_checked_message = _('You have to check at least one warning level.') actions = ( ('delete', _("Delete selected levels"), _("Are you sure you want to delete selected warning levels?")), ) def get_table_form(self, page_items): order_form = {} # Build choices list choices = [] for i in range(0, len(page_items)): choices.append([str(i), i + 1]) # Build selectors list position = 0 for item in page_items: order_form['pos_' + str(item.pk)] = forms.ChoiceField(choices=choices, initial=str(position)) position += 1 # Turn dict into object return type('OrderWarningLevelsForm', (Form,), order_form) def table_action(self, page_items, cleaned_data): for item in page_items: item.warning_level = cleaned_data['pos_' + str(item.pk)] item.save(force_update=True) WarnLevel.objects.flush_cache() return Message(_('Warning levels have been changed'), messages.SUCCESS), reverse('admin_warning_levels') def sort_items(self, page_items, sorting_method): return page_items.order_by('warning_level') def get_item_actions(self, item): return ( self.action('pencil', _("Edit Level"), reverse('admin_warning_levels_edit', item)), self.action('remove', _("Delete Level"), reverse('admin_warning_levels_delete', item), post=True, prompt=_("Are you sure you want to delete this warning level?")), ) def action_delete(self, items, checked): WarnLevel.objects.filter(id__in=checked).delete() levels_counter = 1 for level in WarnLevel.objects.order_by('warning_level').iterator(): if level.warning_level != levels_counter: level.warning_level = levels_counter level.save(force_update=True) levels_counter += 1 WarnLevel.objects.flush_cache() return Message(_('Selected warning levels have been deleted successfully.'), messages.SUCCESS), reverse('admin_warning_levels')
class Delete(ButtonWidget): admin = site.get_action('ranks') id = 'delete' fallback = 'admin_ranks' notfound_message = _('Requested Rank could not be found.') def action(self, target): target.delete() return Message(_('Rank "%(name)s" has been deleted.') % {'name': _(target.name)}, 'success'), False
class List(ListWidget): """ List Users """ admin = site.get_action('ranks') id = 'list' columns = (('rank', _("Rank")), ) table_form_button = _('Reorder Ranks') nothing_checked_message = _('You have to check at least one rank.') actions = (('delete', _("Delete selected"), _("Are you sure you want to delete selected ranks?")), ) def get_table_form(self, request, page_items): order_form = {} # Build choices list choices = [] for i in range(0, len(page_items)): choices.append([str(i), i + 1]) # Build selectors list position = 0 for item in page_items: order_form['pos_' + str(item.pk)] = forms.ChoiceField( choices=choices, initial=str(position)) position += 1 # Turn dict into object return type('OrderRanksForm', (Form, ), order_form) def table_action(self, request, page_items, cleaned_data): for item in page_items: item.order = cleaned_data['pos_' + str(item.pk)] item.save(force_update=True) return BasicMessage(_('Ranks order has been changed'), 'success'), reverse('admin_users_ranks') def sort_items(self, request, page_items, sorting_method): return page_items.order_by('order') def get_item_actions(self, request, item): return ( self.action('pencil', _("Edit Rank"), reverse('admin_users_ranks_edit', item)), self.action( 'remove', _("Delete Rank"), reverse('admin_users_ranks_delete', item), post=True, prompt=_("Are you sure you want to delete this rank?")), ) def action_delete(self, request, items, checked): Rank.objects.filter(id__in=checked).delete() return BasicMessage( _('Selected ranks have been deleted successfully.'), 'success'), reverse('admin_users_ranks')
class List(ListWidget): admin = site.get_action('team') id = 'list' columns = (('username', _("Team Member")), ) default_sorting = 'username_slug' hide_actions = True pagination = 50 def select_items(self, items): return items.filter(is_team=1)
class Edit(FormWidget): admin = site.get_action('users') id = 'edit' name = _("Edit User") fallback = 'admin_users' form = UserForm target_name = 'username' notfound_message = _('Requested User could not be found.') submit_fallback = True def get_form_instance(self, form, request, model, initial, post=False): if post: return form(model, request.POST, request=request, initial=self.get_initial_data(request, model)) return form(model, request=request, initial=self.get_initial_data(request, model)) def get_url(self, request, model): return reverse('admin_users_edit', model) def get_edit_url(self, request, model): return self.get_url(request, model) def get_initial_data(self, request, model): return { 'username': model.username, 'title': model.title, 'email': model.email, 'rank': model.rank, 'roles': model.roles.all(), } def submit_form(self, request, form, target): target.title = form.cleaned_data['title'] target.rank = form.cleaned_data['rank'] # Update user roles if request.user.is_god(): target.roles.clear() for role in form.cleaned_data['roles']: target.roles.add(role) else: for role in target.roles.all(): if not role.protected: target.roles.remove(role) for role in form.cleaned_data['roles']: target.roles.add(role) target.save(force_update=True) return target, BasicMessage( _('Changes in user\'s "%(name)s" account have been saved.' % {'name': self.original_name}), 'success')
class Edit(FormWidget): admin = site.get_action('ranks') id = 'edit' name = _("Edit Rank") fallback = 'admin_ranks' form = RankForm target_name = 'name' notfound_message = _('Requested Rank could not be found.') translate_target_name = True submit_fallback = True def get_link(self, model): return reverse('admin_ranks_edit', model) def get_edit_link(self, model): return self.get_link(model) def get_initial_data(self, model): return { 'name': model.name, 'description': model.description, 'style': model.style, 'title': model.title, 'special': model.special, 'as_tab': model.as_tab, 'on_index': model.on_index, 'criteria': model.criteria, 'roles': model.roles.all(), } def submit_form(self, form, target): target.name = form.cleaned_data['name'] target.slug = slugify(form.cleaned_data['name']) target.description = form.cleaned_data['description'] target.style = form.cleaned_data['style'] target.title = form.cleaned_data['title'] target.special = form.cleaned_data['special'] target.as_tab = form.cleaned_data['as_tab'] target.on_index = form.cleaned_data['on_index'] target.criteria = form.cleaned_data['criteria'] target.save(force_update=True) if self.request.user.is_god(): target.roles.clear() else: target.roles.remove(*target.roles.filter(protected=False)) for role in form.cleaned_data['roles']: target.roles.add(role) target.user_set.update(acl_key=None) return target, Message( _('Changes in rank "%(name)s" have been saved.') % {'name': self.original_name}, messages.SUCCESS)
class Delete(ButtonWidget): admin = site.get_action('newsletters') id = 'delete' fallback = 'admin_newsletters' notfound_message = _('Requested newsletter could not be found.') def action(self, target): target.delete() return Message( _('Newsletter "%(name)s"" has been deleted.') % {'name': target.name}, messages.SUCCESS), False
class Delete(ButtonWidget): admin = site.get_action('prefixes') id = 'delete' fallback = 'admin_threads_prefixes' notfound_message = _('Requested Prefix could not be found.') def action(self, target): target.delete() return Message( _('Prefix "%(name)s" has been deleted.') % {'name': _(target.name)}, messages.SUCCESS), False
class Delete(ButtonWidget): admin = site.get_action('roles_forums') id = 'delete' fallback = 'admin_roles_forums' notfound_message = _('Requested Forum Role could not be found.') def action(self, target): target.delete() self.request.monitor.increase('acl_version') return Message( _('Forum Role "%(name)s" has been deleted.') % {'name': _(target.name)}, 'success'), False
class Delete(ButtonWidget): admin = site.get_action('prune_users') id = 'delete' fallback = 'admin_prune_users' notfound_message = _('Requested pruning policy could not be found.') def action(self, target): if not self.request.user.is_god(): return Message(_('Only system administrators can delete pruning policies.'), messages.ERROR), False target.delete() return Message(_('Pruning policy "%(name)s" has been deleted.') % {'name': target.name}, messages.SUCCESS), False
class Up(ButtonWidget): admin = site.get_action('forums') id = 'up' fallback = 'admin_forums' notfound_message = _('Requested Forum could not be found.') def action(self, target): previous_sibling = target.get_previous_sibling() if previous_sibling: target.move_to(previous_sibling, 'left') return Message(_('Forum "%(name)s" has been moved up.') % {'name': target.name}, 'success'), False return Message(_('Forum "%(name)s" is first child of its parent node and cannot be moved up.') % {'name': target.name}, 'info'), False
class Down(ButtonWidget): admin = site.get_action('forums') id = 'down' fallback = 'admin_forums' notfound_message = _('Requested Forum could not be found.') def action(self, target): next_sibling = target.get_next_sibling() if next_sibling: target.move_to(next_sibling, 'right') return Message(_('Forum "%(name)s" has been moved down.') % {'name': target.name}, 'success'), False return Message(_('Forum "%(name)s" is last child of its parent node and cannot be moved down.') % {'name': target.name}, 'info'), False
class Delete(FormWidget): admin = site.get_action('forums') id = 'delete' name = _("Delete Forum") fallback = 'admin_forums' template = 'delete' form = DeleteForm target_name = 'name' notfound_message = _('Requested Forum could not be found.') submit_fallback = True def get_url(self, model): return reverse('admin_forums_delete', model) def get_form(self, target): if target.type == 'category': self.name = _("Delete Category") if target.type == 'redirect': self.name = _("Delete Redirect") return self.form def get_form_instance(self, form, target, initial, post=False): if post: form_inst = form(self.request.POST, forum=target, request=self.request, initial=self.get_initial_data(target)) else: form_inst = form(forum=target, request=self.request, initial=self.get_initial_data(target)) if target.type != 'forum': del form_inst.fields['contents'] valid_targets = Forum.objects.get(special='root').get_descendants().exclude(Q(lft__gte=target.lft) & Q(rght__lte=target.rght)) form_inst.fields['subforums'] = TreeNodeChoiceField(queryset=valid_targets, required=False, empty_label=_("Remove with forum"), level_indicator=u'- - ') return form_inst def submit_form(self, form, target): if target.type == 'forum': new_forum = form.cleaned_data['contents'] if new_forum: target.move_content(new_forum) new_forum.sync() new_forum.save(force_update=True) new_parent = form.cleaned_data['subforums'] if new_parent: for child in target.get_descendants(): if child.parent_id == target.pk: child.move_to(new_parent, 'last-child') child.save(force_update=True) else: for child in target.get_descendants().order_by('-lft'): Forum.objects.get(id=child.pk).delete() Forum.objects.get(id=target.pk).delete() Forum.objects.populate_tree(True) self.request.monitor.increase('acl_version') return target, Message(_('Forum "%(name)s" has been deleted.') % {'name': self.original_name}, 'success')
class List(ListWidget): """ List Bans """ admin = site.get_action('bans') id = 'list' columns = ( ('ban', _("Ban"), 50), ('expires', _("Expires")), ) default_sorting = 'expires' sortables = { 'ban': 1, 'expires': 0, } pagination = 20 search_form = SearchBansForm empty_message = _('No bans are currently set.') empty_search_message = _('No bans have been found.') nothing_checked_message = _('You have to check at least one ban.') actions = (('delete', _("Lift selected bans"), _("Are you sure you want to lift selected bans?")), ) def set_filters(self, model, filters): if 'ban' in filters: model = model.filter(ban__contains=filters['ban']) if 'reason' in filters: model = model.filter( Q(reason_user__contains=filters['reason']) | Q(reason_admin__contains=filters['reason'])) if 'type' in filters: model = model.filter(type__in=filters['type']) return model def get_item_actions(self, request, item): return ( self.action('pencil', _("Edit Ban"), reverse('admin_users_bans_edit', item)), self.action('remove', _("Lift Ban"), reverse('admin_users_bans_delete', item), post=True, prompt=_("Are you sure you want to lift this ban?")), ) def action_delete(self, request, items, checked): Ban.objects.filter(id__in=checked).delete() request.monitor['bans_version'] = int( request.monitor['bans_version']) + 1 return BasicMessage(_('Selected bans have been lifted successfully.'), 'success'), reverse('admin_users_bans')