- return direct_to_template(request, 'explorer/panels/'+name+'.html',\
- extra_context=extra_context)
-
- @staticmethod
- @ajax_login_required
- @with_repo
- def xmleditor_panel(request, path, panel, repo):
- rpath = file_path(path)
- return {'text': repo.get_file(rpath, file_branch(path, request.user))}
-
- @staticmethod
- @ajax_login_required
- def gallery_panel(request, path, panel):
- return {'form': forms.ImageFoldersForm() }
-
- @staticmethod
- @ajax_login_required
- @with_repo
- def htmleditor_panel(request, path, panel, repo):
- rpath = file_path(path)
- user_branch = file_branch(path, request.user)
- try:
- return {'html': html.transform(repo.get_file(rpath, user_branch), is_file=False)}
- except (ParseError, ValidationError), e:
- return direct_to_template(request, 'explorer/panels/parse_error.html', extra_context={
- 'fileid': path, 'exception_type': type(e).__name__, 'exception': e,
- 'panel_name': panel.display_name})
-
- @staticmethod
- @ajax_login_required
- @with_repo
- def dceditor_panel(request, path, panel, repo):
- user_branch = file_branch(path, request.user)
- rpath = file_path(path)
- try:
- doc_text = repo.get_file(rpath, user_branch)
- document = parser.WLDocument.from_string(doc_text)
- form = forms.DublinCoreForm(info=document.book_info)
- return {'form': form}
- except (ParseError, ValidationError), e:
- return direct_to_template(request, 'explorer/panels/parse_error.html', extra_context={
- 'fileid': path, 'exception_type': type(e).__name__, 'exception': e,
- 'panel_name': panel.display_name})
-
-##
-## Editor "commands" and "dialogs"
-##
-@login_required
-@with_repo
-def print_html(request, path, repo):
- user_branch = file_branch(path, request.user)
- rpath = file_path(path)
- return HttpResponse(
- html.transform(repo.get_file(rpath, user_branch), is_file=False),
- mimetype="text/html")
-
-@login_required
-@with_repo
-def print_xml(request, path, repo):
- user_branch = file_branch(path, request.user)
- rpath = file_path(path)
- return HttpResponse( repo.get_file(rpath, user_branch), mimetype="text/plain; charset=utf-8")
-
-@permission_required('explorer.can_add_files')
-def split_text(request, path):
- rpath = file_path(path)
- valid = False
- if request.method == "POST":
- sform = forms.SplitForm(request.POST, prefix='splitform')
- dcform = forms.DublinCoreForm(request.POST, prefix='dcform')
-
- print "validating sform"
- if sform.is_valid():
- valid = True
- if sform.cleaned_data['autoxml']:
- print "validating dcform"
- valid = dcform.is_valid()
-
- print "valid is ", valid
- if valid:
- uri = path + '$' + sform.cleaned_data['partname']
- child_rpath = file_path(uri)
- repo = hg.Repository(settings.REPOSITORY_PATH)
-
- # save the text into parent's branch
- def split_action():
- if repo._file_exists(child_rpath):
- el = sform._errors.get('partname', ErrorList())
- el.append("Part with this name already exists")
- sform._errors['partname'] = el
- return False
-
- fulltext = sform.cleaned_data['fulltext']
- fulltext = fulltext.replace(u'<include-tag-placeholder />',
- librarian.xinclude_forURI('wlrepo://'+uri) )
-
- repo._write_file(rpath, fulltext.encode('utf-8'))
-
- newtext = sform.cleaned_data['splittext']
- if sform.cleaned_data['autoxml']:
- # this is a horrible hack - really
- bi = dcparser.BookInfo.from_element(librarian.DEFAULT_BOOKINFO.to_etree())
- bi.update(dcform.cleaned_data)
-
- newtext = librarian.wrap_text(newtext, \
- unicode(date.today()), bookinfo=bi )
-
- repo._add_file(child_rpath, newtext.encode('utf-8'))
- repo._commit(message="Split from '%s' to '%s'" % (path, uri), \
- user=request.user.username )
- return True
-
- if repo.in_branch(split_action, file_branch(path, request.user)):
- # redirect to success
- return HttpResponseRedirect( reverse('split-success',\
- kwargs={'path': path})+'?child='+uri)
- else:
- try: # to read the current DC
- repo = hg.Repository(settings.REPOSITORY_PATH)
- fulltext = repo.get_file(rpath, file_branch(path, request.user))
- bookinfo = dcparser.BookInfo.from_string(fulltext)
- except (ParseError, ValidationError):
- bookinfo = librarian.DEFAULT_BOOKINFO
-
- sform = forms.SplitForm(prefix='splitform')
- dcform = forms.DublinCoreForm(prefix='dcform', info=bookinfo)
-
- return direct_to_template(request, 'explorer/split.html', extra_context={
- 'splitform': sform, 'dcform': dcform, 'fileid': path} )
-
-def split_success(request, path):
- return direct_to_template(request, 'explorer/split_success.html',\
- extra_context={'fileid': path, 'cfileid': request.GET['child']} )