##// END OF EJS Templates
Code cleanup part 2
Code cleanup part 2

File last commit:

r722:0a4dc1c4 default
r722:0a4dc1c4 default
Show More
login.py
30 lines | 915 B | text/x-python | PythonLexer
neko259
Moved login view to a separate class. Refactored thread and all threads views
r544 from django.shortcuts import render, redirect
from boards.forms import LoginForm, PlainErrorList
from boards.models import User
neko259
Code cleanup part 2
r722 from boards.views.base import BaseBoardView, CONTEXT_FORM
neko259
Moved login view to a separate class. Refactored thread and all threads views
r544
__author__ = 'neko259'
class LoginView(BaseBoardView):
def get(self, request, form=None):
context = self.get_context_data(request=request)
if not form:
form = LoginForm()
neko259
Code cleanup part 2
r722 context[CONTEXT_FORM] = form
neko259
Moved login view to a separate class. Refactored thread and all threads views
r544
return render(request, 'boards/login.html', context)
def post(self, request):
form = LoginForm(request.POST, request.FILES,
error_class=PlainErrorList)
form.session = request.session
if form.is_valid():
user = User.objects.get(user_id=form.cleaned_data['user_id'])
request.session['user_id'] = user.id
return redirect('index')
else:
return self.get(request, form)