Edgewall Software
Modify

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#3869 closed enhancement (wontfix)

Setting author name if adding attachment to ticket with an external program

Reported by: basv@… Owned by: Jonas Borgström
Priority: normal Milestone:
Component: general Version: 0.10
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Christian Boos)

With email2trac we add attachments to tickets. I used to do it with SQL statements but trac provides some functions. My problem is that if i use this function the author name is not set

fd = open(path)
att = attachment.Attachment(self.env, 'ticket', ticket['id'])
att.insert(url_filename, fd, filesize)
fd.close()

I have made a small patch to acomplish this:

--- attachment.py.org   2006-10-05 15:22:40.659671363 +0200
+++ attachment.py       2006-10-05 13:32:53.154988857 +0200
@@ -34,7 +34,7 @@

 class Attachment(object):

-    def __init__(self, env, parent_type, parent_id, filename=None, db=None):
+    def __init__(self, env, parent_type, parent_id, filename=None, db=None, author=None):
         self.env = env
         self.parent_type = parent_type
         self.parent_id = str(parent_id)
@@ -48,6 +48,10 @@
             self.author = None
             self.ipnr = None

+       if author:
+            self.author = author
+
+
     def _fetch(self, filename, db=None):
         if not db:
             db = self.env.get_db_cnx()

Now i can this to set the author name:

fd = open(path)
att = attachment.Attachment(self.env, 'ticket', ticket['id'], None, None, self.author)
att.insert(url_filename, fd, filesize)
fd.close()

Attachments (0)

Change History (3)

comment:1 by Christian Boos, 18 years ago

Description: modified (diff)

comment:2 by basv@…, 18 years ago

After driving home. We have the ticket number so we also could get the author's name from that database. So we do not have to change the Attachment API.

comment:3 by Matthew Good, 18 years ago

Resolution: wontfix
Status: newclosed

That's how all the Trac model classes work. The constructor only takes the fields needed to initialize the class from the database (if it exists). You should set other fields on the object once it's been initialized:

att = attachment.Attachment(self.env, 'ticket', ticket['id'])
att.author = 'abc'
att.description = 'xyz'
att.insert(url_filename, fd, filesize)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonas Borgström.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jonas Borgström to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.