[Cubicweb] Access 'data_url' in postcreate.py

Aurélien Campéas aurelien.campeas at logilab.fr
Fri Aug 24 13:49:24 CEST 2012

Le 24/08/2012 13:25, Stéphane Bugat a écrit :
> Dear all,


> I'd like to populate my database in 'migration/postcreate.py' by injecting some data issued
> from a CSV file located in the data/ subdir of the sources. Unfortunately, it seems that

Badly placed.

> the convenient function 'data_url' that is usually accessible in hooks or views (via self._cw)
> does not exists here (I've scanned with an awful dir() the content of cnx, session and so on).

There won't be one, ever.

> Is there another way to get it back? For the moment I use an ugly workaround using 'os.path.dirname(os.path.abspath(__file__))'...

Keep the workaround if you keep your file in data/

> Same question but this time in another context: self._cw.data_url is not available in Hooks with events like 'server_startup'...

data/ and data_url are all about cache-managed-client-requested resources

You probably want to use _cw.vreg.config.static_directory & friends (see 
cw/web/webconfig ~396 for the full API).

More information about the Cubicweb mailing list