how to query a local db from trac

16 views
Skip to first unread message

comadreha

unread,
Mar 22, 2013, 5:03:49 AM3/22/13
to trac...@googlegroups.com

Hi!

I have a trac system that is connected to a local oracle db (for authorization purposes). More specifically, the connection with the local oracle db is achieved using a python plugin (it is a .py code inside the plugin folder). I would like to add an additional functionality to the ticketing system, to automatically query the local oracle db for obtaining additional information for the ticket sender (until now only the sender's trac username is visible). In addition, i have created a python function, which takes a trac username as an input and returns additional information for the ticket sender by querying the local oracle database. However, how can i embed this function to the trac system ?

Thanks in advance!

Olemis Lang

unread,
Mar 22, 2013, 12:04:11 PM3/22/13
to trac...@googlegroups.com
On 3/22/13, comadreha <coma...@gmail.com> wrote:
>
>
> Hi!
>

:)
There are two ways : ITicketChangeListener and ITicketManipulator

the differences between them mostly resides on whether you'd like to
veto ticket edit based on your data et al. (ITicketManipulator) or not
(ITicketChangeListener)

> Thanks in advance!
>

hope that helps .

--
Regards,

Olemis.

Apache™ Bloodhound contributor
http://issues.apache.org/bloodhound

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Steffen Hoffmann

unread,
Mar 22, 2013, 4:55:34 PM3/22/13
to trac...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 22.03.2013 10:03, comadreha wrote:
...
> In addition, i have created a python function, which takes a trac
> username as an input and returns additional information for the
> ticket sender by querying the local oracle database. However, how can
> i embed this function to the trac system ?

It depends on how you want to use that information. For bringing it into
ticket views you'll want to implement the IRequestFilter [1] interface
to act on calls to tickets and ITemplateStreamFilter [2] for inserting
some HTML containing that additional information into the ticket page on
the fly.

If you want to insert information directly into ticket fields, you'll
want to take a look at the ITicketManipulator [3] especially its
'prepare_ticket' method, but unluckily it is unused until now. Speaking
about the ITicketChangeListener, its whole point is to notify and
possibly act upon ticket creation/changes, but I doubt that this will be
what you need/want.

Steffen Hoffmann


[1]
http://trac.edgewall.org/wiki/TracDev/PluginDevelopment/ExtensionPoints/trac.web.api.IRequestFilter
[2]
http://trac.edgewall.org/wiki/TracDev/PluginDevelopment/ExtensionPoints/trac.web.api.ITemplateStreamFilter
[3]
http://trac.edgewall.org/wiki/TracDev/PluginDevelopment/ExtensionPoints/trac.ticket.api.ITicketManipulator
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlFMxUUACgkQ31DJeiZFuHeAigCfWk0YKhsyTApjvMDJi+riGEb4
+KwAoLPbTlCBm76gLz/OXE8/1iUPChaT
=CsQt
-----END PGP SIGNATURE-----

Constantinos Lalos

unread,
Mar 28, 2013, 6:02:19 AM3/28/13
to trac...@googlegroups.com
Hi,

Thank you very much for your reply. I have implemented IRequestFilter interface, which writes the result from a db query into a custom ticket label (this custom ticket label is defined in conf/trac.ini). Now, i have the following problem. By default, the db returns a string, which consists of greek characters. Unfortunately, this string cannot be recognized on the ticket interface (it appears a string that consist of multiple '?' , while it should be a string with greek characters). I use the following code to do this,

info = cursor.fetchone()

s_info = str(info)

if info:
    self.config.set('ticket-custom','details.value',s_info)


What can i do ?

Thanks in advance!





--
You received this message because you are subscribed to the Google Groups "Trac Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-dev+u...@googlegroups.com.
To post to this group, send email to trac...@googlegroups.com.
Visit this group at http://groups.google.com/group/trac-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
Κωνσταντίνος Λάλος

Steffen Hoffmann

unread,
Mar 28, 2013, 6:31:54 AM3/28/13
to trac...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 28.03.2013 11:02, Constantinos Lalos wrote:
> ... Now, i have the following problem. By default, the db returns a
> string, which consists of greek characters. Unfortunately, this
> string cannot be recognized on the ticket interface (it appears a
> string that consist of multiple '?' , while it should be a string
> with greek characters). I use the following code to do this,
>
> info = cursor.fetchone()
>
> s_info = str(info)
>
> if info: self.config.set('ticket-custom','details.value',s_info)

It's the str() method.

Try to use to_unicode() from trac.util.text instead of str().

Steffen Hoffmann
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlFUHBcACgkQ31DJeiZFuHfCkgCeIEqxitExnQD24/R3Kqd8N5k7
WxoAoLdKCFvm2BJTE4znPtRwV9vraQYX
=Y3I3
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages