##// END OF EJS Templates
Added rest controllers for repos and users,...
Marcin Kuzminski -
r47:f6ac7918 default
parent child Browse files
Show More
@@ -0,0 +1,57 b''
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, url, app_globals as g
4 from pylons.controllers.util import abort, redirect
5 from pylons_app.lib import auth
6 from pylons_app.lib.base import BaseController, render
7
8 log = logging.getLogger(__name__)
9
10 class ReposController(BaseController):
11 """REST Controller styled on the Atom Publishing Protocol"""
12 # To properly map this controller, ensure your config/routing.py
13 # file has a resource setup:
14 # map.resource('repo', 'repos')
15 def __before__(self):
16 c.staticurl = g.statics
17 c.admin_user = session.get('admin_user')
18 c.admin_username = session.get('admin_username')
19
20 def index(self, format='html'):
21 """GET /repos: All items in the collection"""
22 # url('repos')
23 return render('/repos_manage.html')
24
25 def create(self):
26 """POST /repos: Create a new item"""
27 # url('repos')
28
29 def new(self, format='html'):
30 """GET /repos/new: Form to create a new item"""
31 # url('new_repo')
32
33 def update(self, id):
34 """PUT /repos/id: Update an existing item"""
35 # Forms posted to this method should contain a hidden field:
36 # <input type="hidden" name="_method" value="PUT" />
37 # Or using helpers:
38 # h.form(url('repo', id=ID),
39 # method='put')
40 # url('repo', id=ID)
41
42 def delete(self, id):
43 """DELETE /repos/id: Delete an existing item"""
44 # Forms posted to this method should contain a hidden field:
45 # <input type="hidden" name="_method" value="DELETE" />
46 # Or using helpers:
47 # h.form(url('repo', id=ID),
48 # method='delete')
49 # url('repo', id=ID)
50
51 def show(self, id, format='html'):
52 """GET /repos/id: Show a specific item"""
53 # url('repo', id=ID)
54
55 def edit(self, id, format='html'):
56 """GET /repos/id/edit: Form to edit an existing item"""
57 # url('edit_repo', id=ID)
@@ -0,0 +1,60 b''
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, url, app_globals as g
4 from pylons.controllers.util import abort, redirect
5
6 from pylons_app.lib.base import BaseController, render
7 from pylons_app.lib import auth
8 log = logging.getLogger(__name__)
9
10 class UsersController(BaseController):
11 """REST Controller styled on the Atom Publishing Protocol"""
12 # To properly map this controller, ensure your config/routing.py
13 # file has a resource setup:
14 # map.resource('user', 'users')
15 def __before__(self):
16 c.staticurl = g.statics
17 c.admin_user = session.get('admin_user')
18 c.admin_username = session.get('admin_username')
19
20 def index(self, format='html'):
21 """GET /users: All items in the collection"""
22 # url('users')
23 conn, cur = auth.get_sqlite_conn_cur()
24 cur.execute('SELECT * FROM users')
25 c.users_list = cur.fetchall()
26 return render('/users_manage.html')
27
28 def create(self):
29 """POST /users: Create a new item"""
30 # url('users')
31
32 def new(self, format='html'):
33 """GET /users/new: Form to create a new item"""
34 # url('new_user')
35
36 def update(self, id):
37 """PUT /users/id: Update an existing item"""
38 # Forms posted to this method should contain a hidden field:
39 # <input type="hidden" name="_method" value="PUT" />
40 # Or using helpers:
41 # h.form(url('user', id=ID),
42 # method='put')
43 # url('user', id=ID)
44
45 def delete(self, id):
46 """DELETE /users/id: Delete an existing item"""
47 # Forms posted to this method should contain a hidden field:
48 # <input type="hidden" name="_method" value="DELETE" />
49 # Or using helpers:
50 # h.form(url('user', id=ID),
51 # method='delete')
52 # url('user', id=ID)
53
54 def show(self, id, format='html'):
55 """GET /users/id: Show a specific item"""
56 # url('user', id=ID)
57
58 def edit(self, id, format='html'):
59 """GET /users/id/edit: Form to edit an existing item"""
60 # url('edit_user', id=ID)
@@ -0,0 +1,43 b''
1 from pylons_app.tests import *
2
3 class TestReposController(TestController):
4
5 def test_index(self):
6 response = self.app.get(url('repos'))
7 # Test response...
8
9 def test_index_as_xml(self):
10 response = self.app.get(url('formatted_repos', format='xml'))
11
12 def test_create(self):
13 response = self.app.post(url('repos'))
14
15 def test_new(self):
16 response = self.app.get(url('new_repo'))
17
18 def test_new_as_xml(self):
19 response = self.app.get(url('formatted_new_repo', format='xml'))
20
21 def test_update(self):
22 response = self.app.put(url('repo', id=1))
23
24 def test_update_browser_fakeout(self):
25 response = self.app.post(url('repo', id=1), params=dict(_method='put'))
26
27 def test_delete(self):
28 response = self.app.delete(url('repo', id=1))
29
30 def test_delete_browser_fakeout(self):
31 response = self.app.post(url('repo', id=1), params=dict(_method='delete'))
32
33 def test_show(self):
34 response = self.app.get(url('repo', id=1))
35
36 def test_show_as_xml(self):
37 response = self.app.get(url('formatted_repo', id=1, format='xml'))
38
39 def test_edit(self):
40 response = self.app.get(url('edit_repo', id=1))
41
42 def test_edit_as_xml(self):
43 response = self.app.get(url('formatted_edit_repo', id=1, format='xml'))
@@ -0,0 +1,43 b''
1 from pylons_app.tests import *
2
3 class TestUsersController(TestController):
4
5 def test_index(self):
6 response = self.app.get(url('users'))
7 # Test response...
8
9 def test_index_as_xml(self):
10 response = self.app.get(url('formatted_users', format='xml'))
11
12 def test_create(self):
13 response = self.app.post(url('users'))
14
15 def test_new(self):
16 response = self.app.get(url('new_user'))
17
18 def test_new_as_xml(self):
19 response = self.app.get(url('formatted_new_user', format='xml'))
20
21 def test_update(self):
22 response = self.app.put(url('user', id=1))
23
24 def test_update_browser_fakeout(self):
25 response = self.app.post(url('user', id=1), params=dict(_method='put'))
26
27 def test_delete(self):
28 response = self.app.delete(url('user', id=1))
29
30 def test_delete_browser_fakeout(self):
31 response = self.app.post(url('user', id=1), params=dict(_method='delete'))
32
33 def test_show(self):
34 response = self.app.get(url('user', id=1))
35
36 def test_show_as_xml(self):
37 response = self.app.get(url('formatted_user', id=1, format='xml'))
38
39 def test_edit(self):
40 response = self.app.get(url('edit_user', id=1))
41
42 def test_edit_as_xml(self):
43 response = self.app.get(url('formatted_edit_user', id=1, format='xml'))
@@ -22,8 +22,9 b' def make_map(config):'
22 with map.submapper(path_prefix='/_admin', controller='admin') as m:
22 with map.submapper(path_prefix='/_admin', controller='admin') as m:
23 m.connect('admin_home', '/', action='index')#main page
23 m.connect('admin_home', '/', action='index')#main page
24 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', action='add_repo')
24 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', action='add_repo')
25 m.connect('admin_users_manage', '/repos_manage', action='users_manage')
25
26 m.connect('admin_repos_manage', '/users_manage', action='repos_manage')
26 map.resource('repo', 'repos', path_prefix='/_admin')
27 map.resource('user', 'users', path_prefix='/_admin')
27
28
28 map.connect('hg', '/{path_info:.*}', controller='hg',
29 map.connect('hg', '/{path_info:.*}', controller='hg',
29 action="view", path_info='/')
30 action="view", path_info='/')
@@ -52,18 +52,6 b' class AdminController(BaseController):'
52 )
52 )
53 return render('/admin.html')
53 return render('/admin.html')
54
54
55 def repos_manage(self):
56 return render('/repos_manage.html')
57
58 def users_manage(self):
59 conn, cur = auth.get_sqlite_conn_cur()
60 cur.execute('SELECT * FROM users')
61 c.users_list = cur.fetchall()
62 return render('/users_manage.html')
63
64 def manage_hgrc(self):
65 pass
66
67 def hgrc(self, dirname):
55 def hgrc(self, dirname):
68 filename = os.path.join(dirname, '.hg', 'hgrc')
56 filename = os.path.join(dirname, '.hg', 'hgrc')
69 return filename
57 return filename
@@ -146,7 +146,9 b' ul.submenu li {'
146 font-size: 1.2em;
146 font-size: 1.2em;
147 display: inline;
147 display: inline;
148 }
148 }
149
149 ul.submenu li.current_submenu {
150 border-bottom: 2px solid #006699;
151 }
150 h2 {
152 h2 {
151 margin: 20px 0 10px;
153 margin: 20px 0 10px;
152 height: 30px;
154 height: 30px;
@@ -25,10 +25,10 b''
25 %if c.admin_user:
25 %if c.admin_user:
26 <ul class="submenu">
26 <ul class="submenu">
27 <li>
27 <li>
28 ${h.link_to(u'Repos managment',h.url('admin_repos_manage'))}
28 ${h.link_to(u'Repos',h.url('repos'))}
29 </li>
29 </li>
30 <li>
30 <li>
31 ${h.link_to(u'Users managment',h.url('admin_users_manage'))}
31 ${h.link_to(u'Users',h.url('users'))}
32 </li>
32 </li>
33 </ul>
33 </ul>
34 <br/>
34 <br/>
@@ -7,34 +7,22 b''
7 /
7 /
8 ${h.link_to(u'Admin',h.url('admin_home'))}
8 ${h.link_to(u'Admin',h.url('admin_home'))}
9 /
9 /
10 ${h.link_to(u'Repos managment',h.url('admin_repos_manage'))}
10 ${h.link_to(u'Repos managment',h.url('repos'))}
11 </%def>
11 </%def>
12 <%def name="page_nav()">
12 <%def name="page_nav()">
13 <li>${h.link_to(u'Home',h.url('/'))}</li>
13 <li>${h.link_to(u'Home',h.url('/'))}</li>
14 <li class="current">${_('Admin')}</li>
14 <li class="current">${_('Admin')}</li>
15 </%def>
15 </%def>
16 <%def name="main()">
16 <%def name="main()">
17
17 <ul class="submenu">
18
18 <li class="current_submenu">
19 <div class="twocol-form">
19 ${h.link_to(u'Repos',h.url('repos'))}
20 <h2>Create new repository</h2>
20 </li>
21 <form method="post" action="/repo/create/">
21 <li>
22 <table>
22 ${h.link_to(u'Users',h.url('users'))}
23 <tbody><tr><th><label for="id_name">Name:</label></th><td><input type="text" maxlength="255" name="name" id="id_name"></td></tr>
23 </li>
24 <tr><th><label for="id_description">Description:</label></th><td><textarea name="description" cols="40" rows="10" id="id_description"></textarea></td></tr>
24 </ul>
25 <tr><th><label for="id_website">Website:</label></th><td><input type="text" maxlength="128" name="website" id="id_website"></td></tr>
25 <div>
26 <tr><th><label for="id_is_private">Private:</label></th><td><input type="checkbox" id="id_is_private" name="is_private"></td></tr>
26 <h2>${_('Mercurial repos')}</h2>
27 <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>
28 <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>
29
30
31 <tr><td colspan="2">&nbsp;</td></tr>
32 <tr>
33 <td colspan="2">
34 <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">
35 </td>
36 </tr>
37 </tbody></table>
38 </form>
39 </div>
27 </div>
40 </%def> No newline at end of file
28 </%def>
@@ -7,20 +7,30 b''
7 /
7 /
8 ${h.link_to(u'Admin',h.url('admin_home'))}
8 ${h.link_to(u'Admin',h.url('admin_home'))}
9 /
9 /
10 ${h.link_to(u'Users managment',h.url('admin_users_manage'))}
10 ${h.link_to(u'Users managment',h.url('users'))}
11 </%def>
11 </%def>
12 <%def name="page_nav()">
12 <%def name="page_nav()">
13 <li>${h.link_to(u'Home',h.url('/'))}</li>
13 <li>${h.link_to(u'Home',h.url('/'))}</li>
14 <li class="current">${_('Admin')}</li>
14 <li class="current">${_('Admin')}</li>
15 </%def>
15 </%def>
16 <%def name="main()">
16 <%def name="main()">
17
17 <ul class="submenu">
18 <li>
19 ${h.link_to(u'Repos',h.url('repos'))}
20 </li>
21 <li class="current_submenu">
22 ${h.link_to(u'Users',h.url('users'))}
23 </li>
24 </ul>
25 <div>
26 <h2>${_('Mercurial users')}</h2>
18 <table cellspacing="0">
27 <table cellspacing="0">
19 <tr>
28 <tr>
20 <th>Id</th>
29 <th>Id</th>
21 <th>Username</th>
30 <th>Username</th>
22 <th>Password</th>
31 <th>Password</th>
23 <th>Active</th>
32 <th>Active</th>
33 <th>Admin</th>
24 </tr>
34 </tr>
25 %for i in c.users_list:
35 %for i in c.users_list:
26 <tr>
36 <tr>
@@ -28,7 +38,10 b''
28 <td>${i[1]}</td>
38 <td>${i[1]}</td>
29 <td>${i[2]}</td>
39 <td>${i[2]}</td>
30 <td>${i[3]}</td>
40 <td>${i[3]}</td>
41 <td>${i[4]}</td>
31 </tr>
42 </tr>
32 %endfor
43 %endfor
33 </table>
44 </table>
45 </div>
46
34 </%def> No newline at end of file
47 </%def>
General Comments 0
You need to be logged in to leave comments. Login now