1 from datetime import datetime
4 from django.contrib import auth
5 from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
6 from django.core.cache import cache
7 from django.http import HttpResponse, HttpResponseRedirect
8 from django.shortcuts import render_to_response
9 from django.template import RequestContext
10 from django.utils.http import urlquote_plus
11 from django.utils.translation import ugettext_lazy as _
12 from django.views.decorators.cache import never_cache
14 from ajaxable.utils import AjaxableFormView
15 from catalogue.models import Book
18 def main_page(request):
19 last_published = Book.objects.exclude(html_file='').order_by('-created_at')[:4]
21 return render_to_response("main_page.html", locals(),
22 context_instance=RequestContext(request))
25 class LoginFormView(AjaxableFormView):
26 form_class = AuthenticationForm
27 #template = "auth/login.html"
31 def __call__(self, request):
32 if request.user.is_authenticated():
33 return HttpResponseRedirect('/')
34 return super(LoginFormView, self).__call__(request)
36 def success(self, form, request):
37 auth.login(request, form.get_user())
40 class RegisterFormView(AjaxableFormView):
41 form_class = UserCreationForm
42 #template = "auth/register.html"
44 submit = _('Register')
46 def __call__(self, request):
47 if request.user.is_authenticated():
48 return HttpResponseRedirect('/')
49 return super(RegisterFormView, self).__call__(request)
51 def success(self, form, request):
53 user = auth.authenticate(
54 username=form.cleaned_data['username'],
55 password=form.cleaned_data['password1']
57 auth.login(request, user)
61 def logout_then_redirect(request):
63 return HttpResponseRedirect(urlquote_plus(request.GET.get('next', '/'), safe='/?='))
67 """ Provides server time for jquery.countdown,
68 in a format suitable for Date.parse()
70 return HttpResponse(datetime.now().strftime('%Y/%m/%d %H:%M:%S'))
73 def publish_plan(request):
74 cache_key = "publish_plan"
75 plan = cache.get(cache_key)
80 feed = feedparser.parse('http://localhost:8000/documents/track/editor-proofreading/')
84 for i in range(len(feed['entries'])):
87 'title': feed['entries'][i].title,
88 'link': feed['entries'][i].link,
90 cache.set(cache_key, plan, 1800)
92 return render_to_response("publish_plan.html", {'plan': plan},
93 context_instance=RequestContext(request))