b1513e0cb15792ae41eb64ec07b692971ea501fa
[redakcja.git] / apps / explorer / views.py
1 from librarian import html
2 import hg
3
4 from django.views.generic.simple import direct_to_template
5 from django.conf import settings
6 from django.http import HttpResponseRedirect
7
8 from explorer import forms
9
10
11 repo = hg.Repository(settings.REPOSITORY_PATH)
12
13
14 def file_list(request):
15     return direct_to_template(request, 'explorer/file_list.html', extra_context={
16         'objects': repo.all_files(),
17     })
18
19
20 def file_xml(request, path):
21     if request.method == 'POST':
22         form = forms.BookForm(request.POST)
23         if form.is_valid():
24             repo.add_file(path, form.cleaned_data['text'])
25             repo.commit()
26             return HttpResponseRedirect('/')
27     else:
28         form = forms.BookForm()
29         form.fields['text'].initial = repo.get_file(path).data()
30     
31     return direct_to_template(request, 'explorer/file_xml.html', extra_context={
32         'hash': path,
33         'form': form,
34     })
35
36
37 def file_html(request, path):
38     return direct_to_template(request, 'explorer/file_html.html', extra_context={
39         'object': html.transform(repo.get_file(path).data(), is_file=False),
40         'hash': path,
41     })
42