# HG changeset patch # User Marcin Kuzminski # Date 2010-04-08 01:22:32 # Node ID 73f413946c14b0d8a23b3ebc693fdf4ea87fdb31 # Parent 3ada2f409c1c157c825270dc68585364acaa77e5 user managment implementation continued update/delete/create works + templating changes diff --git a/pylons_app/controllers/users.py b/pylons_app/controllers/users.py --- a/pylons_app/controllers/users.py +++ b/pylons_app/controllers/users.py @@ -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 + ) diff --git a/pylons_app/public/hg_static/style-monoblue.css b/pylons_app/public/hg_static/style-monoblue.css --- a/pylons_app/public/hg_static/style-monoblue.css +++ b/pylons_app/public/hg_static/style-monoblue.css @@ -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; diff --git a/pylons_app/templates/base/base.html b/pylons_app/templates/base/base.html --- a/pylons_app/templates/base/base.html +++ b/pylons_app/templates/base/base.html @@ -26,7 +26,7 @@

- mercurial + mercurial

diff --git a/pylons_app/templates/repos_show.html b/pylons_app/templates/repo_edit.html rename from pylons_app/templates/repos_show.html rename to pylons_app/templates/repo_edit.html diff --git a/pylons_app/templates/user_add.html b/pylons_app/templates/user_add.html new file mode 100644 --- /dev/null +++ b/pylons_app/templates/user_add.html @@ -0,0 +1,50 @@ +<%inherit file="base/base.html"/> +<%def name="title()"> + ${_('User')} - ${_('add new')} + +<%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 name="page_nav()"> +
  • ${h.link_to(u'Home',h.url('/'))}
  • +
  • ${_('Admin')}
  • + +<%def name="main()"> + +
    +

    ${_('User')} - ${_('add new')}

    + ${h.form(url('users'))} + + + + + + + + + + + + + + + + + + +
    ${_('Username')}${h.text('username')}
    ${_('password')}${h.text('password')}
    ${_('Active')}${h.checkbox('active')}
    ${h.submit('add','add')}
    + + ${h.end_form()} +
    + \ No newline at end of file diff --git a/pylons_app/templates/users_show.html b/pylons_app/templates/user_edit.html rename from pylons_app/templates/users_show.html rename to pylons_app/templates/user_edit.html diff --git a/pylons_app/templates/users.html b/pylons_app/templates/users.html --- a/pylons_app/templates/users.html +++ b/pylons_app/templates/users.html @@ -35,7 +35,8 @@ %for user in c.users_list: ${user.user_id} - ${h.link_to(user.username,h.url('user', id=user.user_id))} + ${h.link_to(user.username,h.url('edit_user', id=user.user_id))} + ${user.password} ${user.active} ${user.admin} @@ -45,7 +46,8 @@ %endfor - + +

    ${h.link_to(u'Add user',h.url('new_user'))}

    \ No newline at end of file