Show More
@@ -0,0 +1,93 b'' | |||
|
1 | #!/usr/bin/env python | |
|
2 | # encoding: utf-8 | |
|
3 | # settings controller for pylons | |
|
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
|
5 | ||
|
6 | # This program is free software; you can redistribute it and/or | |
|
7 | # modify it under the terms of the GNU General Public License | |
|
8 | # as published by the Free Software Foundation; version 2 | |
|
9 | # of the License or (at your opinion) any later version of the license. | |
|
10 | # | |
|
11 | # This program is distributed in the hope that it will be useful, | |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
14 | # GNU General Public License for more details. | |
|
15 | # | |
|
16 | # You should have received a copy of the GNU General Public License | |
|
17 | # along with this program; if not, write to the Free Software | |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
|
19 | # MA 02110-1301, USA. | |
|
20 | """ | |
|
21 | Created on July 14, 2010 | |
|
22 | settings controller for pylons | |
|
23 | @author: marcink | |
|
24 | """ | |
|
25 | from formencode import htmlfill | |
|
26 | from pylons import request, session, tmpl_context as c, url | |
|
27 | from pylons.controllers.util import abort, redirect | |
|
28 | from pylons.i18n.translation import _ | |
|
29 | from pylons_app.lib import helpers as h | |
|
30 | from pylons_app.lib.auth import LoginRequired, HasPermissionAllDecorator | |
|
31 | from pylons_app.lib.base import BaseController, render | |
|
32 | from pylons_app.model.db import User, UserLog | |
|
33 | from pylons_app.model.forms import UserForm | |
|
34 | from pylons_app.model.user_model import UserModel | |
|
35 | import formencode | |
|
36 | import logging | |
|
37 | ||
|
38 | log = logging.getLogger(__name__) | |
|
39 | ||
|
40 | ||
|
41 | class SettingsController(BaseController): | |
|
42 | """REST Controller styled on the Atom Publishing Protocol""" | |
|
43 | # To properly map this controller, ensure your config/routing.py | |
|
44 | # file has a resource setup: | |
|
45 | # map.resource('setting', 'settings', controller='admin/settings', | |
|
46 | # path_prefix='/admin', name_prefix='admin_') | |
|
47 | ||
|
48 | ||
|
49 | @LoginRequired() | |
|
50 | #@HasPermissionAllDecorator('hg.admin') | |
|
51 | def __before__(self): | |
|
52 | c.admin_user = session.get('admin_user') | |
|
53 | c.admin_username = session.get('admin_username') | |
|
54 | super(SettingsController, self).__before__() | |
|
55 | ||
|
56 | def index(self, format='html'): | |
|
57 | """GET /admin/settings: All items in the collection""" | |
|
58 | # url('admin_settings') | |
|
59 | return render('admin/settings/settings.html') | |
|
60 | ||
|
61 | def create(self): | |
|
62 | """POST /admin/settings: Create a new item""" | |
|
63 | # url('admin_settings') | |
|
64 | ||
|
65 | def new(self, format='html'): | |
|
66 | """GET /admin/settings/new: Form to create a new item""" | |
|
67 | # url('admin_new_setting') | |
|
68 | ||
|
69 | def update(self, id): | |
|
70 | """PUT /admin/settings/id: Update an existing item""" | |
|
71 | # Forms posted to this method should contain a hidden field: | |
|
72 | # <input type="hidden" name="_method" value="PUT" /> | |
|
73 | # Or using helpers: | |
|
74 | # h.form(url('admin_setting', id=ID), | |
|
75 | # method='put') | |
|
76 | # url('admin_setting', id=ID) | |
|
77 | ||
|
78 | def delete(self, id): | |
|
79 | """DELETE /admin/settings/id: Delete an existing item""" | |
|
80 | # Forms posted to this method should contain a hidden field: | |
|
81 | # <input type="hidden" name="_method" value="DELETE" /> | |
|
82 | # Or using helpers: | |
|
83 | # h.form(url('admin_setting', id=ID), | |
|
84 | # method='delete') | |
|
85 | # url('admin_setting', id=ID) | |
|
86 | ||
|
87 | def show(self, id, format='html'): | |
|
88 | """GET /admin/settings/id: Show a specific item""" | |
|
89 | # url('admin_setting', id=ID) | |
|
90 | ||
|
91 | def edit(self, id, format='html'): | |
|
92 | """GET /admin/settings/id/edit: Form to edit an existing item""" | |
|
93 | # url('admin_edit_setting', id=ID) |
@@ -0,0 +1,21 b'' | |||
|
1 | ## -*- coding: utf-8 -*- | |
|
2 | <%inherit file="/base/base.html"/> | |
|
3 | ||
|
4 | <%def name="title()"> | |
|
5 | ${_('Settings administration')} | |
|
6 | </%def> | |
|
7 | <%def name="breadcrumbs()"> | |
|
8 | ${h.link_to(u'Admin',h.url('admin_home'))} | |
|
9 | / | |
|
10 | ${_('Settings')} | |
|
11 | </%def> | |
|
12 | <%def name="page_nav()"> | |
|
13 | ${self.menu('admin')} | |
|
14 | ${self.submenu('settings')} | |
|
15 | </%def> | |
|
16 | <%def name="main()"> | |
|
17 | <div> | |
|
18 | <h2>${_('Settings administration')}</h2> | |
|
19 | ||
|
20 | </div> | |
|
21 | </%def> |
@@ -0,0 +1,43 b'' | |||
|
1 | from pylons_app.tests import * | |
|
2 | ||
|
3 | class TestSettingsController(TestController): | |
|
4 | ||
|
5 | def test_index(self): | |
|
6 | response = self.app.get(url('admin_settings')) | |
|
7 | # Test response... | |
|
8 | ||
|
9 | def test_index_as_xml(self): | |
|
10 | response = self.app.get(url('formatted_admin_settings', format='xml')) | |
|
11 | ||
|
12 | def test_create(self): | |
|
13 | response = self.app.post(url('admin_settings')) | |
|
14 | ||
|
15 | def test_new(self): | |
|
16 | response = self.app.get(url('admin_new_setting')) | |
|
17 | ||
|
18 | def test_new_as_xml(self): | |
|
19 | response = self.app.get(url('formatted_admin_new_setting', format='xml')) | |
|
20 | ||
|
21 | def test_update(self): | |
|
22 | response = self.app.put(url('admin_setting', id=1)) | |
|
23 | ||
|
24 | def test_update_browser_fakeout(self): | |
|
25 | response = self.app.post(url('admin_setting', id=1), params=dict(_method='put')) | |
|
26 | ||
|
27 | def test_delete(self): | |
|
28 | response = self.app.delete(url('admin_setting', id=1)) | |
|
29 | ||
|
30 | def test_delete_browser_fakeout(self): | |
|
31 | response = self.app.post(url('admin_setting', id=1), params=dict(_method='delete')) | |
|
32 | ||
|
33 | def test_show(self): | |
|
34 | response = self.app.get(url('admin_setting', id=1)) | |
|
35 | ||
|
36 | def test_show_as_xml(self): | |
|
37 | response = self.app.get(url('formatted_admin_setting', id=1, format='xml')) | |
|
38 | ||
|
39 | def test_edit(self): | |
|
40 | response = self.app.get(url('admin_edit_setting', id=1)) | |
|
41 | ||
|
42 | def test_edit_as_xml(self): | |
|
43 | response = self.app.get(url('formatted_admin_edit_setting', id=1, format='xml')) |
@@ -0,0 +1,43 b'' | |||
|
1 | from pylons_app.tests import * | |
|
2 | ||
|
3 | class TestSettingsHgController(TestController): | |
|
4 | ||
|
5 | def test_index(self): | |
|
6 | response = self.app.get(url('admin_settings_hg')) | |
|
7 | # Test response... | |
|
8 | ||
|
9 | def test_index_as_xml(self): | |
|
10 | response = self.app.get(url('formatted_admin_settings_hg', format='xml')) | |
|
11 | ||
|
12 | def test_create(self): | |
|
13 | response = self.app.post(url('admin_settings_hg')) | |
|
14 | ||
|
15 | def test_new(self): | |
|
16 | response = self.app.get(url('admin_new_setting_hg')) | |
|
17 | ||
|
18 | def test_new_as_xml(self): | |
|
19 | response = self.app.get(url('formatted_admin_new_setting_hg', format='xml')) | |
|
20 | ||
|
21 | def test_update(self): | |
|
22 | response = self.app.put(url('admin_setting_hg', id=1)) | |
|
23 | ||
|
24 | def test_update_browser_fakeout(self): | |
|
25 | response = self.app.post(url('admin_setting_hg', id=1), params=dict(_method='put')) | |
|
26 | ||
|
27 | def test_delete(self): | |
|
28 | response = self.app.delete(url('admin_setting_hg', id=1)) | |
|
29 | ||
|
30 | def test_delete_browser_fakeout(self): | |
|
31 | response = self.app.post(url('admin_setting_hg', id=1), params=dict(_method='delete')) | |
|
32 | ||
|
33 | def test_show(self): | |
|
34 | response = self.app.get(url('admin_setting_hg', id=1)) | |
|
35 | ||
|
36 | def test_show_as_xml(self): | |
|
37 | response = self.app.get(url('formatted_admin_setting_hg', id=1, format='xml')) | |
|
38 | ||
|
39 | def test_edit(self): | |
|
40 | response = self.app.get(url('admin_edit_setting_hg', id=1)) | |
|
41 | ||
|
42 | def test_edit_as_xml(self): | |
|
43 | response = self.app.get(url('formatted_admin_edit_setting_hg', id=1, format='xml')) |
@@ -32,7 +32,7 b' def make_map(config):' | |||
|
32 | 32 | return not cr(repo_name, config['base_path']) |
|
33 | 33 | |
|
34 | 34 | #REST routes |
|
35 |
with map.submapper(path_prefix='/_admin', controller=' |
|
|
35 | with map.submapper(path_prefix='/_admin', controller='admin/repos') as m: | |
|
36 | 36 | m.connect("repos", "/repos", |
|
37 | 37 | action="create", conditions=dict(method=["POST"])) |
|
38 | 38 | m.connect("repos", "/repos", |
@@ -67,11 +67,12 b' def make_map(config):' | |||
|
67 | 67 | action="delete_perm_user", conditions=dict(method=["DELETE"], |
|
68 | 68 | function=check_repo)) |
|
69 | 69 | |
|
70 |
map.resource('user', 'users', controller=' |
|
|
71 |
map.resource('permission', 'permissions', controller=' |
|
|
70 | map.resource('user', 'users', controller='admin/users', path_prefix='/_admin') | |
|
71 | map.resource('permission', 'permissions', controller='admin/permissions', path_prefix='/_admin') | |
|
72 | map.resource('setting', 'settings', controller='admin/settings', path_prefix='/_admin', name_prefix='admin_') | |
|
72 | 73 | |
|
73 | 74 | #ADMIN |
|
74 |
with map.submapper(path_prefix='/_admin', controller=' |
|
|
75 | with map.submapper(path_prefix='/_admin', controller='admin/admin') as m: | |
|
75 | 76 | m.connect('admin_home', '', action='index')#main page |
|
76 | 77 | m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', |
|
77 | 78 | action='add_repo') |
@@ -15,7 +15,7 b'' | |||
|
15 | 15 | </%def> |
|
16 | 16 | <%def name="main()"> |
|
17 | 17 | <div> |
|
18 |
<h2>${_(' |
|
|
18 | <h2>${_('Users administration')}</h2> | |
|
19 | 19 | <table class="table_disp"> |
|
20 | 20 | <tr class="header"> |
|
21 | 21 | <td>${_('username')}</td> |
@@ -134,7 +134,7 b' def is_current(selected):' | |||
|
134 | 134 | <li ${is_current('repos')}>${h.link_to(_('repositories'),h.url('repos'),class_='repos')}</li> |
|
135 | 135 | <li ${is_current('users')}>${h.link_to(_('users'),h.url('users'),class_='users')}</li> |
|
136 | 136 | ##commented<li ${is_current('permissions')}>${h.link_to(_('permissions'),h.url('permissions'),class_='permissions')}</li> |
|
137 |
|
|
|
137 | <li ${is_current('settings')}>${h.link_to(_('settings'),h.url('admin_settings'),class_='settings')}</li> | |
|
138 | 138 | </ul> |
|
139 | 139 | </div> |
|
140 | 140 | %endif |
General Comments 0
You need to be logged in to leave comments.
Login now