Version 3 (modified by 18 years ago) ( diff ) | ,
---|
Trac Data Models
The main models that developers might be interested in are Ticket and WikiPage. The constructors each take the environment as the first parameter, and the ticket id or wiki page name next.
Ticket
Data Model - trac.ticket.model.Ticket
29 class Ticket(object): 30 31 def __init__(self, env, tkt_id=None, db=None):
The fields on a model object can be edited by treating the object as a dictionary. If you change any of the fields you must call save_changes() to have them persisted.
To edit a ticket…
import trac.env import trac.ticket.model # Open Trac environment t = trac.env.Environment("path/to/trac/env") # Get the ticket you are after (how can we query for tickets?) myticket = trac.ticket.model.Ticket(t, tkt_id=1) # Read a ticket field print "Changing description for ticket called %s" %myticket["summary"] #Write a ticket field myticket["description"] = "My ticket now has a new description." #Save your changes myticket.save_changes("myusername","Just changed the description")
For usage examples, see trac.ticket.web_ui.
WikiPage
Data Model - trac.wiki.model.WikiPage
26 class WikiPage(object): 27 """Represents a wiki page (new or existing).""" 28 29 def __init__(self, env, name=None, version=None, db=None):
The WikiPage has an optional parameter for the version, and you probably won't need to bother with the last parameter which is an optional db connection.
For usage examples, see trac.wiki.web_ui.
See also: TracDev