1 from datetime import datetime
3 from django.contrib import auth
4 from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
5 from django.http import HttpResponse, HttpResponseRedirect
6 from django.shortcuts import render_to_response
7 from django.template import RequestContext
8 from django.utils.http import urlquote_plus
9 from django.utils.translation import ugettext_lazy as _
10 from django.views.decorators import cache
12 from ajaxable.utils import AjaxableFormView
13 from catalogue.models import Book
16 def main_page(request):
17 last_published = Book.objects.exclude(html_file='').order_by('-created_at')[:4]
19 return render_to_response("main_page.html", locals(),
20 context_instance=RequestContext(request))
23 class LoginFormView(AjaxableFormView):
24 form_class = AuthenticationForm
25 #template = "auth/login.html"
29 def __call__(self, request):
30 if request.user.is_authenticated():
31 return HttpResponseRedirect('/')
32 return super(LoginFormView, self).__call__(request)
34 def success(self, form, request):
35 auth.login(request, form.get_user())
38 class RegisterFormView(AjaxableFormView):
39 form_class = UserCreationForm
40 #template = "auth/register.html"
42 submit = _('Register')
44 def __call__(self, request):
45 if request.user.is_authenticated():
46 return HttpResponseRedirect('/')
47 return super(RegisterFormView, self).__call__(request)
49 def success(self, form, request):
51 user = auth.authenticate(
52 username=form.cleaned_data['username'],
53 password=form.cleaned_data['password1']
55 auth.login(request, user)
59 def logout_then_redirect(request):
61 return HttpResponseRedirect(urlquote_plus(request.GET.get('next', '/'), safe='/?='))
65 """ Provides server time for jquery.countdown,
66 in a format suitable for Date.parse()
68 return HttpResponse(datetime.now().strftime('%Y/%m/%d %H:%M:%S'))