bloodhound-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Saint Germain <saint...@gmail.com>
Subject Re: Use customized configuration variable in templates
Date Tue, 17 Jun 2014 01:43:48 GMT
On Mon, 16 Jun 2014 10:25:45 -0400, Olemis Lang <olemis@gmail.com>
wrote :

> On Mon, Jun 16, 2014 at 9:57 AM, Saint Germain <saintger@gmail.com>
> wrote:
> 
> > On 16 June 2014 15:36, Olemis Lang <olemis@gmail.com> wrote:
> > >
> > > Maybe you just need to implement IRequestFilter and invoke
> > > trac.chrome.add_script or trac.chrome.add_script_data .
> > >
> >
> > That sounds very interesting !
> > Do you have some examples on how we should use these API ?
> >
> >
> >
> [...]
> 
> Described in these links
> 
> http://trac.edgewall.org/browser/trunk/trac/web/api.py?marks=96-134#L96
> http://trac.edgewall.org/browser/trunk/trac/web/chrome.py?marks=148-168#L148
> 

Hello Olemis,

Well I have tried creating my first plugin and failed miserably.

I followed the tutorial and create the following architecture:
├── helloworld
│   ├── helloworld.py
│   ├── htdocs
│   │   ├── css
│   │   ├── hello.js
│   │   └── images
│   ├── __init__.py
│   └── templates
│       └── helloworld.html
└── setup.py

There here is the content of setup.py:
from setuptools import find_packages, setup
setup(
    name='Trachelloworld', version='1.1',
    packages=find_packages(exclude=['*.tests*']),
    entry_points = """
        [trac.plugins]
        helloworld = helloworld
    """,
    package_data={'helloworld': ['templates/*.html', 
                                 'htdocs/css/*.css', 
                                 'htdocs/images/*',
                                 'htdocs/*.js']},
)

The content of helloworld.py:
from trac.core import *
from trac.web import IRequestFilter
from trac.web.chrome import add_script, add_script_data

class HelloworldModule(Component):
    implements(IRequestFilter)

    def pre_process_request(self, req, handler):
        return handler
    
    def post_process_request(self, req, template, data, content_type):
        add_script(req, 'hw/hello.js')
        return (template, data, content_type)

    def get_templates_dirs(self):
        from pkg_resources import resource_filename
        return [resource_filename(__name__, 'templates')]
    
    def get_htdocs_dirs(self):
        from pkg_resources import resource_filename
        return [('hw', resource_filename(__name__, 'htdocs'))]

And the content of hello.js:
alert("Hello !");

I have then create a clean environment with :
bloodhound_setup.py --project=sqlite --database-type=sqlite --admin-user=admin --admin-password=adminpasswd

And then added helloworld.* = enabled to [components] and build the plugin egg and store it
in the plugins directory.

However it's driving me crazy because the hw/hello.js is called but I always got a 404 error.

Is there something I am doing wrong here ?

Thanks in advance,

Mime
View raw message