Mercurial > public > src > rhodecode
changeset 47:f6ac79182600
Added rest controllers for repos and users,
templating changes + css fixes
author | Marcin Kuzminski <marcin@python-blog.com> |
---|---|
date | Wed, 07 Apr 2010 20:19:25 +0200 |
parents | 9db7782727b3 |
children | 8e250e86a670 |
files | pylons_app/config/routing.py pylons_app/controllers/admin.py pylons_app/controllers/repos.py pylons_app/controllers/users.py pylons_app/public/hg_static/style-monoblue.css pylons_app/templates/admin.html pylons_app/templates/repos_manage.html pylons_app/templates/users_manage.html pylons_app/tests/functional/test_repos.py pylons_app/tests/functional/test_users.py |
diffstat | 10 files changed, 239 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/pylons_app/config/routing.py Wed Apr 07 19:39:31 2010 +0200 +++ b/pylons_app/config/routing.py Wed Apr 07 20:19:25 2010 +0200 @@ -22,8 +22,9 @@ 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='/')
--- a/pylons_app/controllers/admin.py Wed Apr 07 19:39:31 2010 +0200 +++ b/pylons_app/controllers/admin.py Wed Apr 07 20:19:25 2010 +0200 @@ -52,18 +52,6 @@ ) 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/controllers/repos.py Wed Apr 07 20:19:25 2010 +0200 @@ -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: + # <input type="hidden" name="_method" value="PUT" /> + # 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: + # <input type="hidden" name="_method" value="DELETE" /> + # 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)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/controllers/users.py Wed Apr 07 20:19:25 2010 +0200 @@ -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: + # <input type="hidden" name="_method" value="PUT" /> + # 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: + # <input type="hidden" name="_method" value="DELETE" /> + # 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)
--- a/pylons_app/public/hg_static/style-monoblue.css Wed Apr 07 19:39:31 2010 +0200 +++ b/pylons_app/public/hg_static/style-monoblue.css Wed Apr 07 20:19:25 2010 +0200 @@ -146,7 +146,9 @@ font-size: 1.2em; display: inline; } - +ul.submenu li.current_submenu { + border-bottom: 2px solid #006699; +} h2 { margin: 20px 0 10px; height: 30px;
--- a/pylons_app/templates/admin.html Wed Apr 07 19:39:31 2010 +0200 +++ b/pylons_app/templates/admin.html Wed Apr 07 20:19:25 2010 +0200 @@ -25,10 +25,10 @@ %if c.admin_user: <ul class="submenu"> <li> - ${h.link_to(u'Repos managment',h.url('admin_repos_manage'))} + ${h.link_to(u'Repos',h.url('repos'))} </li> <li> - ${h.link_to(u'Users managment',h.url('admin_users_manage'))} + ${h.link_to(u'Users',h.url('users'))} </li> </ul> <br/>
--- a/pylons_app/templates/repos_manage.html Wed Apr 07 19:39:31 2010 +0200 +++ b/pylons_app/templates/repos_manage.html Wed Apr 07 20:19:25 2010 +0200 @@ -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> <%def name="page_nav()"> <li>${h.link_to(u'Home',h.url('/'))}</li> <li class="current">${_('Admin')}</li> </%def> <%def name="main()"> - - -<div class="twocol-form"> - <h2>Create new repository</h2> - <form method="post" action="/repo/create/"> - <table> - <tbody><tr><th><label for="id_name">Name:</label></th><td><input type="text" maxlength="255" name="name" id="id_name"></td></tr> -<tr><th><label for="id_description">Description:</label></th><td><textarea name="description" cols="40" rows="10" id="id_description"></textarea></td></tr> -<tr><th><label for="id_website">Website:</label></th><td><input type="text" maxlength="128" name="website" id="id_website"></td></tr> -<tr><th><label for="id_is_private">Private:</label></th><td><input type="checkbox" id="id_is_private" name="is_private"></td></tr> -<tr><th><label for="id_has_issues">Issue tracking:</label></th><td><input type="checkbox" id="id_has_issues" name="has_issues" checked="checked"></td></tr> -<tr><th><label for="id_has_wiki">Wiki:</label></th><td><input type="checkbox" id="id_has_wiki" name="has_wiki" checked="checked"></td></tr> - - - <tr><td colspan="2"> </td></tr> - <tr> - <td colspan="2"> - <input type="submit" class="primary-button" value="Create repository"> <input type="reset" onclick="document.location='http://bitbucket.org/';" class="secondary-button secondary-button-darkbg" value="Cancel"> - </td> - </tr> - </tbody></table> - </form> + <ul class="submenu"> + <li class="current_submenu"> + ${h.link_to(u'Repos',h.url('repos'))} + </li> + <li> + ${h.link_to(u'Users',h.url('users'))} + </li> + </ul> + <div> + <h2>${_('Mercurial repos')}</h2> </div> </%def> \ No newline at end of file
--- a/pylons_app/templates/users_manage.html Wed Apr 07 19:39:31 2010 +0200 +++ b/pylons_app/templates/users_manage.html Wed Apr 07 20:19:25 2010 +0200 @@ -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> <%def name="page_nav()"> <li>${h.link_to(u'Home',h.url('/'))}</li> <li class="current">${_('Admin')}</li> </%def> <%def name="main()"> - + <ul class="submenu"> + <li> + ${h.link_to(u'Repos',h.url('repos'))} + </li> + <li class="current_submenu"> + ${h.link_to(u'Users',h.url('users'))} + </li> + </ul> + <div> + <h2>${_('Mercurial users')}</h2> <table cellspacing="0"> <tr> <th>Id</th> <th>Username</th> <th>Password</th> <th>Active</th> - </tr> + <th>Admin</th> + </tr> %for i in c.users_list: <tr> <td>${i[0]}</td> <td>${i[1]}</td> <td>${i[2]}</td> <td>${i[3]}</td> + <td>${i[4]}</td> </tr> %endfor - </table> + </table> + </div> + </%def> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/tests/functional/test_repos.py Wed Apr 07 20:19:25 2010 +0200 @@ -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'))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/tests/functional/test_users.py Wed Apr 07 20:19:25 2010 +0200 @@ -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'))