temporary attributes for bible tags
[redakcja.git] / src / sources / views.py
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
7 from . import models
8
9
10 # TODO 
11 class SourceView(DetailView):
12     model = models.Source
13
14
15 class SourceUploadView(UploadView):
16     template_name = 'sources/upload.html'
17
18     def get_object(self, request, sid):
19         source = get_object_or_404(models.Source, id=sid)
20         return source
21
22     def breadcrumbs(self):
23         return [
24             (_('sources'),),
25             (self.object.name, self.object.get_absolute_url()),
26             (_('upload'),)
27         ]
28
29     def get_directory(self):
30         return self.object.get_upload_directory()
31
32     def form_valid(self, form):
33         response = super().form_valid(form)
34         self.object.touch()
35         return response
36
37     def delete(self, request, *args, **kwargs):
38         response = super().delete(request, *args, **kwargs)
39         self.object.touch()
40         return response
41
42
43 def prepare(request, pk):
44     book = get_object_or_404(catalogue.models.Book, id=pk)
45
46     if request.POST:
47         dbook = models.BookSource.prepare_document(book, request.user)
48         return redirect('wiki_editor', dbook.slug, dbook[0].slug)
49     else:
50         return redirect(book.get_absolute_url())