Changeset - f6ac79182600
[Not reviewed]
default
0 6 4
Marcin Kuzminski - 16 years ago 2010-04-07 20:19:25
marcin@python-blog.com
Added rest controllers for repos and users,
templating changes + css fixes
10 files changed with 237 insertions and 42 deletions:
0 comments (0 inline, 0 general)
pylons_app/config/routing.py
Show inline comments
 
@@ -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='/')
pylons_app/controllers/admin.py
Show inline comments
 
@@ -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
pylons_app/controllers/repos.py
Show inline comments
 
new file 100644
 
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)
pylons_app/controllers/users.py
Show inline comments
 
new file 100644
 
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)
pylons_app/public/hg_static/style-monoblue.css
Show inline comments
 
@@ -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;
pylons_app/templates/admin.html
Show inline comments
 
@@ -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/>
pylons_app/templates/repos_manage.html
Show inline comments
 
@@ -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">&nbsp;</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
pylons_app/templates/users_manage.html
Show inline comments
 
@@ -7,20 +7,30 @@
 
    / 
 
    ${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>
 
            <th>Admin</th>
 
         </tr>    
 
            %for i in c.users_list:
 
                <tr>
 
@@ -28,7 +38,10 @@
 
                    <td>${i[1]}</td>
 
                    <td>${i[2]}</td>
 
                    <td>${i[3]}</td>
 
                    <td>${i[4]}</td>
 
                </tr>
 
            %endfor
 
        </table>
 
    </div>
 

	
 
</%def>    
 
\ No newline at end of file
pylons_app/tests/functional/test_repos.py
Show inline comments
 
new file 100644
 
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'))
pylons_app/tests/functional/test_users.py
Show inline comments
 
new file 100644
 
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'))
0 comments (0 inline, 0 general)