diff --git a/ordr/resources/account.py b/ordr/resources/account.py index 8aae785..ea2bf61 100644 --- a/ordr/resources/account.py +++ b/ordr/resources/account.py @@ -1,5 +1,7 @@ ''' Resources (sub) package, used to connect URLs to views ''' +import deform + from pyramid.security import Allow, Everyone, DENY_ALL from ordr.schemas.account import RegistrationSchema @@ -23,7 +25,15 @@ class RegistrationResource(BaseChildResource): def get_registration_form(self, **kwargs): ''' returns the registration form''' settings = { - 'buttons': ('Create account', 'Cancel'), + 'buttons': ( + deform.Button(name='create', title='Create Account'), + deform.Button( + title='Cancel', + type='link', + value=self.request.resource_url(self.request.root), + css_class='btn btn-secondary' + ) + ), } settings.update(kwargs) return self._prepare_form(RegistrationSchema, **settings) diff --git a/ordr/schemas/account.py b/ordr/schemas/account.py index 7420f0f..c85004f 100644 --- a/ordr/schemas/account.py +++ b/ordr/schemas/account.py @@ -17,16 +17,19 @@ class RegistrationSchema(CSRFSchema): username = colander.SchemaNode( colander.String(), widget=deform.widget.TextInputWidget( - readonly=True, + readonly=True ), description='automagically generated for you', - validator=deferred_unique_username_validator, + validator=deferred_unique_username_validator, + oid='registration_username' ) first_name = colander.SchemaNode( - colander.String() + colander.String(), + oid='registration_first_name' ) last_name = colander.SchemaNode( - colander.String() + colander.String(), + oid='registration_last_name' ) email = colander.SchemaNode( colander.String(), diff --git a/ordr/static/pyramid.png b/ordr/static/pyramid.png deleted file mode 100644 index 4ab837b..0000000 Binary files a/ordr/static/pyramid.png and /dev/null differ diff --git a/ordr/static/scripts.js b/ordr/static/scripts.js new file mode 100644 index 0000000..c8e1ec3 --- /dev/null +++ b/ordr/static/scripts.js @@ -0,0 +1,21 @@ +$(function() { + + function capitalize(s){ + return s.replace( /\b./g, function(a){ return a.toUpperCase(); } ); + }; + + function generate_user_name() { + var first_name = $('#registration_first_name').val(); + var last_name = $('#registration_last_name').val(); + var user_name = capitalize(first_name) + capitalize(last_name); + return user_name.replace( /[\s-]/g, '') + }; + + // autocomplete of the username (registration form) + $('#registration_first_name').keyup(function () { + $('#registration_username').val( generate_user_name() ); + }); + $('#registration_last_name').keyup(function() { + $('#registration_username').val( generate_user_name() ); + }); +}); \ No newline at end of file diff --git a/ordr/templates/layout.jinja2 b/ordr/templates/layout.jinja2 index 6867c1e..e2c5ce4 100644 --- a/ordr/templates/layout.jinja2 +++ b/ordr/templates/layout.jinja2 @@ -78,6 +78,7 @@ + diff --git a/ordr/views/registration.py b/ordr/views/registration.py index f866947..77e1053 100644 --- a/ordr/views/registration.py +++ b/ordr/views/registration.py @@ -25,12 +25,11 @@ def registration_form(context, request): 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 + if 'create' in request.POST: + data = request.POST.items() + try: + appstruct = form.validate(data) + except deform.ValidationFailure as e: + pass return {'form': form}