X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/3b7f8a9926c3de750443801404309a2aa8659d14..08cc1e1601586efffcb2d82f6b1f39a4ed78fd5d:/apps/catalogue/views.py diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index a1a1ab3c..3bee9107 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -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 apiclient import NotAuthorizedError +from apiclient import NotAuthorizedError, ApiError 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 @@ -101,7 +101,7 @@ def create_missing(request, slug=None): if request.method == "POST": form = forms.DocumentCreateForm(request.POST, request.FILES) if form.is_valid(): - + if request.user.is_authenticated(): creator = request.user else: @@ -225,7 +225,7 @@ def book_html(request, slug): if not book.accessible(request): return HttpResponseForbidden("Not authorized.") - doc = book.wldocument(parse_dublincore=False) + doc = book.wldocument() html = doc.as_html() html = html.get_string() if html is not None else '' @@ -395,14 +395,14 @@ def chunk_mass_edit(request): if request.method == 'POST': ids = map(int, filter(lambda i: i.strip() != '', request.POST.get('ids').split(','))) chunks = map(lambda i: Chunk.objects.get(id=i), ids) - + stage = request.POST.get('stage') if stage: try: stage = Chunk.tag_model.objects.get(slug=stage) except Chunk.DoesNotExist: stage = None - + for c in chunks: c.stage = stage @@ -414,7 +414,7 @@ def chunk_mass_edit(request): user = User.objects.get(username=username) except User.DoesNotExist, e: user = None - + for c in chunks: c.user = user @@ -482,10 +482,11 @@ def publish(request, slug): return HttpResponseForbidden("Not authorized.") try: - book.publish(request.user) + protocol = 'https://' if request.is_secure() else 'http://' + book.publish(request.user, host=protocol + request.get_host()) 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()) @@ -517,3 +518,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}