Commits

Olemis Lang committed ab2e8e9

Trac Rpc [ refs rpc-307 ] Augment Milestone RPC by adding attachment methods ... UNTESTED

Comments (0)

Files changed (1)

trunk/tracrpc/ticket.py

         # FIXME: Remove
         return 0
 
-def ticketModelFactory(cls, cls_attributes):
+def ticketModelFactory(cls, cls_attributes, has_attachments=False):
     """ Return a class which exports an interface to trac.ticket.model.<cls>. """
+
+    realm = cls.__name__.lower()
+
     class TicketModelImpl(Component):
         implements(IXMLRPCHandler)
 
+        def __init__(self):
+            if has_attachments:
+                self._attachment = AttachmentRPCDelegate(self.env, realm, str)
+
         def xmlrpc_namespace(self):
-            return 'ticket.' + cls.__name__.lower()
+            return 'ticket.' + realm
 
         def xmlrpc_methods(self):
             yield ('TICKET_VIEW', ((list,),), self.getAll)
             yield ('TICKET_ADMIN', ((None, str, dict),), self.create)
             yield ('TICKET_ADMIN', ((None, str, dict),), self.update)
 
+            if has_attachments:
+                for sig in self._attachment.xmlrpc_methods():
+                    yield sig
+
         def getAll(self, req):
             for i in cls.select(self.env):
                 yield i.name
-        getAll.__doc__ = """ Get a list of all ticket %s names. """ % cls.__name__.lower()
+        getAll.__doc__ = """ Get a list of all ticket %s names. """ % realm
 
         def get(self, req, name):
             i = cls(self.env, name)
                     v = default
                 attributes[k] = v
             return attributes
-        get.__doc__ = """ Get a ticket %s. """ % cls.__name__.lower()
+        get.__doc__ = """ Get a ticket %s. """ % realm
 
         def delete(self, req, name):
             cls(self.env, name).delete()
-        delete.__doc__ = """ Delete a ticket %s """ % cls.__name__.lower()
+        delete.__doc__ = """ Delete a ticket %s """ % realm
 
         def create(self, req, name, attributes):
             i = cls(self.env)
             for k, v in attributes.iteritems():
                 setattr(i, k, v)
             i.insert();
-        create.__doc__ = """ Create a new ticket %s with the given attributes. """ % cls.__name__.lower()
+        create.__doc__ = """ Create a new ticket %s with the given attributes. """ % realm
 
         def update(self, req, name, attributes):
             self._updateHelper(name, attributes).update()
-        update.__doc__ = """ Update ticket %s with the given attributes. """ % cls.__name__.lower()
+        update.__doc__ = """ Update ticket %s with the given attributes. """ % realm
 
         def _updateHelper(self, name, attributes):
             i = cls(self.env, name)
             for k, v in attributes.iteritems():
                 setattr(i, k, v)
             return i
-    TicketModelImpl.__doc__ = """ Interface to ticket %s objects. """ % cls.__name__.lower()
+    TicketModelImpl.__doc__ = """ Interface to ticket %s objects. """ % realm
     TicketModelImpl.__name__ = '%sRPC' % cls.__name__
     return TicketModelImpl
 
 
 ticketModelFactory(model.Component, {'name': '', 'owner': '', 'description': ''})
 ticketModelFactory(model.Version, {'name': '', 'time': 0, 'description': ''})
-ticketModelFactory(model.Milestone, {'name': '', 'due': 0, 'completed': 0, 'description': ''})
+ticketModelFactory(model.Milestone, {'name': '', 'due': 0, 'completed': 0, 'description': ''},
+                   has_attachments=True)
 
 ticketEnumFactory(model.Type)
 ticketEnumFactory(model.Resolution)