project sell info and initial synchro support
[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     template_name = 'sources/upload.html'
16
17     def get_object(self, request, sid):
18         source = get_object_or_404(models.Source, id=sid)
19         return source
20
21     def breadcrumbs(self):
22         return [
23             (_('sources'),),
24             (self.object.name, self.object.get_absolute_url()),
25             (_('upload'),)
26         ]
27
28     def get_directory(self):
29         return self.object.get_upload_directory()
30
31     def form_valid(self, form):
32         response = super().form_valid(form)
33         self.object.touch()
34         return response
35
36     def delete(self, request, *args, **kwargs):
37         response = super().delete(request, *args, **kwargs)
38         self.object.touch()
39         return response
40
41
42 def prepare(request, bsid):
43     bs = get_object_or_404(models.BookSource, id=bsid)
44
45     if request.POST:
46         dbook = bs.prepare_document(request.user)
47         return redirect('wiki_editor', dbook.slug, dbook[0].slug)
48     else:
49         return render(
50             request,
51             'sources/prepare.html',
52             {
53                 'book_source': bs,
54             }
55         )