comparison pylons_app/controllers/admin/settings.py @ 346:51362853ac3b

added settings rest controllers for admin, updated routes with easier submodule handling
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 14 Jul 2010 13:30:31 +0200
parents
children e8fc875467bd
comparison
equal deleted inserted replaced
345:bb8f45f6d8f9 346:51362853ac3b
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)