changeset 44:d924b931b488

Added managment pages. + fixed routing bug done a lot in templates
author marcink
date Wed, 07 Apr 2010 16:42:11 +0200
parents 2e1247e62c5b
children a886f5eba757
files pylons_app/config/routing.py pylons_app/controllers/admin.py pylons_app/lib/auth.py pylons_app/templates/admin.html pylons_app/templates/base/base.html pylons_app/templates/monoblue_custom/index.tmpl pylons_app/templates/repos_manage.html pylons_app/templates/users_manage.html
diffstat 8 files changed, 178 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/config/routing.py	Wed Apr 07 15:28:50 2010 +0200
+++ b/pylons_app/config/routing.py	Wed Apr 07 16:42:11 2010 +0200
@@ -22,7 +22,8 @@
     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_manage_users', '/manage_users', action='index')
+        m.connect('admin_users_manage', '/repos_manage', action='users_manage')
+        m.connect('admin_repos_manage', '/users_manage', action='repos_manage')
         
     map.connect('hg', '/{path_info:.*}', controller='hg',
                 action="view", path_info='/')
--- a/pylons_app/controllers/admin.py	Wed Apr 07 15:28:50 2010 +0200
+++ b/pylons_app/controllers/admin.py	Wed Apr 07 16:42:11 2010 +0200
@@ -8,6 +8,7 @@
 from mercurial import ui, hg
 from mercurial.error import RepoError
 from ConfigParser import ConfigParser
+from pylons_app.lib import auth
 log = logging.getLogger(__name__)
 
 class AdminController(BaseController):
@@ -15,12 +16,21 @@
 
     def __before__(self):
         c.staticurl = g.statics
+        c.admin_user = True
         
     def index(self):
         # Return a rendered template
         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
 
@@ -32,8 +42,8 @@
         
 
         #extra check it can be add since it's the command
-        if new_repo == 'add':
-            c.msg = 'you basstard ! this repo is a command'
+        if new_repo == '_admin':
+            c.msg = 'DENIED'
             c.new_repo = ''
             return render('add.html')
 
--- a/pylons_app/lib/auth.py	Wed Apr 07 15:28:50 2010 +0200
+++ b/pylons_app/lib/auth.py	Wed Apr 07 16:42:11 2010 +0200
@@ -8,13 +8,13 @@
 log = logging.getLogger(__name__)
 ROOT = dn(dn(dn(os.path.realpath(__file__))))
 
-def get_sqlite_cur_conn():
+def get_sqlite_conn_cur():
     conn = sqlite3.connect(os.path.join(ROOT, 'auth.sqlite'))
     cur = conn.cursor()
     return conn, cur
 
 def authfunc(environ, username, password):
-    conn, cur = get_sqlite_cur_conn()
+    conn, cur = get_sqlite_conn_cur()
     password_crypt = crypt.crypt(password, '6a')
 
     try:
@@ -59,7 +59,7 @@
     '''
     Create a auth database
     '''
-    conn, cur = get_sqlite_cur_conn()
+    conn, cur = get_sqlite_conn_cur()
     try:
         log.info('creating table %s', 'users')
         cur.execute('''DROP TABLE IF EXISTS users ''')
@@ -83,7 +83,7 @@
     cur.close()
     
 def create_user(username, password):
-    conn, cur = get_sqlite_cur_conn()    
+    conn, cur = get_sqlite_conn_cur()    
     password_crypt = crypt.crypt(password, '6a')
     cur_date = datetime.now()
     log.info('creating user %s', username)
@@ -105,5 +105,6 @@
     create_user('bart', 'qweqwe')
     create_user('maho', 'qweqwe')
     create_user('michalg', 'qweqwe')
+    create_user('admin', 'qwe123qwe')
     
     #authfunc('', 'marcink', 'qweqwe')
--- a/pylons_app/templates/admin.html	Wed Apr 07 15:28:50 2010 +0200
+++ b/pylons_app/templates/admin.html	Wed Apr 07 16:42:11 2010 +0200
@@ -1,51 +1,53 @@
 ## -*- 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>Mercurial repositories Admin</title>
-</head>
-
-<body>
-<div id="container">
-    <div class="page-header">
-        <h1><a href="/">Home</a> / Admin</h1>
-        <ul class="page-nav">
-        </ul>
+<%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'))}
+</%def>
+<%def name="page_nav()">
+<li>${h.link_to(u'Home',h.url('/'))}</li>
+<li class="current">${_('Admin')}</li>
+</%def>
+<%def name="main()">
+    %if c.admin_user:
+    <ul class="submenu">
+        <li>
+            ${h.link_to(u'Repos managment',h.url('admin_repos_manage'))}
+        </li>
+        <li>
+            ${h.link_to(u'Users managment',h.url('admin_users_manage'))}
+        </li>
+    </ul>
+    <br/>
+    <div>
+    
+        <h2>Hi !</h2>
     </div>
-    <table cellspacing="0">
-        <tr>
-            <td>${h.link_to(u'Create "ccc" repository',h.url('admin_add_repo',new_repo='ccc'))}</td>
-        </tr>
-        <tr>
-            <td>${h.link_to(u'Create "ccc" repository',h.url('admin_add_repo',new_repo='ccc'))}</td>
-        </tr>
-        <tr>
-            <td>${h.link_to(u'Create "ccc" repository',h.url('admin_add_repo',new_repo='ccc'))}</td>
-        </tr>
-        <tr>
-            <td><h2>${c.new_repo}</h2></td>
-        </tr>
-    </table>    
-    <div class="page-footer">
-        Mercurial Repository: admin
-    </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
+    %else:
+        <div>
+        <br />
+        <h2>${_('Login')}</h2>
+        ${h.form(h.url.current())}
+        <table>
+            <tr>
+                <td>${_('Username')}</td>
+                <td>${h.text('username')}</td>
+            </tr>
+            <tr>
+                <td>${_('Password')}</td>
+                <td>${h.text('password')}</td>
+            </tr>
+            <tr>
+                <td></td>
+                <td>${h.submit('login','login')}</td>
+            </tr>            
+        </table>
+        ${h.end_form()}
+        </div>
+    %endif
+    
+</%def>
\ No newline at end of file
--- a/pylons_app/templates/base/base.html	Wed Apr 07 15:28:50 2010 +0200
+++ b/pylons_app/templates/base/base.html	Wed Apr 07 16:42:11 2010 +0200
@@ -2,33 +2,39 @@
 <!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>
-  <style type="text/css">
-  </style>
-  <title>${next.page_title()}</title>
-  <meta name="author" content=""/>
-  <meta name="keywords" content=""/>
-  <meta name="description" content=""/>
-  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
-  <link rel="shortcut icon" type="image/x-icon" href="/images/sample.ico"/>
-  <script src="/css_browser_selector.js" type="text/javascript"></script>
-  <script type="text/javascript" src="/js/yui/utilities/utilities.js"></script>
-  <link rel="stylesheet" type="text/css" href="/css/style.css"/>     
-
+    <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="top-glow"></div>
-
-  <div id="container">
-    ${next.body()}
+<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}
+    </div>   
 
-  <div id="footer" class="clearfix">
-    ${next.footer()}
-  </div><!-- /footer -->
+    <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><!-- /container -->
+    <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 id="bottom-glow"></div>
-
- </body>
- </html>
\ No newline at end of file
+</div>
+</body>
+</html>
\ No newline at end of file
--- a/pylons_app/templates/monoblue_custom/index.tmpl	Wed Apr 07 15:28:50 2010 +0200
+++ b/pylons_app/templates/monoblue_custom/index.tmpl	Wed Apr 07 16:42:11 2010 +0200
@@ -8,6 +8,8 @@
     <div class="page-header">
         <h1>${c.repos_prefix} Mercurial Repositories</h1>
         <ul class="page-nav">
+            <li class="current">Home</li>
+            <li>${h.link_to(u'Admin',h.url('admin_home'))}</li>
         </ul>
     </div>
     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylons_app/templates/repos_manage.html	Wed Apr 07 16:42:11 2010 +0200
@@ -0,0 +1,40 @@
+<%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('admin_repos_manage'))}
+</%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>
+    </div>
+</%def>    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylons_app/templates/users_manage.html	Wed Apr 07 16:42:11 2010 +0200
@@ -0,0 +1,34 @@
+<%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'Users managment',h.url('admin_users_manage'))}
+</%def>
+<%def name="page_nav()">
+    <li>${h.link_to(u'Home',h.url('/'))}</li>
+    <li class="current">${_('Admin')}</li>
+</%def>
+<%def name="main()">
+
+        <table cellspacing="0">
+         <tr>
+            <th>Id</th>
+            <th>Username</th>
+            <th>Password</th>
+            <th>Active</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>
+                </tr>
+            %endfor
+        </table>
+</%def>    
\ No newline at end of file