Discovering in the application the path to resources?

6 views
Skip to first unread message

Jonathan Ballet

unread,
Apr 24, 2012, 5:45:46 AM4/24/12
to fans...@googlegroups.com
Hi,

I'm using amCharts (a chart library written in Javascript, cf.
http://www.amcharts.com/) in my application. I created a Fanstatic
package with the Javascript file, a CSS file and a few images.

When I setup the Javascript library, I need to specify the path where
the library will find the images such as:

chart = new AmCharts.AmSerialChart();
chart.pathToImages = "/images/amcharts";

but this path obviously depends on how Fanstatic is configured. I'm
currently passing quite a few values from Python to Javascript, so if I
can find the value I should set here in Python, I can pass it back to
the library, but I have no idea how to do that (if it ever possible?)

Fanstatic is serving the images well if I enter the URL by myself (which
is something like
"/resources/amstock/:version:2012-04-24T15:26:05/images/" today.
How can I find this path?

Cheers,

Jonathan

Jan-Jaap Driessen

unread,
Apr 24, 2012, 12:43:04 PM4/24/12
to fans...@googlegroups.com
Hi Jonathan,

On Tue, Apr 24, 2012 at 11:45 AM, Jonathan Ballet <j...@multani.info> wrote:
> Hi,
>
> I'm using amCharts (a chart library written in Javascript, cf.
> http://www.amcharts.com/) in my application. I created a Fanstatic
package with the Javascript file, a CSS file and a few images.

I didn't know amcharts, looks very useful. Please consider sharing
your efforts by putting your package in pypi:

http://www.fanstatic.org/en/0.11.2/development.html#pre-packaged-libraries

> When I setup the Javascript library, I need to specify the path where
> the library will find the images such as:
>
>    chart = new AmCharts.AmSerialChart();
>    chart.pathToImages = "/images/amcharts";
>
> but this path obviously depends on how Fanstatic is configured. I'm
> currently passing quite a few values from Python to Javascript, so if I
> can find the value I should set here in Python, I can pass it back to
> the library, but I have no idea how to do that (if it ever possible?)
>
> Fanstatic is serving the images well if I enter the URL by myself (which
> is something like
> "/resources/amstock/:version:2012-04-24T15:26:05/images/" today.
> How can I find this path?

For every request, fanstatic creates a `NeededResources` object, which
contains the publication configuration options[1].

In your view code, you can access the `NeededResources` object using
fanstatic.get_needed():

>>> needed = fanstatic.get_needed()

In the `Injector`, the URLs are computed [2]. You can do the same
computation [3] in order to find the URL of a library in your view
code:

>>> # in case of js.jquery
>>> from js.jquery import library
>>> needed.library_url(library)
'/fanstatic/jquery/:version:1.6.1'

> Cheers,
>
>  Jonathan

Cheers,

JJ

1) http://www.fanstatic.org/en/0.11.2/configuration.html
2) https://bitbucket.org/fanstatic/fanstatic/src/636ee4170bc3/fanstatic/injector.py#cl-44
3) https://bitbucket.org/fanstatic/fanstatic/src/636ee4170bc3/fanstatic/core.py#cl-817

Jonathan Ballet

unread,
Apr 24, 2012, 11:00:09 PM4/24/12
to fans...@googlegroups.com
On Tue, Apr 24, 2012 at 06:43:04PM +0200, Jan-Jaap Driessen wrote:
> Hi Jonathan,
>
> On Tue, Apr 24, 2012 at 11:45 AM, Jonathan Ballet <j...@multani.info> wrote:
> > Hi,
> >
> > I'm using amCharts (a chart library written in Javascript, cf.
> > http://www.amcharts.com/) in my application. I created a Fanstatic
> > package with the Javascript file, a CSS file and a few images.
>
> I didn't know amcharts, looks very useful. Please consider sharing
> your efforts by putting your package in pypi:
>
> http://www.fanstatic.org/en/0.11.2/development.html#pre-packaged-libraries

I was considering pubishing it after polishing the packaging. I didn't
use fanstatictemplate but I will have a look...

> > When I setup the Javascript library, I need to specify the path where
> > the library will find the images such as:
> >
> > � �chart = new AmCharts.AmSerialChart();
> > � �chart.pathToImages = "/images/amcharts";
> >
> > but this path obviously depends on how Fanstatic is configured. I'm
> > currently passing quite a few values from Python to Javascript, so if I
> > can find the value I should set here in Python, I can pass it back to
> > the library, but I have no idea how to do that (if it ever possible?)
> >
> > Fanstatic is serving the images well if I enter the URL by myself (which
> > is something like
> > "/resources/amstock/:version:2012-04-24T15:26:05/images/" today.
> > How can I find this path?
>
...
> >>> needed = fanstatic.get_needed()
> >>> from js.jquery import library
> >>> needed.library_url(library)
> '/fanstatic/jquery/:version:1.6.1'

Thanks, it does perfectly the job! I added this as a function in library
package so that it's easily reusable.

Thanks a lot for your help!

Jonathan

Jonathan Ballet

unread,
Apr 25, 2012, 8:08:57 AM4/25/12
to fans...@googlegroups.com
Hey Jan-Jaap,

On Tue, Apr 24, 2012 at 06:43:04PM +0200, Jan-Jaap Driessen wrote:
> Hi Jonathan,
>
> On Tue, Apr 24, 2012 at 11:45 AM, Jonathan Ballet <j...@multani.info> wrote:
> > Hi,
> >
> > I'm using amCharts (a chart library written in Javascript, cf.
> > http://www.amcharts.com/) in my application. I created a Fanstatic
> package with the Javascript file, a CSS file and a few images.
>
> I didn't know amcharts, looks very useful. Please consider sharing
> your efforts by putting your package in pypi:
>
> http://www.fanstatic.org/en/0.11.2/development.html#pre-packaged-libraries

I repackaged the library using fanstatictemplate and pushed it to
https://github.com/securactive/js.amcharts

I made a push request on Fanstatic itself to add the library to the list
of pre-packaged libraries at
https://bitbucket.org/fanstatic/fanstatic/pull-request/3 (I also sorted
the list of the libraries, I guess it makes more sense like this).

The package is available at http://pypi.python.org/pypi/js.amcharts and
I updated the roles there.

I wished I could update the Buildbot configuration as described in the
documentation above, but I couldn't find anything related to Fanstatic
libraries themselves?

Cheers,

Jonathan

Jan-Jaap Driessen

unread,
May 8, 2012, 5:06:00 PM5/8/12
to fans...@googlegroups.com, j...@multani.info
On Wed, Apr 25, 2012 at 2:08 PM, Jonathan Ballet <j...@multani.info> wrote:
...
> I wished I could update the Buildbot configuration as described in the
> documentation above, but I couldn't find anything related to Fanstatic
> libraries themselves?

The buildbot is out of comission until further notice. I updated the
documentation to reflect this.

Cheers,

Jan-Jaap
Reply all
Reply to author
Forward
0 new messages