Added Person autocomplete view and User CRUD views.

This commit is contained in:
Lance Edgar 2013-05-07 17:41:58 -07:00
parent 25951c0080
commit 06429a4d05
2 changed files with 172 additions and 0 deletions

View file

@ -0,0 +1,56 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
# more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
``rattail.pyramid.views.people`` -- Person Views
"""
import edbob
from edbob.pyramid.views import people
from rattail.pyramid.views import AutocompleteView
class PeopleAutocomplete(AutocompleteView):
mapped_class = edbob.Person
fieldname = 'display_name'
def includeme(config):
config.add_route('people', '/people')
config.add_view(people.PeopleGrid, route_name='people',
renderer='/people/index.mako',
permission='people.list')
config.add_route('people.autocomplete', '/people/autocomplete')
config.add_view(PeopleAutocomplete, route_name='people.autocomplete',
renderer='json',
permission='people.list')
config.add_route('person.read', '/people/{uuid}')
config.add_view(people.PersonCrud, attr='read', route_name='person.read',
renderer='/people/crud.mako',
permission='people.read')

View file

@ -0,0 +1,116 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
# more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
``rattail.pyramid.views.users`` -- User Views
"""
import formalchemy
from webhelpers.html import tags
import edbob
from edbob.pyramid.views import users
from edbob.pyramid.forms import AutocompleteFieldRenderer
from rattail.pyramid.views import CrudView
def PersonFieldRenderer(url):
BaseRenderer = AutocompleteFieldRenderer(url)
class PersonFieldRenderer(BaseRenderer):
def render_readonly(self, **kwargs):
person = self.raw_value
if not person:
return ''
return tags.link_to(
str(person),
self.request.route_url('person.read', uuid=person.uuid))
return PersonFieldRenderer
class UserCrud(CrudView):
mapped_class = edbob.User
home_route = 'users'
def fieldset(self, user):
fs = self.make_fieldset(user)
# Must set Person options to empty set to avoid unwanted magic.
fs.person.set(options=[])
fs.person.set(renderer=PersonFieldRenderer(
self.request.route_url('people.autocomplete')))
fs.append(users.PasswordField('password'))
fs.append(formalchemy.Field(
'confirm_password', renderer=users.PasswordFieldRenderer))
fs.append(users.RolesField(
'roles', renderer=users.RolesFieldRenderer(self.request)))
fs.configure(
include=[
fs.username,
fs.person,
fs.password.label("Set Password"),
fs.confirm_password,
fs.roles,
])
if self.readonly:
del fs.password
del fs.confirm_password
return fs
def includeme(config):
config.add_route('users', '/users')
config.add_view(users.UsersGrid, route_name='users',
renderer='/users/index.mako',
permission='users.list')
config.add_route('user.create', '/users/new')
config.add_view(UserCrud, attr='create', route_name='user.create',
renderer='/users/crud.mako',
permission='users.create')
config.add_route('user.read', '/users/{uuid}')
config.add_view(UserCrud, attr='read', route_name='user.read',
renderer='/users/crud.mako',
permission='users.read')
config.add_route('user.update', '/users/{uuid}/edit')
config.add_view(UserCrud, attr='update', route_name='user.update',
renderer='/users/crud.mako',
permission='users.update')
config.add_route('user.delete', '/users/{uuid}/delete')
config.add_view(UserCrud, attr='delete', route_name='user.delete',
permission='users.delete')