예제 #1
0
def page_manage_account(request, uname):
    '''
    Main profile page view function, all panels are generated through here.
    - user is the User whose profile is being generated
    - current_panel is an enum string with on of the following values:
        account, places, events, specials.
    '''
    print request.POST
    forms_saved = []
    # only allow access to the page if the current user matches the url
    user = get_object_or_404(User, username=uname)
    if user != request.user:
        return HttpResponseForbidden()

    # 4 separate instances of the standard form building/saving pattern,
    # controlled primarily by which submit button was clicked
    if 'save_profile' in request.POST:
        profile_form = UserProfileForm(data=request.POST, files=request.FILES,
            instance=user.get_profile())
        if profile_form.is_valid():
            profile_form.save()
            forms_saved.append(profile_form)
    else:
        profile_form = UserProfileForm(instance=user.get_profile())

    if 'save_preferences' in request.POST:
        preferences_form = ActivityPreferencesForm(data=request.POST,
            instance=user.get_profile())
        if preferences_form.is_valid():
            preferences_form.save()
            forms_saved.append(preferences_form)
    else:
        preferences_form = ActivityPreferencesForm(instance=user.get_profile())

    if 'save_email' in request.POST:
        email_form = EmailForm(instance=user, data=request.POST)
        if email_form.is_valid():
            email_form.save()
            forms_saved.append(email_form)
    else:
        email_form = EmailForm(instance=user)

    if 'save_password' in request.POST:
        password_form = PasswordChangeForm(user=user, data=request.POST)
        if password_form.is_valid():
            password_form.save()
            forms_saved.append(password_form)
    else:
        password_form = PasswordChangeForm(user=user)

    forms = dict(
        profile_form=profile_form,
        password_form=password_form,
        email_form=email_form,
        preferences_form=preferences_form)
    return _render_profile_page(request, user, 'account',
        {'account_forms': forms, 'forms_saved': forms_saved})
예제 #2
0
def page_signup(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('beta-home'))

    # if POST request, handle the form submission
    if request.POST:
        reg_form = BetaRegistrationForm(data=request.POST, prefix='reg')
        profile_form = UserProfileForm(data=request.POST, prefix='prof')

        if reg_form.is_valid() and profile_form.is_valid():
            print 'yo', reg_form.cleaned_data
            user = reg_form.save()     # saves new user

            # reinitialize the form linked to the new user profile
            profile_form = UserProfileForm(data=request.POST,
                instance=user.get_profile(), prefix='prof')
            profile_form.save()

            # test if the browser supports cookies
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()

                # authenticate new user and log in
                user = authenticate(username=reg_form.cleaned_data['username'],
                    password=reg_form.cleaned_data['password1'])
                login(request, user)

                # redirect to home page
                redirect_to = reverse('beta-home')
            else:   # if cookies aren't enabled, go to login page
                redirect_to = reverse('login')

            return HttpResponseRedirect(redirect_to)
    else:
        reg_form = BetaRegistrationForm(prefix='reg')
        profile_form = UserProfileForm(prefix='prof')

    request.session.set_test_cookie()

    content = dict(
        registration_form=reg_form,
        profile_form=profile_form,
        remember_me=RememberMeForm(),
        form_action=reverse('signup')
    )
    context = PageContext(request,
        page_title='Scenable | Sign Up',
        content_dict=content)
    return render_to_response('registration/page_signup.html', context_instance=context)