class MergeRequestForm(forms.Form):
# should the target document revision be updated or shared
- type = forms.ChoiceField(choices=('update', 'share'))
+ type = forms.ChoiceField(choices=(('update', 'Update'), ('share', 'Share')) )
# which revision to update/share
target_revision = forms.RegexField('[0-9a-f]{40}')
try:
lock = lib.lock()
try:
+ print "DOCID", docid
+
doc = lib.document_create(docid)
# document created, but no content yet
"updated_revision": ndoc.revision
}
except Exception, e:
- lib.rollback()
- raise e
-
- except (RevisionNotFound, KeyError):
- return response.EntityNotFound().django_response()
+ lib._rollback()
+ raise e
+ except RevisionNotFound, e:
+ return response.EntityNotFound().django_response(e)
#
# Dublin Core handlers
"""Read document as raw text"""
try:
if revision == 'latest':
- document = lib.document(docid)
+ doc = lib.document(docid)
else:
- document = lib.document_for_rev(revision)
+ doc = lib.document_for_rev(revision)
bookinfo = dcparser.BookInfo.from_string(doc.data('xml'))
return bookinfo.serialize()
document.serialize().encode('utf-8'),\
message=msg, user=request.user.username)
- return {
- "document": ndoc.id,
- "subview": "xml",
- "previous_revision": prev,
- "updated_revision": ndoc.revision
- }
- except (RevisionNotFound, KeyError):
+ try:
+ # return the new revision number
+ return {
+ "document": ndoc.id,
+ "subview": "dc",
+ "previous_revision": current.revision,
+ "updated_revision": ndoc.revision
+ }
+ except Exception, e:
+ lib._rollback()
+ raise e
+ except RevisionNotFound:
return response.EntityNotFound().django_response()
-
class MergeHandler(BaseHandler):
allowed_methods = ('POST',)
- @validate_form(forms.MergeRequestForm)
+ @validate_form(forms.MergeRequestForm, 'POST')
@hglibrary
def create(self, request, form, docid, lib):
"""Create a new document revision from the information provided by user"""
if target_rev == 'latest':
target_rev = udoc.revision
- if udoc.revision != target_rev:
+ if str(udoc.revision) != target_rev:
# user think doesn't know he has an old version
# of his own branch.
# update his internal state.
return response.EntityConflict().django_response({
"reason": "out-of-date",
- "provided": target_revision,
+ "provided": target_rev,
"latest": udoc.revision })
- if not request.user.has_permission('explorer.pull_request.can_add'):
+ if not request.user.has_perm('explorer.book.can_share'):
# User is not permitted to make a merge, right away
# So we instead create a pull request in the database
prq = PullRequest(
- commiter=request.uset.username,
+ comitter=request.user,
document=docid,
- source_revision = udoc.revision,
+ source_revision = str(udoc.revision),
status="N",
- comment = form.cleaned_data['comment']
+ comment = form.cleaned_data['comment'] or '$AUTO$ Document shared.'
)
prq.save()
- return response.RequestAccepted()
+ return response.RequestAccepted().django_response(\
+ ticket_status=prq.status, \
+ ticket_uri=reverse("pullrequest_view", args=[prq.id]) )
if form.cleanded_data['type'] == 'update':
# update is always performed from the file branch
+++ /dev/null
-#!/usr/bin/env python
-# -*- conding: utf-8 -*-
-__author__="lreqc"
-__date__ ="$2009-09-08 14:31:26$"
-
-from django.core.management.base import BaseCommand
-from django.utils import simplejson as json
-from django.test.client import Client
-from django.core.urlresolvers import reverse
-
-from optparse import make_option
-
-class Command(BaseCommand):
-
- option_list = BaseCommand.option_list + (
- make_option('-u', '--user', action='store', dest='username'),
- make_option('-p', '--password', action='store', dest='password'),
- make_option('-d', '--dublin-core', action='store_true', dest='dc'),
- )
-
- def handle(self, *args, **options):
- client = Client()
- if not options['username'] or not options['password']:
- raise CommandError("You must provide login data")
-
- client.login(username=options['username'], \
- password=options['password'])
-
- print options['username'], options['password']
-
- filename = args[0]
- bookname = args[1]
-
- print "Uploading '%s' as document '%s'" % (filename, bookname)
- print "Wth DC template" if options['dc'] else ""
-
- print client.post( reverse("document_list_view"),\
- {
- 'bookname': bookname,
- 'ocr_file': open(filename),
- 'generate_dc': options['dc'] } )
-
from piston.resource import Resource
from api.utils import DjangoAuth
-
-
-
authdata = {'authentication': DjangoAuth()}
#
document_dc_resource = Resource(dh.DocumentDublinCoreHandler, **authdata)
document_merge = Resource(dh.MergeHandler, **authdata)
+import api.handlers.manage_handlers as mh
+
+pullrequest_collection = Resource(mh.PullRequestListHandler, **authdata)
+pullrequest_rsrc = Resource(mh.PullRequestHandler, **authdata)
+
#
# Toolbar resources
#
toolbar_buttons = Resource(th.ToolbarHandler, **authdata)
scriptlets = Resource(th.ScriptletsHandler, **authdata)
+
+
__all__ = [
'library_resource',
'document_resource',
'document_dc_resource',
'document_merge',
'toolbar_buttons',
- 'scriptlets'
+ 'scriptlets',
+ 'pullrequest_collection',
+ 'pullrequest_rsrc',
]
\ No newline at end of file
# url(r'^hello\.(?P<emitter_format>.+)$', hello_resource),
# Toolbar
- url(r'^toolbar/buttons$', toolbar_buttons, {'emitter_format': 'json'}),
-
- # Toolbar
+ url(r'^toolbar/buttons$', toolbar_buttons, {'emitter_format': 'json'}),
url(r'^toolbar/scriptlets$', scriptlets, {'emitter_format': 'json'}),
+
+ # Pull requests
+ url(r"^pull-requests$", pullrequest_collection,
+ {'emitter_format': 'json'} ),
+
+ url(r"^pull-requests/(?P<prq_id>\d+)$", pullrequest_rsrc,
+ {'emitter_format': 'json'}, name="pullrequest_view" ),
# Documents
url(r'^documents$', library_resource,
document_dc_resource, {'emitter_format': 'json'},
name="docdc_view"),
- url(urlpath(r'documents', DOC, 'revision'),
+ url(urlpath(r'documents', DOC, 'revision', format=False),
document_merge, {'emitter_format': 'json'}, name="docmerge_view")
# url(r'^documents/(?P<docid>[^/]+)/parts$',
form = formclass(getattr(request, source), request.FILES)
if not form.is_valid():
- errorlist = [{'field': k, 'errors': e} for k, e in form.errors.items()]
+ errorlist = [{'field': k, 'errors': str(e)} for k, e in form.errors.items()]
return api.response.BadRequest().django_response(errorlist)
kwargs['form'] = form
class Book(models.Model):
class Meta:
- permissions = (
- ("can_add_files", "Can do hg add."),
+ permissions = (
+ ("can_share", "Can share documents without pull requests."),
)
abstract=True
pass
f.close()
l._fileadd(r(entry))
- return self.invoke_and_commit(write, lambda d: (msg, user))
+ return self.invoke_and_commit(write, lambda d: (msg, self.owner))
def invoke_and_commit(self, ops,
before_commit, rollback=False):
return self._library.document(docid=self.id, user=user)
except Exception, e:
# rollback the last commit
- self._library.rollback()
+ self._library._rollback()
raise e
finally:
lock.release()