1 from librarian import html
3 from django.utils import simplejson as json
5 from django.views.generic.simple import direct_to_template
6 from django.conf import settings
7 from django.http import HttpResponseRedirect
9 from explorer import forms, models
11 repo = hg.Repository(settings.REPOSITORY_PATH)
13 def file_list(request):
14 return direct_to_template(request, 'explorer/file_list.html', extra_context={
15 'objects': repo.all_files(),
19 def file_xml(request, path):
20 if request.method == 'POST':
21 form = forms.BookForm(request.POST)
23 repo.add_file(path, form.cleaned_data['text'])
24 # issues = _get_issues_for_file(path)
25 # commit_message = _add_references(form.cleaned_data['commit_message'], issued)
26 repo.commit(message=form.cleaned_data['commit_message'], user=form.cleaned_data['user'])
27 return HttpResponseRedirect(request.get_full_path())
29 form = forms.BookForm()
30 form.fields['text'].initial = repo.get_file(path).data()
32 return direct_to_template(request, 'explorer/file_xml.html', extra_context={
35 'image_folders_form': forms.ImageFoldersForm(),
39 def file_html(request, path):
40 return direct_to_template(request, 'explorer/file_html.html', extra_context={
41 'object': html.transform(repo.get_file(path).data(), is_file=False),
43 'image_folders_form': forms.ImageFoldersForm(),
46 def folder_images(request, folder):
47 return direct_to_template(request, 'explorer/folder_images.html', extra_context={
48 'images': models.get_images_from_folder(folder),
51 def _add_references(message, issues):
53 message += " refs #%d " % issue.id
56 def _get_issues_for_file(path):
57 if not path.endswith('.xml'):
58 raise ValueError('Path must end with .xml')
61 uf = urllib2.urlopen(settings.REDMINE_URL + 'publications/%s/issues' % book_id)
64 return json.loads(uf.read())