-def file_xml(request, path):
- if request.method == 'POST':
- form = forms.BookForm(request.POST)
- if form.is_valid():
- repo.add_file(path, form.cleaned_data['text'])
- # issues = _get_issues_for_file(path)
- # commit_message = _add_references(form.cleaned_data['commit_message'], issued)
- repo.commit(message=form.cleaned_data['commit_message'], user=form.cleaned_data['user'])
- return HttpResponseRedirect(request.get_full_path())
- else:
- form = forms.BookForm()
- form.fields['text'].initial = repo.get_file(path).data()
-
- return direct_to_template(request, 'explorer/file_xml.html', extra_context={
- 'hash': path,
- 'form': form,
- 'image_folders_form': forms.ImageFoldersForm(),
- })
+def file_branch(fileid, user=None):
+ parts = fileid.split('$')
+ return ('personal_'+ user.username + '_' if user is not None else '') \
+ + 'file_' + parts[0]
+
+def file_path(fileid):
+ return 'pub_'+fileid+'.xml'
+
+def with_repo(view):
+ """Open a repository for this view"""
+ def view_with_repo(request, *args, **kwargs):
+ kwargs['repo'] = wlrepo.open_library(settings.REPOSITORY_PATH, 'hg')
+ return view(request, *args, **kwargs)
+ return view_with_repo
+
+#
+def ajax_login_required(view):
+ """Similar ro @login_required, but instead of redirect,
+ just return some JSON stuff with error."""
+ def view_with_auth(request, *args, **kwargs):
+ if request.user.is_authenticated():
+ return view(request, *args, **kwargs)
+ # not authenticated
+ return HttpResponse( json.dumps({'result': 'access_denied', 'errors': ['Brak dostępu.']}) );
+ return view_with_auth
+
+@login_required
+# @with_repo
+def display_editor(request, path):
+ # this is the only entry point where we create an autobranch for the user
+ # if it doesn't exists. All other views SHOULD fail.
+ #def ensure_branch_exists():
+ # parent = repo.get_branch_tip('default')
+ # repo._create_branch(file_branch(path, request.user), parent)