1 # -*- encoding: utf-8 -*-
3 __author__= "Ćukasz Rekucki"
4 __date__ = "$2009-09-25 15:49:50$"
5 __doc__ = "Module documentation."
7 from piston.handler import BaseHandler, AnonymousBaseHandler
9 from api.utils import hglibrary
10 from explorer.models import PullRequest
11 from api.response import *
13 class PullRequestListHandler(BaseHandler):
14 allowed_methods = ('GET',)
16 def read(self, request):
17 if request.user.has_perm('explorer.book.can_share'):
18 return PullRequest.objects.all()
20 return PullRequest.objects.filter(commiter=request.user)
23 class PullRequestHandler(BaseHandler):
24 allowed_methods = ('GET', 'PUT')
26 def read(self, request, prq_id):
27 return PullRequest.objects.get(id=prq_id)
29 def update(self, request, prq_id):
30 """Change the status of request"""
32 if not request.user.has_perm('explorer.document.can_share'):
33 return AccessDenied().django_response("Insufficient priviliges")
35 prq = PullRequest.objects.get(id=prq_id)
38 return EntityNotFound().django_response()
41 action = request.PUT.get('action', None)
43 if action == 'accept' and prq.status == 'N':
44 return self.accept_merge(prq)
45 elif action == 'reject' and prq.status in ['N', 'R']:
46 return self.reject_merge(prq)
48 return BadRequest().django_response()
52 def accept_merge(self, prq, lib):
53 doc = lib.document( prq.document )
54 udoc = doc.take( prq.comitter.username )
55 success, changed = udoc.share(prq.comment)
58 return EntityConflict().django_response()
63 prq.merged_revisions = unicode(doc.revision)
66 return SuccessAllOk().django_response({
71 def reject_merge(self, prq, lib):
75 return SuccessAllOk().django_response({