我目前正在将我们的TRAC实例修改为Bootstrap 3.1。但是,需要对.py文件进行一些模板操作。我只知道如何自定义.html文件...只需添加类,稍微自定义DOM结构然后将其放在TRAC实例的模板文件夹中。
现在关于从插件中自定义.py文件有什么用?我尝试将它们放在模板文件夹中但没有任何反应。
我没有使用Python的经验,但是只需要修改并添加一个引导类,例如在milestone.py
中的标签中添加“col-sm-2 control-label” def __edit_project(self, data, req):
milestone = data.get('milestone').name
all_projects = self.__SmpModel.get_all_projects_filtered_by_conditions(req)
id_project_milestone = self.__SmpModel.get_id_project_milestone(milestone)
if id_project_milestone != None:
id_project_selected = id_project_milestone[0]
else:
id_project_selected = None
return tag.div(
tag.label(
class_="col-sm-2 control-label",
'Project',
tag.br(),
tag.select(
tag.option(),
[tag.option(row[1], selected=(id_project_selected == row[0] or None), value=row[0]) for row in sorted(all_projects, key=itemgetter(1))],
name="project")
),
class_="field")
答案 0 :(得分:0)
再次编译插件对我有用。在特定的.py文件上添加bootstrap类之后,这里是我执行的步骤/命令:
在我正在编辑的插件的特定setup.py所在的TRAC环境插件目录中,构建.egg文件,例如
tracproject/plugins_source/sampleplugin: python setup.py bdist_egg
然后我在插件目录中重命名了插件的原始.egg文件,例如
tracproject/plugins/sampleplugin/: mv sampleplugin.egg sampleplugin.egg.old
之后,我将生成的新.egg文件复制到插件目录,例如
tracproject/plugins_source/sampleplugin/dist: mv sampleplugin.egg ../../../plugins/
最后,我重新启动了我们的服务器(但是,有些情况下,由于更改立即反映,因此无需重新启动)
sudo service apache2 restart
谢谢@falkb!我看到你是SimpleMultiProject插件的作者我试图放置引导类。 :)
这是simplemultiprojectplugin milestone.py的片段,其中我添加了样式
def __edit_project(self, data, req):
milestone = data.get('milestone').name
all_projects = self.__SmpModel.get_all_projects_filtered_by_conditions(req)
id_project_milestone = self.__SmpModel.get_id_project_milestone(milestone)
if id_project_milestone != None:
id_project_selected = id_project_milestone[0]
else:
id_project_selected = None
return tag.div(
tag.label('Project', class_="control-label col-sm-2"),
tag.div(
tag.select(
tag.option(),
[tag.option(row[1], selected=(id_project_selected == row[0] or None), value=row[0]) for row in sorted(all_projects, key=itemgetter(1))],
name="project",
class_="form-control"),
class_="col-sm-5"),
class_="form-group")