X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/70e52697f5d41c6658b03b739378a2a2139355e8..bf3f18ce9313f4929ff327fbf12803157de171cb:/apps/wolnelektury_core/views.py?ds=inline diff --git a/apps/wolnelektury_core/views.py b/apps/wolnelektury_core/views.py index ae582ce2d..51371735a 100644 --- a/apps/wolnelektury_core/views.py +++ b/apps/wolnelektury_core/views.py @@ -1,30 +1,33 @@ -from datetime import datetime +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from datetime import date, datetime import feedparser +from django.conf import settings from django.contrib import auth from django.contrib.auth.decorators import login_required from django.contrib.auth.forms import UserCreationForm, AuthenticationForm from django.core.cache import cache from django.http import HttpResponse, HttpResponseRedirect -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.utils.http import urlquote_plus from django.utils.translation import ugettext_lazy as _ from django.views.decorators.cache import never_cache -from django.conf import settings from ajaxable.utils import AjaxableFormView -from catalogue.models import Book from ajaxable.utils import placeholdized -from social.templatetags.social_tags import choose_cite +from catalogue.models import Book +from ssify import ssi_included def main_page(request): - last_published = Book.objects.filter(parent=None).order_by('-created_at')[:4] - cite = choose_cite(RequestContext(request)) + last_published = Book.objects.exclude(cover_thumb='').filter(parent=None).order_by('-created_at')[:4] - return render_to_response("main_page.html", locals(), - context_instance=RequestContext(request)) + return render(request, "main_page.html", { + 'last_published': last_published, + }) class LoginFormView(AjaxableFormView): @@ -91,10 +94,10 @@ def logout_then_redirect(request): @never_cache def clock(request): - """ Provides server time for jquery.countdown, + """ Provides server UTC time for jquery.countdown, in a format suitable for Date.parse() """ - return HttpResponse(datetime.now().strftime('%Y/%m/%d %H:%M:%S')) + return HttpResponse(datetime.utcnow().strftime('%Y/%m/%d %H:%M:%S UTC')) def publish_plan(request): @@ -115,11 +118,35 @@ def publish_plan(request): }) cache.set(cache_key, plan, 1800) - return render_to_response("publish_plan.html", {'plan': plan}, - context_instance=RequestContext(request)) + return render(request, "publish_plan.html", {'plan': plan}) @login_required def user_settings(request): - return render_to_response("user.html", - context_instance=RequestContext(request)) + return render(request, "user.html") + + +@ssi_included(use_lang=False, timeout=1800) +def latest_blog_posts(request, feed_url=None, posts_to_show=5): + if feed_url is None: + feed_url = settings.LATEST_BLOG_POSTS + try: + feed = feedparser.parse(str(feed_url)) + posts = [] + for i in range(posts_to_show): + pub_date = feed['entries'][i].published_parsed + published = date(pub_date[0], pub_date[1], pub_date[2]) + posts.append({ + 'title': feed['entries'][i].title, + 'summary': feed['entries'][i].summary, + 'link': feed['entries'][i].link, + 'date': published, + }) + except: + posts = [] + return render(request, 'latest_blog_posts.html', {'posts': posts}) + + +@ssi_included(use_lang=False) +def widget(request): + return render(request, 'widget.html')