diff --git a/ordr/__init__.py b/ordr/__init__.py
index 2a89ec2..2d775e5 100644
--- a/ordr/__init__.py
+++ b/ordr/__init__.py
@@ -19,6 +19,5 @@ def main(global_config, **settings):
config.include('.resources')
config.include('.schemas')
config.include('.security')
- config.add_static_view('static', 'static', cache_max_age=3600)
- config.scan()
+ config.include('.views')
return config.make_wsgi_app()
diff --git a/ordr/schemas/__init__.py b/ordr/schemas/__init__.py
index f3a31f7..953dfa4 100644
--- a/ordr/schemas/__init__.py
+++ b/ordr/schemas/__init__.py
@@ -35,10 +35,12 @@ class CSRFSchema(colander.Schema):
:param kwargs:
additional parameters for the form rendering.
'''
+ schema = cls().bind(request=request)
if action is None:
action = request.resource_url(request.context, request.view_name)
- schema = cls().bind(request=request)
- return deform.Form(schema, action=action, **kwargs)
+ settings = {'col_label': 3, 'col_input': 9, 'action': action}
+ settings.update(kwargs)
+ return deform.Form(schema, **settings)
def includeme(config):
diff --git a/ordr/schemas/account.py b/ordr/schemas/account.py
index e1eb3a4..7420f0f 100644
--- a/ordr/schemas/account.py
+++ b/ordr/schemas/account.py
@@ -16,7 +16,9 @@ class RegistrationSchema(CSRFSchema):
username = colander.SchemaNode(
colander.String(),
- widget=deform.widget.TextInputWidget(readonly=True),
+ widget=deform.widget.TextInputWidget(
+ readonly=True,
+ ),
description='automagically generated for you',
validator=deferred_unique_username_validator,
)
@@ -34,3 +36,4 @@ class RegistrationSchema(CSRFSchema):
colander.String(),
widget=deform.widget.CheckedPasswordWidget()
)
+
diff --git a/ordr/schemas/helpers.py b/ordr/schemas/helpers.py
index efa1798..d96b99d 100644
--- a/ordr/schemas/helpers.py
+++ b/ordr/schemas/helpers.py
@@ -45,10 +45,11 @@ def deferred_unique_email_validator(node, kw):
email_validator(node, value) # raises exception on invalid address
request = kw.get('request')
user = request.dbsession.query(User).filter_by(email=value).first()
- if user not in (None, request.context.model):
- # allow existing email addresses if
- # it belongs to the user that is currently edited
- raise colander.Invalid(node, 'Email address in use')
+ if user is not None:
+ if user != getattr(request.context, 'model', None):
+ # allow existing email addresses if
+ # it belongs to the user that is currently edited
+ raise colander.Invalid(node, 'Email address in use')
return validate_unique_email
diff --git a/ordr/templates/account/registration_form.jinja2 b/ordr/templates/account/registration_form.jinja2
index 806a9d9..b8809e1 100644
--- a/ordr/templates/account/registration_form.jinja2
+++ b/ordr/templates/account/registration_form.jinja2
@@ -1,5 +1,31 @@
{% extends "ordr:templates/layout.jinja2" %}
{% block content %}
- {{ context.get_registration_form().render()|safe }}
+
+
+
+
+ Step 1: Registration
+
+
+
+
+ Step 2: Validate Email
+
+
+
+
+
+
+ {{ form.render()|safe }}
+
+
{% endblock content %}
diff --git a/ordr/templates/deform/checked_password.pt b/ordr/templates/deform/checked_password.pt
new file mode 100644
index 0000000..19e3c6c
--- /dev/null
+++ b/ordr/templates/deform/checked_password.pt
@@ -0,0 +1,46 @@
+
+${field.start_mapping()}
+
+
+
+
+${field.end_mapping()}
+
diff --git a/ordr/templates/deform/form.pt b/ordr/templates/deform/form.pt
new file mode 100644
index 0000000..0fee3d7
--- /dev/null
+++ b/ordr/templates/deform/form.pt
@@ -0,0 +1,110 @@
+
diff --git a/ordr/templates/deform/mapping_item.pt b/ordr/templates/deform/mapping_item.pt
new file mode 100644
index 0000000..ac34815
--- /dev/null
+++ b/ordr/templates/deform/mapping_item.pt
@@ -0,0 +1,55 @@
+
diff --git a/ordr/templates/deform/readonly/textinput.pt b/ordr/templates/deform/readonly/textinput.pt
new file mode 100644
index 0000000..109866c
--- /dev/null
+++ b/ordr/templates/deform/readonly/textinput.pt
@@ -0,0 +1,17 @@
+
+
+
diff --git a/ordr/templates/deform/textinput.pt b/ordr/templates/deform/textinput.pt
new file mode 100644
index 0000000..580829b
--- /dev/null
+++ b/ordr/templates/deform/textinput.pt
@@ -0,0 +1,18 @@
+
+
+
diff --git a/ordr/templates/layout.jinja2 b/ordr/templates/layout.jinja2
index 617cda6..6867c1e 100644
--- a/ordr/templates/layout.jinja2
+++ b/ordr/templates/layout.jinja2
@@ -15,6 +15,9 @@
+
+ {# #}
+
diff --git a/ordr/views/__init__.py b/ordr/views/__init__.py
index e69de29..3388dbe 100644
--- a/ordr/views/__init__.py
+++ b/ordr/views/__init__.py
@@ -0,0 +1,15 @@
+''' views (sub) package for ordr '''
+
+
+def includeme(config):
+ '''
+ Initialize the views in a Pyramid app.
+
+ Activate this setup using ``config.include('ordr2.views')``.
+ '''
+ settings = config.get_settings()
+ age = int(settings.get('static_views.cache_max_age', 3600))
+
+ config.add_static_view('static', 'ordr:static', cache_max_age=age)
+ config.add_static_view('deform', 'deform:static', cache_max_age=age)
+ config.scan()
diff --git a/ordr/views/registration.py b/ordr/views/registration.py
index 232de9f..f866947 100644
--- a/ordr/views/registration.py
+++ b/ordr/views/registration.py
@@ -1,4 +1,6 @@
-# from pyramid.httpexceptions import HTTPFound
+import deform
+
+from pyramid.httpexceptions import HTTPFound
from pyramid.view import view_config
# from ordr.models import User
@@ -11,4 +13,24 @@ from pyramid.view import view_config
renderer='ordr:templates/account/registration_form.jinja2'
)
def registration_form(context, request):
- return {}
+ form = context.get_registration_form()
+ return {'form': form}
+
+
+
+@view_config(
+ context='ordr.resources.account.RegistrationResource',
+ permission='view',
+ request_method='POST',
+ renderer='ordr:templates/account/registration_form.jinja2'
+ )
+def registration_form_processing(context, request):
+ if 'Cancel' in request.POST:
+ return HTTPFound(request.resource_url(request.root))
+ form = context.get_registration_form()
+ data = request.POST.items()
+ try:
+ appstruct = form.validate(data)
+ except deform.ValidationFailure as e:
+ pass
+ return {'form': form}