Trac Data Models and Schema

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.

[b]Ticket[/b]

Data Model - trac.ticket.model.Ticket​



from trac.env import Environment
from trac.ticket.model import Ticket

env = Environment('/path/to/trac/env')

# Create a new ticket:
tkt = Ticket(env)
tkt['reporter'] = 'me'
tkt['summary'] = 'my new ticket'
tkt['description'] = 'some bogus description'
tkt['status'] = 'new'
tkt.insert()

# To read an existing ticket pass its id to the constructor:
tkt = Ticket(env, 1)
print tkt['priority']

# Update another ticket:
tkt = Ticket(env, 2)
tkt['status'] = 'closed'
tkt['resolution'] = 'fixed'
tkt.save_changes(author='me', comment='progammaticly closed a ticket')

# And finally deleting:
tkt = Ticket(env, 3)
tkt.delete()

For more examples, see trac.ticket.web_ui​.

[b]WikiPage[/b]

Data Model - trac.wiki.model.WikiPage​



from trac.env import Environment
from trac.wiki.model import WikiPage

env = Environment('/path/to/trac/env')

# Read an existing or new WikiPage:
page = WikiPage(env, 'MyWikiPage')
# Check if this is a new page:
print page.exists
# Update the content:
page.text = 'page content goes here'
page.save(author='me', comment='I can edit the Wiki!', remote_addr='127.0.0.1')

# Read a specific page version:
page = WikiPage(env, 'TracFaq', 1)
print page.text

# Delete a page:
page = WikiPage(env, 'BadWikiPage')
page.delete()

# Or delete only a specific version of a page:
page = WikiPage(env, 'AnotherPage')
page.delete(version=5)



[img]http://dl.iteye.com/upload/attachment/308993/1e4e4236-45fb-3271-a28b-248b045f960f.png[/img]


[img]http://dl.iteye.com/upload/attachment/308999/80c27de1-2b79-3597-b828-4b7a57aeabc0.png[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值