From 48625c4ed3b93daecc8df786f6fdc45a2477122e Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Fri, 1 Apr 2016 17:04:39 +0200 Subject: [PATCH 1/1] lessons for cybernauts (ajax view) --- apps/catalogue/urls.py | 2 ++ apps/catalogue/views.py | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/catalogue/urls.py b/apps/catalogue/urls.py index e74f9162..ec43053f 100644 --- a/apps/catalogue/urls.py +++ b/apps/catalogue/urls.py @@ -51,4 +51,6 @@ urlpatterns = patterns('catalogue.views', 'chunk_mass_edit', name='catalogue_chunk_mass_edit'), url(r'^track/(?P[^/]*)/$', PublishTrackFeed()), + + url(r'^cybernauci/$', 'lessons_for_cybernauts'), ) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index a1a1ab3c..d07303f4 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -24,7 +24,7 @@ from django.template import RequestContext from apiclient import NotAuthorizedError from catalogue import forms from catalogue import helpers -from catalogue.helpers import active_tab +from catalogue.helpers import active_tab, ajax from catalogue.models import Book, Chunk, Project from fileupload.views import UploadView, PackageView @@ -517,3 +517,22 @@ class GalleryPackageView(GalleryMixin, PackageView): def get_redirect_url(self, slug): return reverse('catalogue_book_gallery', kwargs={'slug': slug}) + + +@ajax(method='get') +def lessons_for_cybernauts(request): + books = Book.objects.filter(for_cybernauts=True) + data = [] + for book in books: + try: + changes = book.get_current_changes() + time_changed = max(change.created_at for change in changes) + xml_url = reverse('catalogue_book_xml', args=[book.slug]) + data.append({ + 'slug': book.slug, + 'url': xml_url, + 'time_changed': time_changed.isoformat(), + }) + except Book.NoTextError: + pass + return {'lessons': data} -- 2.20.1