+ doc = lib.document(docid, user, rev=rev)
+ except RevisionMismatch, e:
+ # the document exists, but the revision is bad
+ return response.EntityNotFound().django_response({
+ 'reason': 'revision-mismatch',
+ 'message': e.message,
+ 'docid': docid,
+ 'user': user,
+ })
+ except RevisionNotFound, e:
+ # the user doesn't have this document checked out
+ # or some other weird error occured
+ # try to do the checkout
+ if is_prq(user) or (user == request.user.username):
+ try:
+ mdoc = lib.document(docid)
+ doc = mdoc.take(user)
+
+ if is_prq(user):
+ # source revision, should probably change
+ # but there are no changes yet, so...
+ pass
+
+ except RevisionNotFound, e:
+ return response.EntityNotFound().django_response({
+ 'reason': 'document-not-found',
+ 'message': e.message,
+ 'docid': docid
+ })
+ else:
+ return response.EntityNotFound().django_response({
+ 'reason': 'document-not-found',
+ 'message': e.message,
+ 'docid': docid,
+ 'user': user,
+ })
+
+ return {
+ 'name': doc.id,
+ 'user': user,
+ 'html_url': reverse('dochtml_view', args=[doc.id]),
+ 'text_url': reverse('doctext_view', args=[doc.id]),
+ # 'dc_url': reverse('docdc_view', args=[doc.id]),
+ 'gallery_url': reverse('docgallery_view', args=[doc.id]),
+ 'merge_url': reverse('docmerge_view', args=[doc.id]),
+ 'revision': doc.revision,
+ 'timestamp': doc.revision.timestamp,
+ # 'public_revision': doc.revision,
+ # 'public_timestamp': doc.revision.timestamp,
+ }
+
+
+# @hglibrary
+# def update(self, request, docid, lib):
+# """Update information about the document, like display not"""
+# return
+#
+#
+#
+class DocumentHTMLHandler(BaseHandler):
+ allowed_methods = ('GET')
+
+ @validate_form(forms.DocumentRetrieveForm, 'GET')
+ @hglibrary
+ def read(self, request, form, docid, lib, stylesheet='partial'):
+ """Read document as html text"""
+ try:
+ revision = form.cleaned_data['revision']
+ user = form.cleaned_data['user'] or request.user.username
+ document = lib.document_for_rev(revision)
+
+ if document.id != docid:
+ return response.BadRequest().django_response({
+ 'reason': 'name-mismatch',
+ 'message': 'Provided revision is not valid for this document'
+ })
+
+ if document.owner != user:
+ return response.BadRequest().django_response({
+ 'reason': 'user-mismatch',
+ 'message': "Provided revision doesn't belong to user %s" % user
+ })
+
+ for error in check_user(request, user):
+ return error
+
+ return librarian.html.transform(document.data('xml'), is_file=False, \
+ parse_dublincore=False, stylesheet=stylesheet,\
+ options={
+ "with-paths": 'boolean(1)',
+ })
+
+ except (EntryNotFound, RevisionNotFound), e:
+ return response.EntityNotFound().django_response({
+ 'reason': 'not-found', 'message': e.message})
+ except librarian.ParseError, e:
+ return response.InternalError().django_response({
+ 'reason': 'xml-parse-error', 'message': e.message })