[Grok-dev] Static dir with grok.PageTemplateFile

Alex Leach albl500 at york.ac.uk
Sun May 13 18:05:46 UTC 2012

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 
       'static': None,
       'template': <grokcore.view.components.TrustedFilePageTemplate object at 
       '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):
    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):

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'" >
          <link rel="stylesheet" type="text/css" tal:attributes="href 

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 

Thanks for any and all help,
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.zope.org/pipermail/grok-dev/attachments/20120513/dba18d80/attachment.html>

More information about the Grok-dev mailing list