X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Fviews%2Fxmlrpc.py;h=84ed4089b346812f241789e35af4e69624302080;hb=bdd8d68219c2eed373a642a6e3818f79fc4d5be9;hp=3310e69651ae5c52347e5e6af479b9dfd062865f;hpb=bf0aef79a1e5b1d0b78c10df4a610b0a7b2d365f;p=patchwork diff --git a/apps/patchwork/views/xmlrpc.py b/apps/patchwork/views/xmlrpc.py index 3310e69..84ed408 100644 --- a/apps/patchwork/views/xmlrpc.py +++ b/apps/patchwork/views/xmlrpc.py @@ -20,15 +20,13 @@ # Patchwork XMLRPC interface # -from django.core.exceptions import ImproperlyConfigured from SimpleXMLRPCServer import SimpleXMLRPCDispatcher from django.http import HttpResponse, HttpResponseRedirect, \ HttpResponseServerError -from django.conf import settings from django.core import urlresolvers -from django.shortcuts import render_to_response from django.contrib.auth import authenticate -from patchwork.models import Patch, Project, Person, Bundle, State +from patchwork.models import Patch, Project, Person, State +from patchwork.views import patch_to_mbox from django.views.decorators.csrf import csrf_exempt import sys @@ -61,9 +59,9 @@ class PatchworkXMLRPCDispatcher(SimpleXMLRPCDispatcher): def _user_for_request(self, request): auth_header = None - if request.META.has_key('HTTP_AUTHORIZATION'): + if 'HTTP_AUTHORIZATION' in request.META: auth_header = request.META.get('HTTP_AUTHORIZATION') - elif request.META.has_key('Authorization'): + elif 'Authorization' in request.META: auth_header = request.META.get('Authorization') if auth_header is None or auth_header == '': @@ -102,7 +100,7 @@ class PatchworkXMLRPCDispatcher(SimpleXMLRPCDispatcher): def _marshaled_dispatch(self, request): try: - params, method = xmlrpclib.loads(request.raw_post_data) + params, method = xmlrpclib.loads(request.body) response = self._dispatch(request, method, params) # wrap response in a singleton tuple @@ -132,7 +130,7 @@ def xmlrpc(request): try: ret = dispatcher._marshaled_dispatch(request) response.write(ret) - except Exception, e: + except Exception: return HttpResponseServerError() return response @@ -170,11 +168,19 @@ def project_to_dict(obj): def person_to_dict(obj): """Return a trimmed down dictionary representation of a Person object which is OK to send to the client.""" + + # Make sure we don't return None even if the user submitted a patch + # with no real name. XMLRPC can't marshall None. + if obj.name is not None: + name = obj.name + else: + name = obj.email + return \ { 'id' : obj.id, 'email' : obj.email, - 'name' : obj.name, + 'name' : name, 'user' : unicode(obj.user).encode("utf-8"), } @@ -192,6 +198,7 @@ def patch_to_dict(obj): 'project_id' : obj.project_id, 'state' : unicode(obj.state).encode("utf-8"), 'state_id' : obj.state_id, + 'archived' : obj.archived, 'submitter' : unicode(obj.submitter).encode("utf-8"), 'submitter_id' : obj.submitter_id, 'delegate' : unicode(obj.delegate).encode("utf-8"), @@ -293,6 +300,7 @@ def patch_list(filter={}): "project_id", "submitter_id", "delegate_id", + "archived", "state_id", "date", "commit_ref", @@ -320,6 +328,9 @@ def patch_list(filter={}): elif parts[0] == 'submitter_id': dfilter['submitter'] = Person.objects.filter(id = filter[key])[0] + elif parts[0] == 'delegate_id': + dfilter['delegate'] = Person.objects.filter(id = + filter[key])[0] elif parts[0] == 'state_id': dfilter['state'] = State.objects.filter(id = filter[key])[0] @@ -331,7 +342,7 @@ def patch_list(filter={}): patches = Patch.objects.filter(**dfilter) if max_count > 0: - return map(patch_to_dict, patches)[:max_count] + return map(patch_to_dict, patches[:max_count]) else: return map(patch_to_dict, patches) @@ -371,7 +382,7 @@ def patch_get_mbox(patch_id): """Return mbox string for the given patch ID.""" try: patch = Patch.objects.filter(id = patch_id)[0] - return patch.mbox().as_string() + return patch_to_mbox(patch).as_string(True) except: return ""