changeset 50:73f413946c14

user managment implementation continued update/delete/create works + templating changes
author Marcin Kuzminski <marcin@python-blog.com>
date Thu, 08 Apr 2010 03:22:32 +0200
parents 3ada2f409c1c
children a699c0088344
files pylons_app/controllers/users.py pylons_app/public/hg_static/style-monoblue.css pylons_app/templates/base/base.html pylons_app/templates/repo_edit.html pylons_app/templates/repos_show.html pylons_app/templates/user_add.html pylons_app/templates/user_edit.html pylons_app/templates/users.html pylons_app/templates/users_show.html
diffstat 9 files changed, 186 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/controllers/users.py	Thu Apr 08 01:50:46 2010 +0200
+++ b/pylons_app/controllers/users.py	Thu Apr 08 03:22:32 2010 +0200
@@ -7,6 +7,7 @@
 from formencode import htmlfill
 from pylons_app.model import meta
 from pylons_app.model.db import Users, UserLogs
+import crypt
 log = logging.getLogger(__name__)
 
 class UsersController(BaseController):
@@ -14,6 +15,7 @@
     # 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')
@@ -30,10 +32,26 @@
     def create(self):
         """POST /users: Create a new item"""
         # url('users')
+        params = dict(request.params)
 
+        try:
+            new_user = Users()
+            new_user.active = params.get('active', False)
+            new_user.username = params.get('username')
+            new_user.password = crypt.crypt(params.get('password'), '6a')
+            new_user.admin = False
+            self.sa.add(new_user)
+            self.sa.commit()
+        except:
+            self.sa.rollback()
+            raise      
+          
+        return redirect(url('users'))
+    
     def new(self, format='html'):
         """GET /users/new: Form to create a new item"""
         # url('new_user')
+        return render('/user_add.html')
 
     def update(self, id):
         """PUT /users/id: Update an existing item"""
@@ -43,7 +61,23 @@
         #    h.form(url('user', id=ID),
         #           method='put')
         # url('user', id=ID)
+        params = dict(request.params)
 
+        try:
+            new_user = self.sa.query(Users).get(id)
+            new_user.active = params.get('active')
+            new_user.username = params.get('username')
+            print params
+            if params.get('new_password'):
+                new_user.password = crypt.crypt(params.get('new_password'), '6a')
+            self.sa.add(new_user)
+            self.sa.commit()
+        except:
+            self.sa.rollback()
+            raise      
+          
+        return redirect(url('users'))
+    
     def delete(self, id):
         """DELETE /users/id: Delete an existing item"""
         # Forms posted to this method should contain a hidden field:
@@ -63,15 +97,16 @@
     def show(self, id, format='html'):
         """GET /users/id: Show a specific item"""
         # url('user', id=ID)
-        c.user = self.sa.query(Users).get(id)
-
-        return htmlfill.render(
-            render('/users_show.html'),
-            defaults=c.user.__dict__,
-            encoding="UTF-8",
-            force_defaults=False
-        )        
+    
     
     def edit(self, id, format='html'):
         """GET /users/id/edit: Form to edit an existing item"""
         # url('edit_user', id=ID)
+        c.user = self.sa.query(Users).get(id)
+
+        return htmlfill.render(
+            render('/user_edit.html'),
+            defaults=c.user.__dict__,
+            encoding="UTF-8",
+            force_defaults=False
+        )    
--- a/pylons_app/public/hg_static/style-monoblue.css	Thu Apr 08 01:50:46 2010 +0200
+++ b/pylons_app/public/hg_static/style-monoblue.css	Thu Apr 08 03:22:32 2010 +0200
@@ -173,6 +173,7 @@
   border-top: dotted 1px #D5E1E6;
   font-weight: bold;
 }
+
 h2.no-link {
   color:#006699;
 }
@@ -185,6 +186,15 @@
   font-weight:bold;
   color:#006699;
 }
+h3 {
+  margin: 20px 0 10px;
+  height: 30px;
+  line-height: 30px;
+  text-indent: 20px;
+  background: #FFF;
+  font-size: 1.1em;
+  font-weight: bold;
+}
 
 div.page-path {
   text-align: right;
--- a/pylons_app/templates/base/base.html	Thu Apr 08 01:50:46 2010 +0200
+++ b/pylons_app/templates/base/base.html	Thu Apr 08 03:22:32 2010 +0200
@@ -26,7 +26,7 @@
     <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>
+            <img src="${c.staticurl}hglogo.png" width="75" height="90" alt="mercurial"/></a>
         </p>
     </div>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylons_app/templates/repo_edit.html	Thu Apr 08 03:22:32 2010 +0200
@@ -0,0 +1,28 @@
+<%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
--- a/pylons_app/templates/repos_show.html	Thu Apr 08 01:50:46 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-<%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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylons_app/templates/user_add.html	Thu Apr 08 03:22:32 2010 +0200
@@ -0,0 +1,50 @@
+<%inherit file="base/base.html"/>
+<%def name="title()">
+    ${_('User')} - ${_('add new')}
+</%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')} - ${_('add new')}</h2>
+        ${h.form(url('users'))}
+        <table>
+        	<tr>
+        		<td>${_('Username')}</td>
+        		<td>${h.text('username')}</td>
+        	</tr>
+        	<tr>
+        		<td>${_('password')}</td>
+        		<td>${h.text('password')}</td>
+        	</tr>
+        	<tr>
+        		<td>${_('Active')}</td>
+        		<td>${h.checkbox('active')}</td>
+        	</tr>
+        	<tr>
+        		<td></td>
+        		<td>${h.submit('add','add')}</td>
+        	</tr>
+        	        	        	
+        </table>
+        	
+        ${h.end_form()}
+    </div>
+</%def>    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylons_app/templates/user_edit.html	Thu Apr 08 03:22:32 2010 +0200
@@ -0,0 +1,50 @@
+<%inherit file="base/base.html"/>
+<%def name="title()">
+    ${_('User')} - ${c.user.username}
+</%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.username}</h2>
+        ${h.form(url('user', id=c.user.user_id),method='put')}
+        <table>
+        	<tr>
+        		<td>${_('Username')}</td>
+        		<td>${h.text('username')}</td>
+        	</tr>
+        	<tr>
+        		<td>${_('New password')}</td>
+        		<td>${h.text('new_password')}</td>
+        	</tr>
+        	<tr>
+        		<td>${_('Active')}</td>
+        		<td>${h.checkbox('active')}</td>
+        	</tr>
+        	<tr>
+        		<td></td>
+        		<td>${h.submit('save','save')}</td>
+        	</tr>
+        	        	        	
+        </table>
+        	
+        ${h.end_form()}
+    </div>
+</%def>    
\ No newline at end of file
--- a/pylons_app/templates/users.html	Thu Apr 08 01:50:46 2010 +0200
+++ b/pylons_app/templates/users.html	Thu Apr 08 03:22:32 2010 +0200
@@ -35,7 +35,8 @@
             %for user in c.users_list:
                 <tr>
                     <td>${user.user_id}</td>
-                    <td>${h.link_to(user.username,h.url('user', id=user.user_id))}</td>
+                    <td>${h.link_to(user.username,h.url('edit_user', id=user.user_id))}</td>
+                    <td>${user.password}</td>
                     <td>${user.active}</td>
                     <td>${user.admin}</td>
                     <td>
@@ -45,7 +46,8 @@
         			</td>
                 </tr>
             %endfor
-        </table>        
+        </table>
+        <h3>${h.link_to(u'Add user',h.url('new_user'))}</h3>        
     </div>
 
 </%def>    
\ No newline at end of file
--- a/pylons_app/templates/users_show.html	Thu Apr 08 01:50:46 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-<%inherit file="base/base.html"/>
-<%def name="title()">
-    ${_('User')} - ${c.user.username}
-</%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.username}</h2>
-        ${h.form(url('user', id=c.user.user_id),method='put')}
-        <table>
-        	<tr>
-        		<td>${_('Username')}</td>
-        		<td>${h.text('username')}</td>
-        	</tr>
-        	<tr>
-        		<td>${_('New password')}</td>
-        		<td>${h.text('new_password')}</td>
-        	</tr>
-        	<tr>
-        		<td>${_('Active')}</td>
-        		<td>${h.checkbox('active')}</td>
-        	</tr>
-        	<tr>
-        		<td></td>
-        		<td>${h.submit('save','save')}</td>
-        	</tr>
-        	        	        	
-        </table>
-        	
-        ${h.end_form()}
-    </div>
-</%def>    
\ No newline at end of file