Changeset - 8e250e86a670
[Not reviewed]
default
2 5 4
Marcin Kuzminski - 16 years ago 2010-04-07 21:10:43
marcin@python-blog.com
Css fixes, implemented removal of users, and display draft
9 files changed with 101 insertions and 15 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/repos.py
Show inline comments
 
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')
 
        return render('/repos.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)
 

	
 
        return render('/repos_show.html')
 
    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
 
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')
 
        self.conn, self.cur = auth.get_sqlite_conn_cur()
 
        
 
    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')
 
        
 
        self.cur.execute('SELECT * FROM users')
 
        c.users_list = self.cur.fetchall()        
 
        return render('/users.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)
 

	
 
        try:
 
            self.cur.execute("DELETE FROM users WHERE user_id=?", (id,))
 
            self.conn.commit()
 
        except:
 
            self.conn.rollback()
 
            raise
 
        return redirect(url('users'))
 
        
 
    def show(self, id, format='html'):
 
        """GET /users/id: Show a specific item"""
 
        # url('user', id=ID)
 

	
 
        self.cur.execute("SELECT * FROM users WHERE user_id=?", (id,))
 
        ret = self.cur.fetchone()
 
        c.user_name = ret[1]
 
        return render('/users_show.html')
 
    
 
    def edit(self, id, format='html'):
 
        """GET /users/id/edit: Form to edit an existing item"""
 
        # url('edit_user', id=ID)
pylons_app/lib/auth.py
Show inline comments
 
@@ -63,49 +63,49 @@ def authfunc(environ, username, password
 
                                    cur.execute('''INSERT INTO 
 
                                                        user_logs 
 
                                                   VALUES(?,?,?,?)''',
 
                                                    (None, data[0], cmd, datetime.now()))
 
                                    conn.commit()
 
                                except Exception as e:
 
                                    conn.rollback()
 
                                    log.error(e)
 
                                  
 
                return True
 
        else:
 
            log.error('user %s is disabled', username)
 
            
 
    return False
 

	
 
def create_user_table():
 
    '''
 
    Create a auth database
 
    '''
 
    conn, cur = get_sqlite_conn_cur()
 
    try:
 
        log.info('creating table %s', 'users')
 
        cur.execute('''DROP TABLE IF EXISTS users ''')
 
        cur.execute('''CREATE TABLE users
 
                        (id INTEGER PRIMARY KEY AUTOINCREMENT, 
 
                        (user_id INTEGER PRIMARY KEY AUTOINCREMENT, 
 
                         username TEXT, 
 
                         password TEXT,
 
                         active INTEGER,
 
                         admin INTEGER)''')
 
        log.info('creating table %s', 'user_logs')
 
        cur.execute('''DROP TABLE IF EXISTS user_logs ''')
 
        cur.execute('''CREATE TABLE user_logs
 
                        (id INTEGER PRIMARY KEY AUTOINCREMENT,
 
                            user_id INTEGER,
 
                            last_action TEXT, 
 
                            last_action_date DATETIME)''')
 
        conn.commit()
 
    except:
 
        conn.rollback()
 
        raise
 
    
 
    cur.close()
 
    
 
def create_user(username, password, admin=False):
 
    conn, cur = get_sqlite_conn_cur()    
 
    password_crypt = crypt.crypt(password, '6a')
 
    log.info('creating user %s', username)
 
    try:
 
        cur.execute('''INSERT INTO users values (?,?,?,?,?) ''',
pylons_app/public/hg_static/style-monoblue.css
Show inline comments
 
@@ -43,49 +43,63 @@ div.page-header {
 
    font-family: osaka,'MS P Gothic', Georgia, serif;
 
    letter-spacing: 1px;
 
    color: #DDD;
 
  }
 
  div.page-header h1 a {
 
    font-weight: bold;
 
    color: #FFF;
 
  }
 
  div.page-header a {
 
    text-decoration: none;
 
  }
 
  div.rss_logo { 
 
    float: right; white-space: nowrap; 
 
  }
 
  div.rss_logo a {
 
    padding:3px 6px; line-height:10px;
 
    border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
 
    color:#ffffff; background-color:#ff6600;
 
    font-weight:bold; font-family:sans-serif; font-size:10px;
 
    text-align:center; text-decoration:none;
 
}
 
  div.rss_logo a:hover { 
 
    background-color:#ee5500; 
 
  }
 

	
 
input.submit{
 
	background-color:#FF6600;
 
	border-color:#FCC7A5 #7D3302 #3E1A01 #FF954E;
 
	border-style:solid;
 
	border-width:1px;
 
	color:#FFFFFF;
 
	font-family:sans-serif;
 
	font-size:10px;
 
	font-weight:bold;
 
	line-height:8px;
 
	padding:1px 2px;
 
	text-align:center;
 
	text-decoration:none;
 
	cursor: pointer;
 
}
 
  td.indexlinks { 
 
	   white-space: nowrap; 
 
  }
 
  td.indexlinks a {
 
	  padding: 2px 5px; line-height: 10px;
 
	  border: 1px solid;
 
	  color: #ffffff; background-color: #7777bb;
 
	  border-color: #aaaadd #333366 #333366 #aaaadd;
 
	  font-weight: bold;  text-align: center; text-decoration: none;
 
	  font-size: 10px;
 
  }
 
  td.indexlinks a:hover {
 
	 background-color: #6666aa; 
 
  }
 

	
 
  div.page-header form {
 
    position: absolute;
 
    margin-bottom: 2px;
 
    bottom: 0;
 
    right: 20px;
 
  }
 
  div.page-header form label {
 
    color: #DDD;
 
  }
pylons_app/templates/base/base.html
Show inline comments
 
## -*- coding: utf-8 -*-
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
 
    <link rel="icon" href="${c.staticurl}hgicon.png" type="image/png" />
 
    <meta name="robots" content="index, nofollow"/>
 
    <link rel="stylesheet" href="${c.staticurl}style-monoblue.css" type="text/css" />
 
       <title>${next.title()}</title>
 
</head>
 

	
 
<body>
 
<div id="container">
 
    <div class="page-header">
 
        <h1>
 
            ${next.breadcrumbs()}
 
        </h1>
 
        <ul class="page-nav">
 
            ${next.page_nav()}
 
        </ul>
 
    </div>
 
    ${next.main()}
 
    <div class="page-footer">
 
        Mercurial Repository: ${c.repo_name}
 
        Mercurial
 
    </div>   
 

	
 
    <div id="powered-by">
 
        <p>
 
        <a href="http://mercurial.selenic.com/" title="Mercurial">
 
            <img src="${c.staticurl}hglogo.png" width="75" height="90" alt="mercurial"></a>
 
        </p>
 
    </div>
 

	
 
    <div id="corner-top-left"></div>
 
    <div id="corner-top-right"></div>
 
    <div id="corner-bottom-left"></div>
 
    <div id="corner-bottom-right"></div>
 

	
 
</div>
 
</body>
 
</html>
 
\ No newline at end of file
pylons_app/templates/repos.html
Show inline comments
 
file renamed from pylons_app/templates/repos_manage.html to pylons_app/templates/repos.html
pylons_app/templates/repos_show.html
Show inline comments
 
new file 100644
 
<%inherit file="base/base.html"/>
 
<%def name="title()">
 
    ${_('Repository managment')}
 
</%def>
 
<%def name="breadcrumbs()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    / 
 
    ${h.link_to(u'Admin',h.url('admin_home'))}
 
    /
 
    ${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()">
 
    <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.html
Show inline comments
 
file renamed from pylons_app/templates/users_manage.html to pylons_app/templates/users.html
 
@@ -3,45 +3,49 @@
 
    ${_('Repository managment')}
 
</%def>
 
<%def name="breadcrumbs()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    / 
 
    ${h.link_to(u'Admin',h.url('admin_home'))}
 
    /
 
    ${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">
 
        <table>
 
         <tr>
 
            <th>Id</th>
 
            <th>Username</th>
 
            <th>Password</th>
 
            <th>Active</th>
 
            <th>Admin</th>
 
            <th>Action</th>
 
         </tr>
 
            %for i in c.users_list:
 
                <tr>
 
                    <td>${i[0]}</td>
 
                    <td>${i[1]}</td>
 
                    <td>${i[2]}</td>
 
                    <td>${h.link_to(i[1],h.url('user', id=i[0]))}</td>
 
                    <td>${i[3]}</td>
 
                    <td>${i[4]}</td>
 
                    <td>
 
	                    ${h.form(url('user', id=i[0]),method='delete')}
 
	                    	${h.submit('remove','remove',class_="submit")}
 
	                    ${h.end_form()}
 
        			</td>
 
                </tr>
 
            %endfor
 
        </table>        
 
    </div>
 

	
 
</%def>    
 
\ No newline at end of file
pylons_app/templates/users_show.html
Show inline comments
 
new file 100644
 
<%inherit file="base/base.html"/>
 
<%def name="title()">
 
    ${_('User c.user_name')}
 
</%def>
 
<%def name="breadcrumbs()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    / 
 
    ${h.link_to(u'Admin',h.url('admin_home'))}
 
    /
 
    ${h.link_to(u'Users',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>${_('User')} - ${c.user_name}</h2>
 
    </div>
 
</%def>    
 
\ No newline at end of file
0 comments (0 inline, 0 general)