fix unicode problems in gallery view
[redakcja.git] / apps / catalogue / views.py
index a1a1ab3..94710ca 100644 (file)
@@ -21,10 +21,10 @@ from django.utils.translation import ugettext_lazy as _
 from django.views.decorators.http import require_POST
 from django.template import RequestContext
 
 from django.views.decorators.http import require_POST
 from django.template import RequestContext
 
-from apiclient import NotAuthorizedError
+from apiclient import NotAuthorizedError, ApiError
 from catalogue import forms
 from catalogue import helpers
 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
 
 from catalogue.models import Book, Chunk, Project
 from fileupload.views import UploadView, PackageView
 
@@ -485,7 +485,7 @@ def publish(request, slug):
         book.publish(request.user)
     except NotAuthorizedError:
         return http.HttpResponseRedirect(reverse('apiclient_oauth'))
         book.publish(request.user)
     except NotAuthorizedError:
         return http.HttpResponseRedirect(reverse('apiclient_oauth'))
-    except BaseException, e:
+    except ApiError, e:
         return http.HttpResponse(e)
     else:
         return http.HttpResponseRedirect(book.get_absolute_url())
         return http.HttpResponse(e)
     else:
         return http.HttpResponseRedirect(book.get_absolute_url())
@@ -517,3 +517,22 @@ class GalleryPackageView(GalleryMixin, PackageView):
 
     def get_redirect_url(self, slug):
         return reverse('catalogue_book_gallery', kwargs={'slug': slug})
 
     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}