Changeset - 73f413946c14
[Not reviewed]
default
2 4 3
Marcin Kuzminski - 16 years ago 2010-04-08 03:22:32
marcin@python-blog.com
user managment implementation continued update/delete/create works
+ templating changes
7 files changed with 108 insertions and 11 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/users.py
Show inline comments
 
@@ -7,6 +7,7 @@ from pylons_app.lib.base import BaseCont
 
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 @@ class UsersController(BaseController):
 
    # 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 @@ class UsersController(BaseController):
 
    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 @@ class UsersController(BaseController):
 
        #    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 @@ class UsersController(BaseController):
 
    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
 
        )    
pylons_app/public/hg_static/style-monoblue.css
Show inline comments
 
@@ -173,6 +173,7 @@ h2 {
 
  border-top: dotted 1px #D5E1E6;
 
  font-weight: bold;
 
}
 

	
 
h2.no-link {
 
  color:#006699;
 
}
 
@@ -185,6 +186,15 @@ h2 a {
 
  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;
pylons_app/templates/base/base.html
Show inline comments
 
@@ -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>
 

	
pylons_app/templates/repo_edit.html
Show inline comments
 
file renamed from pylons_app/templates/repos_show.html to pylons_app/templates/repo_edit.html
pylons_app/templates/user_add.html
Show inline comments
 
new file 100644
 
<%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
pylons_app/templates/user_edit.html
Show inline comments
 
file renamed from pylons_app/templates/users_show.html to pylons_app/templates/user_edit.html
pylons_app/templates/users.html
Show inline comments
 
@@ -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
0 comments (0 inline, 0 general)