1 from django.http import HttpResponse
2 from django.shortcuts import render, get_object_or_404, redirect
3 from django.utils.translation import gettext as _
4 from django.views.generic import DetailView
5 from fileupload.views import UploadView
6 import catalogue.models
11 class SourceView(DetailView):
15 class SourceUploadView(UploadView):
16 template_name = 'sources/upload.html'
18 def get_object(self, request, sid):
19 source = get_object_or_404(models.Source, id=sid)
22 def breadcrumbs(self):
25 (self.object.name, self.object.get_absolute_url()),
29 def get_directory(self):
30 return self.object.get_upload_directory()
32 def form_valid(self, form):
33 response = super().form_valid(form)
37 def delete(self, request, *args, **kwargs):
38 response = super().delete(request, *args, **kwargs)
43 def prepare(request, pk):
44 book = get_object_or_404(catalogue.models.Book, id=pk)
47 dbook = models.BookSource.prepare_document(book, request.user)
48 return redirect('wiki_editor', dbook.slug, dbook[0].slug)
50 return redirect(book.get_absolute_url())