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 @@ -22,8 +22,9 @@ def make_map(config): with map.submapper(path_prefix='/_admin', controller='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') - m.connect('admin_users_manage', '/repos_manage', action='users_manage') - m.connect('admin_repos_manage', '/users_manage', action='repos_manage') + + map.resource('repo', 'repos', path_prefix='/_admin') + map.resource('user', 'users', path_prefix='/_admin') map.connect('hg', '/{path_info:.*}', controller='hg', action="view", path_info='/') diff --git a/pylons_app/controllers/admin.py b/pylons_app/controllers/admin.py --- a/pylons_app/controllers/admin.py +++ b/pylons_app/controllers/admin.py @@ -52,18 +52,6 @@ class AdminController(BaseController): ) return render('/admin.html') - def repos_manage(self): - return render('/repos_manage.html') - - def users_manage(self): - conn, cur = auth.get_sqlite_conn_cur() - cur.execute('SELECT * FROM users') - c.users_list = cur.fetchall() - return render('/users_manage.html') - - def manage_hgrc(self): - pass - def hgrc(self, dirname): filename = os.path.join(dirname, '.hg', 'hgrc') return filename diff --git a/pylons_app/controllers/repos.py b/pylons_app/controllers/repos.py new file mode 100644 --- /dev/null +++ b/pylons_app/controllers/repos.py @@ -0,0 +1,57 @@ +import logging + +from pylons import request, response, session, tmpl_context as c, url, app_globals as g +from pylons.controllers.util import abort, redirect +from pylons_app.lib import auth +from pylons_app.lib.base import BaseController, render + +log = logging.getLogger(__name__) + +class ReposController(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('repo', 'repos') + def __before__(self): + c.staticurl = g.statics + c.admin_user = session.get('admin_user') + c.admin_username = session.get('admin_username') + + def index(self, format='html'): + """GET /repos: All items in the collection""" + # url('repos') + return render('/repos_manage.html') + + def create(self): + """POST /repos: Create a new item""" + # url('repos') + + def new(self, format='html'): + """GET /repos/new: Form to create a new item""" + # url('new_repo') + + def update(self, id): + """PUT /repos/id: Update an existing item""" + # Forms posted to this method should contain a hidden field: + # + # Or using helpers: + # h.form(url('repo', id=ID), + # method='put') + # url('repo', id=ID) + + def delete(self, id): + """DELETE /repos/id: Delete an existing item""" + # Forms posted to this method should contain a hidden field: + # + # Or using helpers: + # h.form(url('repo', id=ID), + # method='delete') + # url('repo', id=ID) + + def show(self, id, format='html'): + """GET /repos/id: Show a specific item""" + # url('repo', id=ID) + + def edit(self, id, format='html'): + """GET /repos/id/edit: Form to edit an existing item""" + # url('edit_repo', id=ID) diff --git a/pylons_app/controllers/users.py b/pylons_app/controllers/users.py new file mode 100644 --- /dev/null +++ b/pylons_app/controllers/users.py @@ -0,0 +1,60 @@ +import logging + +from pylons import request, response, session, tmpl_context as c, url, app_globals as g +from pylons.controllers.util import abort, redirect + +from pylons_app.lib.base import BaseController, render +from pylons_app.lib import auth +log = logging.getLogger(__name__) + +class UsersController(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('user', 'users') + def __before__(self): + c.staticurl = g.statics + c.admin_user = session.get('admin_user') + c.admin_username = session.get('admin_username') + + def index(self, format='html'): + """GET /users: All items in the collection""" + # url('users') + conn, cur = auth.get_sqlite_conn_cur() + cur.execute('SELECT * FROM users') + c.users_list = cur.fetchall() + return render('/users_manage.html') + + def create(self): + """POST /users: Create a new item""" + # url('users') + + def new(self, format='html'): + """GET /users/new: Form to create a new item""" + # url('new_user') + + def update(self, id): + """PUT /users/id: Update an existing item""" + # Forms posted to this method should contain a hidden field: + # + # Or using helpers: + # h.form(url('user', id=ID), + # method='put') + # url('user', id=ID) + + def delete(self, id): + """DELETE /users/id: Delete an existing item""" + # Forms posted to this method should contain a hidden field: + # + # Or using helpers: + # h.form(url('user', id=ID), + # method='delete') + # url('user', id=ID) + + def show(self, id, format='html'): + """GET /users/id: Show a specific item""" + # url('user', id=ID) + + def edit(self, id, format='html'): + """GET /users/id/edit: Form to edit an existing item""" + # url('edit_user', id=ID) diff --git a/pylons_app/public/hg_static/style-monoblue.css b/pylons_app/public/hg_static/style-monoblue.css --- a/pylons_app/public/hg_static/style-monoblue.css +++ b/pylons_app/public/hg_static/style-monoblue.css @@ -146,7 +146,9 @@ ul.submenu li { font-size: 1.2em; display: inline; } - +ul.submenu li.current_submenu { + border-bottom: 2px solid #006699; +} h2 { margin: 20px 0 10px; height: 30px; diff --git a/pylons_app/templates/admin.html b/pylons_app/templates/admin.html --- a/pylons_app/templates/admin.html +++ b/pylons_app/templates/admin.html @@ -25,10 +25,10 @@ %if c.admin_user:
diff --git a/pylons_app/templates/repos_manage.html b/pylons_app/templates/repos_manage.html --- a/pylons_app/templates/repos_manage.html +++ b/pylons_app/templates/repos_manage.html @@ -7,34 +7,22 @@ / ${h.link_to(u'Admin',h.url('admin_home'))} / - ${h.link_to(u'Repos managment',h.url('admin_repos_manage'))} + ${h.link_to(u'Repos managment',h.url('repos'))} <%def name="page_nav()">
  • ${h.link_to(u'Home',h.url('/'))}
  • ${_('Admin')}
  • <%def name="main()"> - - -
    -

    Create new repository

    -
    - - - - - - - - - - - - - -
     
    - -
    -
    + +
    +

    ${_('Mercurial repos')}

    \ No newline at end of file diff --git a/pylons_app/templates/users_manage.html b/pylons_app/templates/users_manage.html --- a/pylons_app/templates/users_manage.html +++ b/pylons_app/templates/users_manage.html @@ -7,28 +7,41 @@ / ${h.link_to(u'Admin',h.url('admin_home'))} / - ${h.link_to(u'Users managment',h.url('admin_users_manage'))} + ${h.link_to(u'Users managment',h.url('users'))} <%def name="page_nav()">
  • ${h.link_to(u'Home',h.url('/'))}
  • ${_('Admin')}
  • <%def name="main()"> - + +
    +

    ${_('Mercurial users')}

    - + + %for i in c.users_list: + %endfor -
    Id Username Password Active
    Admin
    ${i[0]} ${i[1]} ${i[2]} ${i[3]}${i[4]}
    + +
    + \ No newline at end of file diff --git a/pylons_app/tests/functional/test_repos.py b/pylons_app/tests/functional/test_repos.py new file mode 100644 --- /dev/null +++ b/pylons_app/tests/functional/test_repos.py @@ -0,0 +1,43 @@ +from pylons_app.tests import * + +class TestReposController(TestController): + + def test_index(self): + response = self.app.get(url('repos')) + # Test response... + + def test_index_as_xml(self): + response = self.app.get(url('formatted_repos', format='xml')) + + def test_create(self): + response = self.app.post(url('repos')) + + def test_new(self): + response = self.app.get(url('new_repo')) + + def test_new_as_xml(self): + response = self.app.get(url('formatted_new_repo', format='xml')) + + def test_update(self): + response = self.app.put(url('repo', id=1)) + + def test_update_browser_fakeout(self): + response = self.app.post(url('repo', id=1), params=dict(_method='put')) + + def test_delete(self): + response = self.app.delete(url('repo', id=1)) + + def test_delete_browser_fakeout(self): + response = self.app.post(url('repo', id=1), params=dict(_method='delete')) + + def test_show(self): + response = self.app.get(url('repo', id=1)) + + def test_show_as_xml(self): + response = self.app.get(url('formatted_repo', id=1, format='xml')) + + def test_edit(self): + response = self.app.get(url('edit_repo', id=1)) + + def test_edit_as_xml(self): + response = self.app.get(url('formatted_edit_repo', id=1, format='xml')) diff --git a/pylons_app/tests/functional/test_users.py b/pylons_app/tests/functional/test_users.py new file mode 100644 --- /dev/null +++ b/pylons_app/tests/functional/test_users.py @@ -0,0 +1,43 @@ +from pylons_app.tests import * + +class TestUsersController(TestController): + + def test_index(self): + response = self.app.get(url('users')) + # Test response... + + def test_index_as_xml(self): + response = self.app.get(url('formatted_users', format='xml')) + + def test_create(self): + response = self.app.post(url('users')) + + def test_new(self): + response = self.app.get(url('new_user')) + + def test_new_as_xml(self): + response = self.app.get(url('formatted_new_user', format='xml')) + + def test_update(self): + response = self.app.put(url('user', id=1)) + + def test_update_browser_fakeout(self): + response = self.app.post(url('user', id=1), params=dict(_method='put')) + + def test_delete(self): + response = self.app.delete(url('user', id=1)) + + def test_delete_browser_fakeout(self): + response = self.app.post(url('user', id=1), params=dict(_method='delete')) + + def test_show(self): + response = self.app.get(url('user', id=1)) + + def test_show_as_xml(self): + response = self.app.get(url('formatted_user', id=1, format='xml')) + + def test_edit(self): + response = self.app.get(url('edit_user', id=1)) + + def test_edit_as_xml(self): + response = self.app.get(url('formatted_edit_user', id=1, format='xml'))