source: worklogplugin/trunk/worklog/admin.py

Last change on this file was 15698, checked in by Ryan J Ollos, 7 years ago

1.0dev: Add file headers

Refs #12845.

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (c) 2007-2012 Colin Guthrie <trac@colin.guthr.ie>
4# Copyright (c) 2011-2016 Ryan J Ollos <ryan.j.ollos@gmail.com>
5# All rights reserved.
6#
7# This software is licensed as described in the file COPYING, which
8# you should have received as part of this distribution.
9
10from trac.admin.api import IAdminPanelProvider
11from trac.core import Component, implements
12from trac.web.chrome import add_notice
13from trac.util.translation import _
14
15
16class WorklogAdminPanel(Component):
17    implements(IAdminPanelProvider)
18
19    # IAdminPanelProvider methods
20
21    def get_admin_panels(self, req):
22        if 'WORK_ADMIN' in req.perm:
23            yield ('ticket', _("Ticket System"), 'worklog', _("Work Log"))
24
25    def render_admin_panel(self, req, category, page, path_info):
26        req.perm.require('WORK_ADMIN')
27
28        settings = ('autostop', 'autostopstart', 'autoreassignaccept',
29                    'comment', 'timingandestimation', 'trachoursplugin')
30
31        if req.method == 'POST' and 'update' in req.args:
32            for field in settings:
33                if field in req.args:
34                    self.config.set('worklog', field, True)
35                else:
36                    self.config.set('worklog', field, False)
37                roundup = 1
38                if 'roundup' in req.args:
39                    try:
40                        if int(req.args.get('roundup')) > 0:
41                            roundup = int(req.args.get('roundup'))
42                    except:
43                        pass
44                self.config.set('worklog', 'roundup', roundup)
45
46            self.config.save()
47            add_notice(req, _("Changes have been saved."))
48
49        data = {'view': 'settings'}
50        for field in settings:
51            if self.config.getbool('worklog', field):
52                data[field] = 'checked'
53
54        if self.config.getint('worklog', 'roundup'):
55            data['roundup'] = self.config.getint('worklog', 'roundup')
56
57        return 'worklog_admin.html', data
Note: See TracBrowser for help on using the repository browser.