我正在尝试获取当前环境中的所有组件,但我无法理解的原因是我收到以下错误:
AttributeError: 'str' object has no attribute 'db_query'
这是代码(跳过某些部分):
from trac.core import *
from trac.ticket import model
class TracIteraDirectory(Component):
implements(INavigationContributor, ITemplateProvider, IRequestHandler)
def process_request(self, req):
myenv = '/home/konart/backup/Trac/TracDB/Planing'
self.db = self.env.get_db_cnx()
components = []
test = model.Component(myenv)
test1 = test.select(myenv)
for each in test1:
components.append((each.name, each.owner))
#for component in model.Component(myenv).select(myenv):
#components.append((component.name, component.owner))
我已经在trac-hacks.org和核心文件上查看了一些插件exanples,但是我无法理解我在这里做错了什么(或根本没有做错)
答案 0 :(得分:1)
我想我过度劳累了一下。 答案很简单 - 我传递了一个带有路径的简单字符串到我的env,而不是传递一个实际的Environment对象:
def process_request(self, req):
if req.path_info.startswith('/traciteradirectory'):
components = []
test = model.Component(self.env)
test1 = test.select(self.env)