[Grok-dev] Static dir with grok.PageTemplateFile

Christian Klinger cklinger at novareto.de
Mon May 14 08:55:28 UTC 2012


Hi Alex,

we recently worked on the bavarian sprint on that topic. Which version
of grokcore.view do you use?

 From the CHANGES.TXT in grokcore.view 2.7:

Fix how the static resource are found. Instead of using as name the 
package name where the component is defined, using as name the package 
where the template for the component is defined, or the base component. 
This is done by setting an attribute __static_name__ on the component 
that specify which resource directory should be used. This fix missing 
resources when you extend the component and don't redefined the template.

HTH

Christian

Alex Leach schrieb:
> I have a few forms in separate modules that share the same template.
> Rather than having the template in the <module_name>_templates/
> directory, I've got this one 'edit-form.pt' template in the bottom, src/
> directory.
>
> It worked fine, until I added a (conditional) include in the head of the
> page template, so that it downloads a CSS stylesheet if the form request
> wasn't done through an AJAX call.
>
> So I'm getting an error now, whenever I request one of the forms which
> use this template, as it fails to find the static directory holding the
> CSS. I've tried adding `resource.style.need()` to the forms' update
> methods, but they still don't find the static directory. Part of the
> traceback shows this:-
>
> Line 5, Column 10
> In expression: <PathExpr standard:u'static/css/style.css'>
>
> - Names:
>
> {'args': (),
>
> 'context': <server.app.Server object at 0x7f4878033668>,
>
> 'default': <object object at 0x7f4891c0a490>,
>
> 'loop': {},
>
> 'nothing': None,
>
> 'options': {},
>
> 'repeat': {},
>
> 'request': <zope.publisher.browser.BrowserRequest instance
> URL=http://localhost:8080/develop2/addSQLdatabase>,
>
> 'static': None,
>
> 'template': <grokcore.view.components.TrustedFilePageTemplate object at
> 0x40bc8d0>,
>
> 'view': <server.BrowseSQL.AddSQLDatabaseForm object at 0x4b246d0>}
>
> I reckon the problem is where it says: 'static' : None, but I don't know
> how to rectify that...
>
> The class declaration I have for this form is:-
>
> class AddSQLDatabaseForm(grok.AddForm):
>
> grok.context(Server)
>
> grok.implements(ISQLDatabase)
>
> grok.name('addSQLdatabase')
>
> form_fields = grok.AutoFields(ISQLDatabase)
>
> label = 'Add SQL database'
>
> template = grok.PageTemplateFile("edit-form.pt")
>
> @grok.action('New SQL database')
>
> def new_database(self,**kwargs):
>
> database = SQLDatabase(**kwargs)
>
> database.creator = self.request.principal.title
>
> database.creation_date = datetime.datetime.now()
>
> database.modification_date = datetime.datetime.now()
>
> dbname = kwargs.pop('database')
>
> self.context[dbname] = database
>
> def update(self):
>
> resource.style.need()
>
> The relevant part of the page template file (edit-form.pt) is:-
>
> <metal:block
> tal:condition="python:request.get('HTTP_X_REQUESTED_WITH',None)
> !='XMLHttpRequest'" >
>
> <head>
>
> <link rel="stylesheet" type="text/css" tal:attributes="href
> static/css/style.css">
>
> </head>
>
> </metal:block>
>
> Any idea why it can't find the CSS file? That same tal:attributes URL
> works in all the module-specific page templates. Why not with this
> generic form template?
>
> Thanks for any and all help,
>
> Alex
>
> --
>
> Alex Leach BSc. MRes.
>
> Department of Biology
>
> University of York
>
> York YO10 5DD
>
> United Kingdom
>
> www: http://bioltfws1.york.ac.uk/~albl500
>
> EMAIL DISCLAIMER: http://www.york.ac.uk/docs/disclaimer/email.htm
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list