Ticket #598: attachment-description-xmlrpc-1070.patch

File attachment-description-xmlrpc-1070.patch, 2.1 kB (added by steffenp@gmx.de, 2 years ago)

Extends listAttachment() and putAttachment() for retrieving and setting of attachment attributes.

  • ticket.py

    old new  
    2727        yield ('TICKET_VIEW', ((list, int),), self.listAttachments) 
    2828        yield ('TICKET_VIEW', ((xmlrpclib.Binary, int, str),), self.getAttachment) 
    2929        yield ('TICKET_APPEND', 
    30                ((str, int, str, xmlrpclib.Binary, bool), 
    31                 (str, int, str, xmlrpclib.Binary)), 
     30               ((str, int, str, str, xmlrpclib.Binary, bool), 
     31                (str, int, str, str, xmlrpclib.Binary)), 
    3232               self.putAttachment) 
    3333        yield ('TICKET_ADMIN', ((bool, int, str),), self.deleteAttachment) 
    3434 
     
    7878    changeLog.__doc__ = pydoc.getdoc(model.Ticket.get_changelog) 
    7979 
    8080    def listAttachments(self, req, ticket): 
    81         """ Lists attachments for a given ticket. """ 
    82         return [a.filename for a in Attachment.select(self.env, 'ticket', ticket)] 
     81        """ Lists attachments for a given ticket. Returns [filename, description, size, time, author] 
     82        for each attachment.""" 
     83        out = [] 
     84        for t in Attachment.select(self.env, 'ticket', ticket): 
     85            out.append((t.filename, t.description or '', t.size, t.time, t.author)) 
     86        return out 
    8387 
    8488    def getAttachment(self, req, ticket, filename): 
    8589        """ returns the content of an attachment. """ 
    8690        attachment = Attachment(self.env, 'ticket', ticket, filename) 
    8791        return xmlrpclib.Binary(attachment.open().read()) 
    8892 
    89     def putAttachment(self, req, ticket, filename, data, replace=True): 
     93    def putAttachment(self, req, ticket, filename, description, data, replace=True): 
    9094        """ Add an attachment, optionally (and defaulting to) overwriting an 
    9195        existing one. Returns filename.""" 
    9296        if not model.Ticket(self.env, ticket).exists: 
     
    99103                pass 
    100104        attachment = Attachment(self.env, 'ticket', ticket) 
    101105        attachment.author = req.authname or 'anonymous' 
     106        attachment.description = description 
    102107        attachment.insert(filename, StringIO(data.data), len(data.data)) 
    103108        return attachment.filename 
    104109