Mailing List Archive

[The Trac Project] #3869: Setting author name if adding attachment to ticket with an external program
#3869: Setting author name if adding attachment to ticket with an external program
--------------------------+-------------------------------------------------
Reporter: basv@sara.nl | Owner: jonas
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: general | Version: 0.10
Severity: normal | Keywords:
--------------------------+-------------------------------------------------
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()
}}}

--
Ticket URL: <http://trac.edgewall.org/ticket/3869>
The Trac Project <http://trac.edgewall.org/>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Tickets" group.
To post to this group, send email to trac-tickets@googlegroups.com
To unsubscribe from this group, send email to trac-tickets-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.se/group/trac-tickets
-~----------~----~----~----~------~----~------~--~---
Re: [The Trac Project] #3869: Setting author name if adding attachment to ticket with an external program [ In reply to ]
#3869: Setting author name if adding attachment to ticket with an external program
--------------------------+-------------------------------------------------
Reporter: basv@sara.nl | Owner: jonas
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: general | Version: 0.10
Severity: normal | Resolution:
Keywords: |
--------------------------+-------------------------------------------------
Old description:

> 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()
> }}}

New description:

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()
}}}

--
Ticket URL: <http://trac.edgewall.org/ticket/3869#comment:1>
The Trac Project <http://trac.edgewall.org/>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Tickets" group.
To post to this group, send email to trac-tickets@googlegroups.com
To unsubscribe from this group, send email to trac-tickets-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.se/group/trac-tickets
-~----------~----~----~----~------~----~------~--~---
Re: [The Trac Project] #3869: Setting author name if adding attachment to ticket with an external program [ In reply to ]
#3869: Setting author name if adding attachment to ticket with an external program
--------------------------+-------------------------------------------------
Reporter: basv@sara.nl | Owner: jonas
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: general | Version: 0.10
Severity: normal | Resolution:
Keywords: |
--------------------------+-------------------------------------------------
Comment (by basv@sara.nl):

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.

--
Ticket URL: <http://trac.edgewall.org/ticket/3869#comment:2>
The Trac Project <http://trac.edgewall.org/>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Tickets" group.
To post to this group, send email to trac-tickets@googlegroups.com
To unsubscribe from this group, send email to trac-tickets-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.se/group/trac-tickets
-~----------~----~----~----~------~----~------~--~---
Re: [The Trac Project] #3869: Setting author name if adding attachment to ticket with an external program [ In reply to ]
#3869: Setting author name if adding attachment to ticket with an external program
--------------------------+-------------------------------------------------
Reporter: basv@sara.nl | Owner: jonas
Type: enhancement | Status: closed
Priority: normal | Milestone:
Component: general | Version: 0.10
Severity: normal | Resolution: wontfix
Keywords: |
--------------------------+-------------------------------------------------
Changes (by mgood):

* status: new => closed
* resolution: => wontfix

Comment:

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)
}}}

--
Ticket URL: <http://trac.edgewall.org/ticket/3869#comment:3>
The Trac Project <http://trac.edgewall.org/>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac Tickets" group.
To post to this group, send email to trac-tickets@googlegroups.com
To unsubscribe from this group, send email to trac-tickets-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.se/group/trac-tickets
-~----------~----~----~----~------~----~------~--~---