+
+
+class GalleryMixin(object):
+ def get_directory(self):
+ return "%s%s/" % (settings.IMAGE_DIR, self.object.gallery)
+
+ @staticmethod
+ def get_object(request, slug):
+ book = get_object_or_404(Book, slug=slug)
+ if not book.gallery:
+ raise Http404
+ return book
+
+
+class GalleryView(GalleryMixin, UploadView):
+
+ def breadcrumbs(self):
+ return [
+ (u'moduły', reverse('catalogue_document_list')),
+ (self.object.title, self.object.get_absolute_url()),
+ (u'materiały',),
+ ]
+
+
+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}