示例#1
0
def loginview(request, admin=False):

    # TODO (Thu 26 Feb 2015 00:07:10 GMT): Why are we doing @loginrequired?
    if not request.user.is_authenticated():

        if admin:
            template = 'administration/admin_login.html'
            title = 'Admin Login'
            login_title = 'Admin Login'
            login_url = '/adminlogin'
        else:
            template = 'subjects/member_login.html'
            title = 'Member Login'
            login_title = 'Member Login'
            login_url = '/login'

        context = {'title': title,
                   'no_show_login': True,
                   'username_placeholder': conf.username_placeholder,
                   'login_title': login_title}

        return form_view(request,
                         template=template,
                         context=context,
                         process=LoginForm.process,
                         prgobject_key='loginform_context',
                         url_on_valid = lambda: '/initialize',
                         url_on_invalid=lambda: login_url)
    else:

        return HttpResponseRedirect('/')
示例#2
0
def getdemographicsview(request):

    '''
    The view for the demographic form submission page.
    '''
    
    demographic_templates = dict([
        ('Date_of_Birth', 'subjects/birthday.html'),
        ('Sex', 'subjects/sex.html'),
        ('Handedness', 'subjects/handedness.html'),
        ('Native_Language', 'subjects/native-language.html')
    ])

    subject = get_subject_from_request(request)
    
    required_variables\
        = [variable for (variable, required) in conf.demographic_variables\
           if required and not subject.has(variable)]

    placeholders\
        = {variable + '_placeholder': value for variable, value\
           in conf.demographic_variables_placeholders.items()\
           if variable in required_variables}

    templates\
        = [demographic_templates[variable] for variable in required_variables]

    if required_variables:

        context = dict(demographic_templates = templates)
        context.update(placeholders)
        
        logger.info(
            'Subject %s. Getting demographic variables: %s'\
            % (subject.user.username, ', '.join(required_variables))
        )
        
        process = lambda request: DemographicsForm.process(request, 
                                                           required_variables)

        return form_view(request,
                         template = 'subjects/demographicsform.html',
                         context=context,
                         process=process,
                         prgobject_key = 'demographicsform_context',
                         url_on_valid = lambda: http_redirect(request).url,
                         url_on_invalid = lambda: '/initialize')
    else:

        logger.info(
            'Subject %s. No required demographic variables.' % (subject.user.username)
        )
 
        return http_redirect(request)
示例#3
0
def forgotpasswordview(request):

    if not request.user.is_authenticated():

        context = {'title': 'Forgot Password',
                   'username_placeholder': conf.username_placeholder,
                   'forgot_your_password_title': conf.forgot_your_password_title}

        return form_view(request,
                        template='subjects/forgotpassword.html',
                        context=context,
                        process=ForgotPasswordForm.process,
                        prgobject_key='forgotpasswordform_context',
                        url_on_valid= lambda: '/forgotpassword',
                        url_on_invalid= lambda: '/forgotpassword')
    else:

        return HttpResponseRedirect('/')
示例#4
0
def signupview(request):

    if not request.user.is_authenticated():

        context = {'minimal_password_length': conf.minimal_password_length,
                   'firstname_placeholder': conf.firstname_placeholder,
                   'username_placeholder': conf.username_placeholder,
                   'no_show_signup': True,
                   'title': 'Sign up'}

        return form_view(request,
                         template = 'subjects/signup.html',
                         context=context,
                         process=SignUpForm.process,
                         prgobject_key = 'signupform_context',
                         url_on_valid = lambda: '/initialize',
                         url_on_invalid = lambda: '/signup')
    else:

        return HttpResponseRedirect('/')