0

I am currently modifying our TRAC instance to Bootstrap 3.1. However, some templating needs to be done on the .py files. I only know how to customize .html files... just add classes, customize DOM structure a little bit then put it in templates folder of our TRAC instance.

NOW WHAT ABOUT customizing .py files from plugins? I tried putting them in templates folder but nothing happened.

I had no experience with Python, but it's easy just to hack around and add a bootstrap class e.g adding "col-sm-2 control-label" in a label in 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(
                   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")
Woppi
  • 5,303
  • 11
  • 57
  • 81
  • 2
    can you please explain before voting down the question? I can't find related articles on how to customize plugins... that's why I ended up asking it here in SO. – Woppi Jul 09 '14 at 08:29
  • First callback-question would be: What are you trying to accomplish. Just restyling or reshaping (i.e. changing layout)? – SamuelTee Jul 10 '14 at 07:06
  • Btw, I wasn't the one who downvoted. – SamuelTee Jul 10 '14 at 07:12
  • @SamuelTee Just want to add a bootstrap class in html select tag that was rendered in .py file. Some of the rendering were made on .py files. Even if I change the .py file nothing is happening. I tried to put the modified .py file in plugins directory, or templates directory of our TRAC instance. I even tried restarting our web server... nothing happened. I had no experience in Python development... I was searching if I can recompile the plugin... but I can't find related articles... Thanks! – Woppi Jul 11 '14 at 03:09
  • 1
    @Woppi: you can recompile the plugin by calling *python.exe setup.py bdist_egg* from the Trac's command line shell and then copy the result file (an .egg file in directory *.\dist*) to Trac's plugin directory. Not to forget the restart the Apache after all. – falkb Jul 11 '14 at 14:07

1 Answers1

0

Compiling the plugin again worked for me. After adding bootstrap classes on specific .py files, here are the steps/commands I did:

In our TRAC environment plugins directory where specific setup.py of the plugin I'm editing is located, build the .egg file e.g

tracproject/plugins_source/sampleplugin: python setup.py bdist_egg

Then I renamed the plugin's original .egg file in the plugins directory e.g

tracproject/plugins/sampleplugin/: mv sampleplugin.egg sampleplugin.egg.old

After that, I copied the newly .egg file generated to the plugins directory e.g

tracproject/plugins_source/sampleplugin/dist: mv sampleplugin.egg ../../../plugins/

Lastly, I restarted our server e.g (however, there were cases, no restart was needed since changes were instantly reflected)

sudo service apache2 restart

Thanks @falkb! I see that you're the author of SimpleMultiProject plugin I was trying to put bootstrap classes. :)

Here's a snippet of simplemultiprojectplugin milestone.py where I added styling

    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")
Woppi
  • 5,303
  • 11
  • 57
  • 81
  • I'm not sure if this is the right way for decorating to your own styles, though I can't help here. I'm also curious what the right solution actually would be. Anyway I helped you to push your question to 0 again. – falkb Jul 14 '14 at 07:10
  • @falkb Thanks! Edited my post to show you what I did to your milestone.py file. – Woppi Jul 14 '14 at 07:38
  • is this a universal patch or just a hack? Where do these class names come from, are the universal? – falkb Jul 14 '14 at 13:34
  • @falkb Just a hack since I'm trying to change our entire TRAC instance to Twitter Bootstrap 3.1 template including plugins such as SimpleMultiProject. Class names are from Twitter Bootstrap. :) – Woppi Jul 15 '14 at 02:39
  • @Woppi I recommend reading http://trac.edgewall.org/wiki/TracInterfaceCustomization#SiteAppearance. Even if that lacks some kind of documentation, you may find some hints on how to customize your trac (html and css) without the need for editing all the py-files manually. – SamuelTee Jul 15 '14 at 07:39