39
|
1 # -*- coding: utf-8 -*-
|
|
2 #
|
|
3 # Copyright (C) 2004-2005 Edgewall Software
|
|
4 # Copyright (C) 2004-2005 Daniel Lundin <daniel@edgewall.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. The terms
|
|
9 # are also available at http://trac.edgewall.com/license.html.
|
|
10 #
|
|
11 # This software consists of voluntary contributions made by many
|
|
12 # individuals. For exact contribution history, see the revision
|
|
13 # history and logs, available at http://projects.edgewall.com/trac/.
|
|
14 #
|
|
15 # Author: Daniel Lundin <daniel@edgewall.com>
|
|
16
|
|
17 from trac.core import *
|
|
18 from trac.util.markup import html
|
|
19 from trac.web import IRequestHandler
|
|
20 from trac.web.chrome import INavigationContributor
|
|
21
|
|
22
|
|
23 class SettingsModule(Component):
|
|
24
|
|
25 implements(INavigationContributor, IRequestHandler)
|
|
26
|
|
27 _form_fields = ['newsid','name', 'email']
|
|
28
|
|
29 # INavigationContributor methods
|
|
30
|
|
31 def get_active_navigation_item(self, req):
|
|
32 return 'settings'
|
|
33
|
|
34 def get_navigation_items(self, req):
|
|
35 yield ('metanav', 'settings',
|
|
36 html.A('Settings', href=req.href.settings()))
|
|
37
|
|
38 # IRequestHandler methods
|
|
39
|
|
40 def match_request(self, req):
|
|
41 return req.path_info == '/settings'
|
|
42
|
|
43 def process_request(self, req):
|
|
44 action = req.args.get('action')
|
|
45
|
|
46 if req.method == 'POST':
|
|
47 if action == 'save':
|
|
48 self._do_save(req)
|
|
49 elif action == 'load':
|
|
50 self._do_load(req)
|
|
51
|
|
52 req.hdf['title'] = 'Settings'
|
|
53 req.hdf['settings'] = req.session
|
|
54 if req.authname == 'anonymous':
|
|
55 req.hdf['settings.session_id'] = req.session.sid
|
|
56
|
|
57 return 'settings.cs', None
|
|
58
|
|
59 # Internal methods
|
|
60
|
|
61 def _do_save(self, req):
|
|
62 for field in self._form_fields:
|
|
63 val = req.args.get(field)
|
|
64 if val:
|
|
65 if field == 'newsid' and val:
|
|
66 req.session.change_sid(val)
|
|
67 else:
|
|
68 req.session[field] = val
|
|
69 req.redirect(req.href.settings())
|
|
70
|
|
71 def _do_load(self, req):
|
|
72 if req.authname == 'anonymous':
|
|
73 oldsid = req.args.get('loadsid')
|
|
74 req.session.get_session(oldsid)
|
|
75 req.redirect(req.href.settings())
|