# HG changeset patch # User Marcin Kuzminski # Date 1270689752 -7200 # Node ID 73f413946c14b0d8a23b3ebc693fdf4ea87fdb31 # Parent 3ada2f409c1c157c825270dc68585364acaa77e5 user managment implementation continued update/delete/create works + templating changes diff -r 3ada2f409c1c -r 73f413946c14 pylons_app/controllers/users.py --- 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 + ) diff -r 3ada2f409c1c -r 73f413946c14 pylons_app/public/hg_static/style-monoblue.css --- 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; diff -r 3ada2f409c1c -r 73f413946c14 pylons_app/templates/base/base.html --- 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 @@

- mercurial + mercurial

diff -r 3ada2f409c1c -r 73f413946c14 pylons_app/templates/repo_edit.html --- /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 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 name="page_nav()"> +
  • ${h.link_to(u'Home',h.url('/'))}
  • +
  • ${_('Admin')}
  • + +<%def name="main()"> + +
    +

    ${_('Mercurial repos')}

    +
    + \ No newline at end of file diff -r 3ada2f409c1c -r 73f413946c14 pylons_app/templates/repos_show.html --- 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 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 name="page_nav()"> -
  • ${h.link_to(u'Home',h.url('/'))}
  • -
  • ${_('Admin')}
  • - -<%def name="main()"> - -
    -

    ${_('Mercurial repos')}

    -
    - \ No newline at end of file diff -r 3ada2f409c1c -r 73f413946c14 pylons_app/templates/user_add.html --- /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 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 -r 3ada2f409c1c -r 73f413946c14 pylons_app/templates/user_edit.html --- /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 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')} - ${c.user.username}

    + ${h.form(url('user', id=c.user.user_id),method='put')} + + + + + + + + + + + + + + + + + + +
    ${_('Username')}${h.text('username')}
    ${_('New password')}${h.text('new_password')}
    ${_('Active')}${h.checkbox('active')}
    ${h.submit('save','save')}
    + + ${h.end_form()} +
    + \ No newline at end of file diff -r 3ada2f409c1c -r 73f413946c14 pylons_app/templates/users.html --- 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: ${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 diff -r 3ada2f409c1c -r 73f413946c14 pylons_app/templates/users_show.html --- 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 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')} - ${c.user.username}

    - ${h.form(url('user', id=c.user.user_id),method='put')} - - - - - - - - - - - - - - - - - - -
    ${_('Username')}${h.text('username')}
    ${_('New password')}${h.text('new_password')}
    ${_('Active')}${h.checkbox('active')}
    ${h.submit('save','save')}
    - - ${h.end_form()} -
    - \ No newline at end of file