예제 #1
0
def create_wish_form(context, request):    
    schema = schemas.Wish()
    if request.user and hasattr(request.user, 'groups'):
        if 'admin' in request.user.groups:
            schema['email'].missing=''
    if request.user: 
        del schema['email']
        if hasattr(request.user, 'zip_code'):
            schema['zip_code'].default= request.user.zip_code
    form = Form(schema, formid="bobby", buttons=(Button(title='Make Wish', css_class='btn large primary'),))
    if context.__name__ ==  'forms':    
        return form.render() 
    return form 
예제 #2
0
def create_user(context, request):
    heading = 'Kindly Sign Up'
    schema = schemas.User()
    form = Form(schema,
        buttons=(Button(title="Create Account", css_class='btn'),)) 
    if request.method == "GET": 
        return {'form':form.render(), 'heading': heading}
    # validate      
    try:
        controls = request.POST.items()
        # bind unique username
        username = schema['username']
        username.validator = colander.All(colander.Length(min=2, max=50), unique_username)
        captured = form.validate(controls)
    except deform.ValidationFailure, e:
        return {'form':e.render(), 'heading': heading}
예제 #3
0
def contact(context, request):
    tpl_vars = {'heading'  : 'Say Hello...',
                'content'  : '<p><b>email: </b>[email protected]</p>',
                'page_name': 'contact'}  
    
    schema = schemas.Contact()
    myform = Form(schema, 
                buttons=(Button(title='Send', css_class='btn'),))
    if request.method == "GET": 
        tpl_vars['form'] = myform.render()
        return tpl_vars
    # validate            
    try:
        controls = request.POST.items()
        captured = myform.validate(controls)
    except deform.ValidationFailure, e:
        tpl_vars['form'] = e.render()
        return tpl_vars
예제 #4
0
def create_reply_user(context, request):
    heading = 'Please create an account so that you can reply to this wish'
    wish = models.Wishes().by_id(request.subpath[0])
    schema = schemas.Seller()
    form = Form(schema,
        buttons=(Button(title="Create Account", css_class='btn'),)) 
    if request.method == "GET": 
        return {'form':form.render(),
                'heading': heading,
                'wish': wish}
    # validate      
    try:
        controls = request.POST.items()
        # bind unique username
        username = schema['username']
        username.validator = colander.All(colander.Length(min=2, max=50), unique_username)
        captured = form.validate(controls)
    except deform.ValidationFailure, e:
        return {'form':e.render(),
                'heading': heading,
                'wish': wish}
예제 #5
0
def login(context, request):
    # context prior to forbidden being throw is in request.context
    login_url = request.application_url+'/users/login'
    referrer = request.url
    if referrer == login_url:
        referrer = '/' # never use the login form itself as came_from
    came_from = request.params.get('came_from', referrer)
    schema = schemas.Login(
        validator = match_login_password).bind(came_from = came_from)
    form = Form(schema, buttons=(
        Button(title='Login', css_class='btn'),))
    heading = 'Kindly, sign in'            
    if request.method == "GET": 
        return {'form':form.render(),
                'heading': heading}
    # validate        
    try:
        controls = request.POST.items()
        captured = form.validate(controls)
    except deform.ValidationFailure, e:
        return {'form': e.render(), 
                'heading': heading}
예제 #6
0
def create_reply_form(context, request):    
    schema = schemas.Reply()
    form = Form(schema, css_class='reply-form form-stacked', buttons=(Button(title='Reply', css_class='btn'),))
    return form.render()