diff --git a/pylons_app/config/routing.py b/pylons_app/config/routing.py --- a/pylons_app/config/routing.py +++ b/pylons_app/config/routing.py @@ -32,7 +32,7 @@ def make_map(config): return not cr(repo_name, config['base_path']) #REST routes - with map.submapper(path_prefix='/_admin', controller='pylons_app.controllers.admin.repos:ReposController') as m: + with map.submapper(path_prefix='/_admin', controller='admin/repos') as m: m.connect("repos", "/repos", action="create", conditions=dict(method=["POST"])) m.connect("repos", "/repos", @@ -67,11 +67,12 @@ def make_map(config): action="delete_perm_user", conditions=dict(method=["DELETE"], function=check_repo)) - map.resource('user', 'users', controller='pylons_app.controllers.admin.users:UsersController', path_prefix='/_admin') - map.resource('permission', 'permissions', controller='pylons_app.controllers.admin.permissions:PermissionsController', path_prefix='/_admin') + map.resource('user', 'users', controller='admin/users', path_prefix='/_admin') + map.resource('permission', 'permissions', controller='admin/permissions', path_prefix='/_admin') + map.resource('setting', 'settings', controller='admin/settings', path_prefix='/_admin', name_prefix='admin_') #ADMIN - with map.submapper(path_prefix='/_admin', controller='pylons_app.controllers.admin.admin:AdminController') as m: + with map.submapper(path_prefix='/_admin', controller='admin/admin') as m: m.connect('admin_home', '', action='index')#main page m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', action='add_repo') diff --git a/pylons_app/controllers/admin/settings.py b/pylons_app/controllers/admin/settings.py new file mode 100644 --- /dev/null +++ b/pylons_app/controllers/admin/settings.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# encoding: utf-8 +# settings controller for pylons +# Copyright (C) 2009-2010 Marcin Kuzminski + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; version 2 +# of the License or (at your opinion) any later version of the license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +""" +Created on July 14, 2010 +settings controller for pylons +@author: marcink +""" +from formencode import htmlfill +from pylons import request, session, tmpl_context as c, url +from pylons.controllers.util import abort, redirect +from pylons.i18n.translation import _ +from pylons_app.lib import helpers as h +from pylons_app.lib.auth import LoginRequired, HasPermissionAllDecorator +from pylons_app.lib.base import BaseController, render +from pylons_app.model.db import User, UserLog +from pylons_app.model.forms import UserForm +from pylons_app.model.user_model import UserModel +import formencode +import logging + +log = logging.getLogger(__name__) + + +class SettingsController(BaseController): + """REST Controller styled on the Atom Publishing Protocol""" + # To properly map this controller, ensure your config/routing.py + # file has a resource setup: + # map.resource('setting', 'settings', controller='admin/settings', + # path_prefix='/admin', name_prefix='admin_') + + + @LoginRequired() + #@HasPermissionAllDecorator('hg.admin') + def __before__(self): + c.admin_user = session.get('admin_user') + c.admin_username = session.get('admin_username') + super(SettingsController, self).__before__() + + def index(self, format='html'): + """GET /admin/settings: All items in the collection""" + # url('admin_settings') + return render('admin/settings/settings.html') + + def create(self): + """POST /admin/settings: Create a new item""" + # url('admin_settings') + + def new(self, format='html'): + """GET /admin/settings/new: Form to create a new item""" + # url('admin_new_setting') + + def update(self, id): + """PUT /admin/settings/id: Update an existing item""" + # Forms posted to this method should contain a hidden field: + # + # Or using helpers: + # h.form(url('admin_setting', id=ID), + # method='put') + # url('admin_setting', id=ID) + + def delete(self, id): + """DELETE /admin/settings/id: Delete an existing item""" + # Forms posted to this method should contain a hidden field: + # + # Or using helpers: + # h.form(url('admin_setting', id=ID), + # method='delete') + # url('admin_setting', id=ID) + + def show(self, id, format='html'): + """GET /admin/settings/id: Show a specific item""" + # url('admin_setting', id=ID) + + def edit(self, id, format='html'): + """GET /admin/settings/id/edit: Form to edit an existing item""" + # url('admin_edit_setting', id=ID) diff --git a/pylons_app/templates/admin/settings/settings.html b/pylons_app/templates/admin/settings/settings.html new file mode 100644 --- /dev/null +++ b/pylons_app/templates/admin/settings/settings.html @@ -0,0 +1,21 @@ +## -*- coding: utf-8 -*- +<%inherit file="/base/base.html"/> + +<%def name="title()"> + ${_('Settings administration')} + +<%def name="breadcrumbs()"> + ${h.link_to(u'Admin',h.url('admin_home'))} + / + ${_('Settings')} + +<%def name="page_nav()"> + ${self.menu('admin')} + ${self.submenu('settings')} + +<%def name="main()"> +
+

${_('Settings administration')}

+ +
+ diff --git a/pylons_app/templates/admin/users/users.html b/pylons_app/templates/admin/users/users.html --- a/pylons_app/templates/admin/users/users.html +++ b/pylons_app/templates/admin/users/users.html @@ -15,7 +15,7 @@ <%def name="main()">
-

${_('Mercurial users')}

+

${_('Users administration')}

diff --git a/pylons_app/templates/base/base.html b/pylons_app/templates/base/base.html --- a/pylons_app/templates/base/base.html +++ b/pylons_app/templates/base/base.html @@ -134,7 +134,7 @@ def is_current(selected):
  • ${h.link_to(_('repositories'),h.url('repos'),class_='repos')}
  • ${h.link_to(_('users'),h.url('users'),class_='users')}
  • ##commented
  • ${h.link_to(_('permissions'),h.url('permissions'),class_='permissions')}
  • - ##commented
  • ${h.link_to(_('settings'),h.url('hgapp_settings'),class_='settings')}
  • +
  • ${h.link_to(_('settings'),h.url('admin_settings'),class_='settings')}
  • %endif diff --git a/pylons_app/tests/functional/test_admin_settings.py b/pylons_app/tests/functional/test_admin_settings.py new file mode 100644 --- /dev/null +++ b/pylons_app/tests/functional/test_admin_settings.py @@ -0,0 +1,43 @@ +from pylons_app.tests import * + +class TestSettingsController(TestController): + + def test_index(self): + response = self.app.get(url('admin_settings')) + # Test response... + + def test_index_as_xml(self): + response = self.app.get(url('formatted_admin_settings', format='xml')) + + def test_create(self): + response = self.app.post(url('admin_settings')) + + def test_new(self): + response = self.app.get(url('admin_new_setting')) + + def test_new_as_xml(self): + response = self.app.get(url('formatted_admin_new_setting', format='xml')) + + def test_update(self): + response = self.app.put(url('admin_setting', id=1)) + + def test_update_browser_fakeout(self): + response = self.app.post(url('admin_setting', id=1), params=dict(_method='put')) + + def test_delete(self): + response = self.app.delete(url('admin_setting', id=1)) + + def test_delete_browser_fakeout(self): + response = self.app.post(url('admin_setting', id=1), params=dict(_method='delete')) + + def test_show(self): + response = self.app.get(url('admin_setting', id=1)) + + def test_show_as_xml(self): + response = self.app.get(url('formatted_admin_setting', id=1, format='xml')) + + def test_edit(self): + response = self.app.get(url('admin_edit_setting', id=1)) + + def test_edit_as_xml(self): + response = self.app.get(url('formatted_admin_edit_setting', id=1, format='xml')) diff --git a/pylons_app/tests/functional/test_admin_settings_hg.py b/pylons_app/tests/functional/test_admin_settings_hg.py new file mode 100644 --- /dev/null +++ b/pylons_app/tests/functional/test_admin_settings_hg.py @@ -0,0 +1,43 @@ +from pylons_app.tests import * + +class TestSettingsHgController(TestController): + + def test_index(self): + response = self.app.get(url('admin_settings_hg')) + # Test response... + + def test_index_as_xml(self): + response = self.app.get(url('formatted_admin_settings_hg', format='xml')) + + def test_create(self): + response = self.app.post(url('admin_settings_hg')) + + def test_new(self): + response = self.app.get(url('admin_new_setting_hg')) + + def test_new_as_xml(self): + response = self.app.get(url('formatted_admin_new_setting_hg', format='xml')) + + def test_update(self): + response = self.app.put(url('admin_setting_hg', id=1)) + + def test_update_browser_fakeout(self): + response = self.app.post(url('admin_setting_hg', id=1), params=dict(_method='put')) + + def test_delete(self): + response = self.app.delete(url('admin_setting_hg', id=1)) + + def test_delete_browser_fakeout(self): + response = self.app.post(url('admin_setting_hg', id=1), params=dict(_method='delete')) + + def test_show(self): + response = self.app.get(url('admin_setting_hg', id=1)) + + def test_show_as_xml(self): + response = self.app.get(url('formatted_admin_setting_hg', id=1, format='xml')) + + def test_edit(self): + response = self.app.get(url('admin_edit_setting_hg', id=1)) + + def test_edit_as_xml(self): + response = self.app.get(url('formatted_admin_edit_setting_hg', id=1, format='xml'))
    ${_('username')}