Skip to content

Commit

Permalink
A client-side validation form written in python
Browse files Browse the repository at this point in the history
  • Loading branch information
Dusty Phillips committed Apr 3, 2012
1 parent d37d4a0 commit 841064f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
25 changes: 25 additions & 0 deletions pyjaco/todoy.py
@@ -0,0 +1,25 @@

def setup():
validate("#registration_form",
{
'confirm_password': 'The passwords do not match',
'username': "I'm afraid that username is taken"},
username={
'required': True,
'remote': 'user_valid.json'
},
password='required',
confirm_password={'equalTo': 'input[name=password]'})


@JSVar('jQuery')
def validate(selector, mess=None, **kwargs):
if mess == None:
mess = {}
jQuery(js(selector)).validate(
{'rules': js(kwargs),
'messages': js(mess)
}
)

jQuery(js(setup))
3 changes: 1 addition & 2 deletions www/account/register.html
@@ -1,5 +1,4 @@
# -*- python -*-
import json
from aspen import Response
from trembling.auth import User
from trembling import Redirect
Expand Down Expand Up @@ -46,7 +45,7 @@
except InvalidDataError as e:
print e.error_dict()
response = Response(406, json.dumps(
{k:v.message for k,v in e.error_dict().iteritems()}))
{k: v.message for k, v in e.error_dict().iteritems()}))
else:
print "VALID"

Expand Down
15 changes: 15 additions & 0 deletions www/account/user_valid.json
@@ -0,0 +1,15 @@
# -*- python -*-
# This json response is used by the validator on
# register.html
from aspen import Response
from trembling.auth import User

^L
username = request.qs.one('username')
existing_user = User.objects(username=username)

response = Response()
if existing_user:
response.body = False
else:
response.body = True
2 changes: 1 addition & 1 deletion www/js/todoy.js
Expand Up @@ -2,7 +2,7 @@ var setup = function() {
var __kwargs = __kwargs_get(arguments);
var __varargs = __varargs_get(arguments);
var $v1 = Array.prototype.slice.call(arguments).concat(js(__varargs));
validate(str('#registration_form'), dict([str('confirm_password'), str('The passwords do not match')]), __kwargs_make({username: str('required'), password: str('required'), confirm_password: dict([str('equalTo'), str('input[name=password]')])}));
validate(str('#registration_form'), dict([str('confirm_password'), str('The passwords do not match'), str('username'), str("I'm afraid that username is taken")]), __kwargs_make({username: dict([str('required'), __builtins__.PY$True, str('remote'), str('user_valid.json')]), password: str('required'), confirm_password: dict([str('equalTo'), str('input[name=password]')])}));
return None;
}
var validate = function() {
Expand Down

0 comments on commit 841064f

Please sign in to comment.