示例#1
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    # email to send forms
    settings['from'] = '*****@*****.**'
    settings['to'] = '*****@*****.**'

#    settings['session.secret'] = 'u3wawf7jmvypAz8hpE8Yfu7J4fGZzbkg'
#    settings['session.key'] = 'rubyrate' 
#    settings['session.auto'] = True 
#    settings['session.cookie_expires'] = True 
#    settings['session.type'] = 'file' 
#
#    settings['session.data_dir'] = here + '/data/sessions/data'     
#    settings['session.lock_dir'] = here + '/data/sessions/lock' 

    settings['mako.directories'] = 'rubyrate:templates'
    settings['mako.module_directory'] = 'rubyrate:data/templates'
    settings['mako.imports'] = ['from webhelpers.html import escape',
                                'from webhelpers.html import literal']
    settings['mako.default_filters'] = ['escape']

    # adding the renderer to my own version of form
    deform_templates = resource_filename('deform', 'templates')
    search_path = (here + '/templates/deform') #, deform_templates
    #settings['deform.renderer'] = ZPTRendererFactory(search_path)
    settings['deform.searchpath'] = here + '/templates/deform'

    Form.set_zpt_renderer(search_path)

    authn_policy = AuthTktAuthenticationPolicy(
        secret='u3wawf7jmvypAz8hpE8Yfu7J4fGZzbkg',          
        callback=groupfinder)
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(root_factory=appmaker,
        settings=settings,
        authentication_policy=authn_policy,
        authorization_policy=authz_policy)

    config.set_session_factory(session_factory_from_settings(settings))

    # Mongo Setup
    conn = pymongo.Connection('mongodb://localhost/')
    config.registry.settings['db_conn'] = conn

    config.include('pyramid_mailer')

    config.add_static_view('static', 'rubyrate:static', cache_max_age=315360000)
    config.scan('rubyrate')

    config.set_request_factory(RequestWithUserAttribute)


    return config.make_wsgi_app()
示例#2
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 
示例#3
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}
示例#4
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
示例#5
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}
示例#6
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}
示例#7
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()