+from toolbar import models as toolbar_models
+
+from django.forms.util import ErrorList
+
+import wlrepo
+
+#
+# Some useful decorators
+
+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)
+
+# try:
+ # repo.with_wlock(ensure_branch_exists)
+
+ return direct_to_template(request, 'explorer/editor.html', extra_context={
+ 'fileid': path,
+ 'panel_list': ['lewy', 'prawy'],
+ 'availble_panels': models.EditorPanel.objects.all(),
+ # 'scriptlets': toolbar_models.Scriptlet.objects.all()