+#class DocumentDublinCoreHandler(BaseHandler):
+# allowed_methods = ('GET', 'POST')
+#
+# @hglibrary
+# def read(self, request, docid, lib):
+# """Read document as raw text"""
+# try:
+# revision = request.GET.get('revision', 'latest')
+#
+# if revision == 'latest':
+# doc = lib.document(docid)
+# else:
+# doc = lib.document_for_revision(revision)
+#
+#
+# if document.id != docid:
+# return response.BadRequest().django_response({'reason': 'name-mismatch',
+# 'message': 'Provided revision is not valid for this document'})
+#
+# bookinfo = dcparser.BookInfo.from_string(doc.data('xml'))
+# return bookinfo.serialize()
+# except (EntryNotFound, RevisionNotFound), e:
+# return response.EntityNotFound().django_response({
+# 'exception': type(e), 'message': e.message})
+#
+# @hglibrary
+# def create(self, request, docid, lib):
+# try:
+# bi_json = request.POST['contents']
+# revision = request.POST['revision']
+#
+# if request.POST.has_key('message'):
+# msg = u"$USER$ " + request.PUT['message']
+# else:
+# msg = u"$AUTO$ Dublin core update."
+#
+# current = lib.document(docid, request.user.username)
+# orig = lib.document_for_revision(revision)
+#
+# if current != orig:
+# return response.EntityConflict().django_response({
+# "reason": "out-of-date",
+# "provided": orig.revision,
+# "latest": current.revision })
+#
+# xmldoc = parser.WLDocument.from_string(current.data('xml'))
+# document.book_info = dcparser.BookInfo.from_json(bi_json)
+#
+# # zapisz
+# ndoc = current.quickwrite('xml', \
+# document.serialize().encode('utf-8'),\
+# message=msg, user=request.user.username)
+#
+# try:
+# # return the new revision number
+# return {
+# "document": ndoc.id,
+# "subview": "dc",
+# "previous_revision": current.revision,
+# "revision": ndoc.revision,
+# 'timestamp': ndoc.revision.timestamp,
+# "url": reverse("docdc_view", args=[ndoc.id])
+# }
+# except Exception, e:
+# if ndoc: lib._rollback()
+# raise e
+# except RevisionNotFound:
+# return response.EntityNotFound().django_response()
+
+class MergeHandler(BaseHandler):
+ allowed_methods = ('POST',)
+
+ @validate_form(forms.MergeRequestForm, 'POST')
+ @hglibrary
+ def create(self, request, form, docid, lib):
+ """Create a new document revision from the information provided by user"""
+ revision = form.cleaned_data['revision']
+
+ # fetch the main branch document
+ doc = lib.document(docid)
+
+ # fetch the base document
+ user_doc = lib.document_for_revision(revision)
+ base_doc = user_doc.latest()
+
+ if base_doc != user_doc:
+ return response.EntityConflict().django_response({
+ "reason": "out-of-date",
+ "provided": str(user_doc.revision),
+ "latest": str(base_doc.revision)
+ })
+
+ if form.cleaned_data['type'] == 'update':
+ # update is always performed from the file branch
+ # to the user branch
+ user_doc_new = base_doc.update(request.user.username)
+
+ if user_doc_new == user_doc:
+ return response.SuccessAllOk().django_response({
+ "result": "no-op"
+ })
+
+ # shared document is the same
+ doc_new = doc