+ 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(u'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.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
+ import urllib
+ uri = urllib.quote( unicode(uri).encode('utf-8'))
+ return HttpResponseRedirect( reverse('split-success',\
+ kwargs={'path': path})+'?child='+uri )