[Grok-dev] generic directoryresource in grokcore.view

Kevin Teague kevin at bud.ca
Fri Oct 17 05:22:14 EDT 2008


On Oct 16, 2008, at 11:34 PM, Jan-Wijbrand Kolman wrote:

> Kevin Teague wrote:
>> Hmm, is there an easy way to use page templates located in
>> DirectoryResources using grok.PageTemplate? Or is this something that
>> could be added?
>>
>> For example, I have a 'resources' DirectoryResource with a template
>> named 'my_custom_edit.pt', then in an edit form I want to write:
>>
>> class Edit(grok.EditForm):
>>    ... regular form stuff ...
>>    template = grok.PageTemplate(???) # I want to use the '/@@/
>> resources/my_custom_edit.pt' template here
>
> I'm not sure what you want to achieve here. The DirectoryResource is
> purely a slightly more general form of the directory resources that  
> Grok
> makes available through the static attribute - the static attribute  
> on a
> view class is nothing more than a lookup for such a *particular"
> directoryresource.
>
> I guess, if that's what you want, you could mimic how the static
> attribute is put on the view class for whatever
> attribute-providing-access-to-a-specific-directoryresource.
>

Hmm, I'm not sure if DirectoryResource is quite what I need for this  
problem ... but I'll try and explain what I'm trying to do a bit more.

I've got a package (gum, an app providing a web interface for an LDAP  
install) and it has EditForm's which use a custom template  
(gum_edit_form.pt). I had this template in the root of the package,  
and could just read it using:

class SomeEditForm(grok.EditForm):
   template = grok.PageTemplateFile('gum_edit_form.pt')

Then I wanted to extend the gum package with some views that were  
specific to the requirements of a particular installation (when a user  
is added to a certain group, then a JIRA account would be remotely  
created). I put this in a different package, but wanted to use the  
same custom edit form. I created a DirectoryResource (named  
'resources') and was able to share the Image, Javascript and CSS files  
that the template is using between the two packages easily enough. But  
I also wanted to share the template file as well, so I put it into the  
resources directory and wrote:

package: gum

   class SomeEditForm(grok.EditForm):
     template = grok.PageTemplateFile('resources/gum_edit_form.pt')

package: gum-custom-extension

   class CustomEditForm(grok.EditForm):
     template = ???

So since I'm using a DirectoryResource to share images, javascript and  
css between pacakges I figured it might make sense to share templates?  
I couldn't easily determine how to do this though - I can get at the  
template inside the resources, and feed it into a grok.PageTemplate()  
call by manually open()ing the resource, but that's pretty messy - but  
maybe DirectoryResources are only intended for resources which should  
be published to the web, and isn't really the right tool for template  
sharing?




More information about the Grok-dev mailing list