]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/views/xmlrpc.py
tox: Add tox.ini file
[patchwork] / apps / patchwork / views / xmlrpc.py
index 1d9d389c528a815342d6953b5b8b47147fe8a21f..84ed4089b346812f241789e35af4e69624302080 100644 (file)
@@ -26,6 +26,7 @@ from django.http import HttpResponse, HttpResponseRedirect, \
 from django.core import urlresolvers
 from django.contrib.auth import authenticate
 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
@@ -58,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 == '':
@@ -99,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
@@ -129,7 +130,7 @@ def xmlrpc(request):
     try:
         ret = dispatcher._marshaled_dispatch(request)
         response.write(ret)
-    except Exception, e:
+    except Exception:
         return HttpResponseServerError()
 
     return response
@@ -167,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"),
         }
 
@@ -189,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"),
@@ -290,6 +300,7 @@ def patch_list(filter={}):
             "project_id",
             "submitter_id",
             "delegate_id",
+            "archived",
             "state_id",
             "date",
             "commit_ref",
@@ -317,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]
@@ -328,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)
 
@@ -368,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 ""