source: tagsplugin/trunk/tractags/admin.py

Last change on this file was 18137, checked in by Cinc-th, 2 years ago

TagsPlugin: change admin template to Jinja2. Some translations are gone unfortunately.

Refs #13993

File size: 2.6 KB
RevLine 
[10639]1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2011 Itamar Ostricher <itamarost@gmail.com>
[13304]4# Copyright (C) 2011-2013 Steffen Hoffmann <hoff.st@web.de>
[10639]5#
6# This software is licensed as described in the file COPYING, which
7# you should have received as part of this distribution.
8#
9
10from trac.admin import IAdminPanelProvider
[14153]11from trac.core import Component, implements
[16943]12from trac.web.chrome import Chrome, add_warning
[14950]13
[14153]14from tractags.api import TagSystem, _
[10639]15
16
17class TagChangeAdminPanel(Component):
[13865]18    """[opt] Admin web-UI providing administrative tag system actions."""
[10639]19
20    implements(IAdminPanelProvider)
21
22    # AdminPanelProvider methods
23    def get_admin_panels(self, req):
24        if 'TAGS_ADMIN' in req.perm:
[16943]25            yield 'tags', _('Tag System'), 'replace', _('Replace')
[10639]26
27    def render_admin_panel(self, req, cat, page, version):
28        req.perm.require('TAGS_ADMIN')
[13304]29
[14153]30        tag_system = TagSystem(self.env)
31        all_realms = tag_system.get_taggable_realms(req.perm)
[13304]32        # Check request for enabled filters, or use default.
[15558]33        if not [r for r in all_realms if r in req.args]:
[14153]34            for realm in all_realms:
[13304]35                req.args[realm] = 'on'
[14153]36        checked_realms = [r for r in all_realms if r in req.args]
[13304]37        data = dict(checked_realms=checked_realms,
38                    tag_realms=list(dict(name=realm,
39                                         checked=realm in checked_realms)
[14153]40                                    for realm in all_realms))
[13304]41
[10639]42        if req.method == 'POST':
43            # Replace Tag
44            allow_delete = req.args.get('allow_delete')
45            new_tag = req.args.get('tag_new_name').strip()
[13712]46            new_tag = not new_tag == u'' and new_tag or None
[10639]47            if not (allow_delete or new_tag):
[16943]48                add_warning(req, _("Selected current tag(s) and either "
49                                   "new tag or delete approval are required"))
[10639]50            else:
51                comment = req.args.get('comment', u'')
[16943]52                old_tags = req.args.getlist('tag_name')
[10639]53                if old_tags:
54                    tag_system.replace_tag(req, old_tags, new_tag, comment,
[13304]55                                           allow_delete, filter=checked_realms)
[10639]56                data['selected'] = new_tag
[16943]57            req.redirect(req.href.admin('tags', 'replace'))
[10639]58
[16943]59        query = ' or '.join('realm:%s' % r for r in checked_realms)
[13304]60        all_tags = sorted(tag_system.get_all_tags(req, query))
[10639]61        data['tags'] = all_tags
[17050]62        chrome = Chrome(self.env)
63        chrome.add_textarea_grips(req)
[18137]64
65        return 'admin_tag_change.html', data, {'domain': 'tractags'}
Note: See TracBrowser for help on using the repository browser.