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