Remove some edbob, unicode tweak, etc.

In particular it was noticed that edbob has been configuring FormAlchemy
all this time, whoops.  That's still partially the case but now at least
it's explicit.
This commit is contained in:
Lance Edgar 2015-01-19 00:45:26 -06:00
parent e47477f0c4
commit c4a19f279b
4 changed files with 61 additions and 30 deletions

View file

@ -1,9 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar
# Copyright © 2010-2015 Lance Edgar
#
# This file is part of Rattail.
#
@ -21,11 +20,12 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Label Views
"""
from __future__ import unicode_literals
from pyramid.httpexceptions import HTTPFound
import formalchemy
@ -35,7 +35,6 @@ from webhelpers.html import HTML
from ..db import Session
from . import SearchableAlchemyGridView, CrudView
from ..grids.search import BooleanSearchFilter
from edbob.pyramid.forms import StrippingFieldRenderer
from rattail.db.model import LabelProfile
@ -102,8 +101,6 @@ class ProfileCrud(CrudView):
return super(FormatFieldRenderer, self).render(**kwargs)
fs = self.make_fieldset(model)
fs.printer_spec.set(renderer=StrippingFieldRenderer)
fs.formatter_spec.set(renderer=StrippingFieldRenderer)
fs.format.set(renderer=FormatFieldRenderer)
fs.configure(
include=[

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2014 Lance Edgar
# Copyright © 2010-2015 Lance Edgar
#
# This file is part of Rattail.
#
@ -20,27 +20,24 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
User Views
"""
from __future__ import unicode_literals
from rattail.db.model import User, Person, Role
from rattail.db.auth import guest_role, set_user_password
import formalchemy
from formalchemy import Field, ValidationError
from formalchemy.fields import SelectFieldRenderer
from edbob.pyramid.views import users
from webhelpers.html import tags
from webhelpers.html import HTML
from . import SearchableAlchemyGridView, CrudView
from ..forms import PersonFieldLinkRenderer
from ..db import Session
from rattail.db.model import User, Person, Role
from rattail.db.auth import guest_role
from webhelpers.html import tags
from webhelpers.html import HTML
from tailbone.grids.search import BooleanSearchFilter
@ -141,6 +138,33 @@ def RolesFieldRenderer(request):
return RolesFieldRenderer
class PasswordFieldRenderer(formalchemy.PasswordFieldRenderer):
def render(self, **kwargs):
return tags.password(self.name, value='', maxlength=self.length, **kwargs)
def passwords_match(value, field):
if field.parent.confirm_password.value != value:
raise formalchemy.ValidationError("Passwords do not match")
return value
class PasswordField(formalchemy.Field):
def __init__(self, *args, **kwargs):
kwargs.setdefault('value', lambda x: x.password)
kwargs.setdefault('renderer', PasswordFieldRenderer)
kwargs.setdefault('validate', passwords_match)
super(PasswordField, self).__init__(*args, **kwargs)
def sync(self):
if not self.is_readonly():
password = self.renderer.deserialize()
if password:
set_user_password(self.model, password)
class UserCrud(CrudView):
mapped_class = User
@ -152,9 +176,9 @@ class UserCrud(CrudView):
# Must set Person options to empty set to avoid unwanted magic.
fs.person.set(options=[])
fs.append(users.PasswordField('password'))
fs.append(PasswordField('password'))
fs.append(Field('confirm_password',
renderer=users.PasswordFieldRenderer))
renderer=PasswordFieldRenderer))
fs.append(RolesField(
'roles', renderer=RolesFieldRenderer(self.request)))