Mercurial > agora-palash
view views.py @ 130:5ab229c9d348
Add back ability to edit account settings
* Account/profile editing is now done with a ModelForm, instead of processing
the data manually. Help text and verbose names have been moved to the
Profile model and to the UserForm (in the latter case, it's because we
can't edit the User model directly).
* The profile page now shows pygments style information and sections of the
profile that are not filled are now hidden.
* Some parts of apps/profiles/views.py have been rewritten (the getprofile()
method has been removed, as it's no longer necessary, and the editprofile()
view was rewritten in accordance with the switch to using ModelForms).
* The styling for forms has been modified slightly.
author | dellsystem <ilostwaldo@gmail.com> |
---|---|
date | Sat, 22 Sep 2012 11:18:23 -0400 |
parents | 2bca07be6e51 |
children | b8e0bdc37e32 |
line wrap: on
line source
from django.contrib.auth import login, authenticate from django.contrib.auth.forms import AuthenticationForm from django.shortcuts import render, redirect from django.core.urlresolvers import reverse from registration.forms import RegistrationForm from agora.apps.snippet.models import Snippet def code(request): context = { 'snippets': Snippet.objects.all()[:5], 'modules': None, # temp 'forge': None, # temp } return render(request, 'code.djhtml', context) def login_register(request): form = None next_url = None if request.method == 'POST': action = request.POST.get('action') next_url = request.GET.get('next') or reverse('login') if action == 'login': username = request.POST.get('username', '') password = request.POST.get('password1', '') if username and password: user = authenticate(username=username, password=password) login(request, user) return redirect(next_url) else: form = { 'password1': { 'errors': 'Please enter a username and password.', }, } elif action == 'register': form = RegistrationForm(request.POST) if form.is_valid(): user = form.save() login(request, user) return redirect(next_url) else: # The action is not set. Malicious submission? pass context = { 'next_url': next_url, 'form': form, } return render(request, 'login.djhtml', context)