[Grok-dev] FW: grok 1.0 and forbidden attribute error

Lacko Roman rlacko at gratex.com
Mon Jan 11 11:46:03 EST 2010


Hi,
I found that code bellow raises the exception (from megrok.form), please see [form_field = self.context.form_fields.get(field_name, None)]

>>>
class FileViewDispatcher(UrlDispatcher):
    """
    This overrides collective.namedfile.browser.FileViewDispatcher. The former is
    almost equal, but uses restrictedTraverse (which is specific to Zope 2 / Plone),
    I think.
    """
    
    def __call__(self):    
        if not self.traverse_subpath:
            raise NotFound(self, '', self.request)
        field_name = self.traverse_subpath[0]
        # ===== HERE is the exception raised =====
        form_field = self.context.form_fields.get(field_name, None)
        if form_field is None:
            raise NotFound(self, field_name, self.request)
        field = form_field.field.bind(self.context.context)
        file = field.get(self.context.context)
        if getattr(file, 'filename', None):
            extension = os.path.splitext(file.filename)[1].lower()
            contenttype = mimetypes.types_map.get(extension,
                                                  "application/octet-stream")
        elif file.contentType:
            contenttype = file.contentType
        else:
            contenttype = "application/octet-stream"
        self.request.response.setHeader("Content-Type", contenttype)
        self.request.response.setHeader("Content-Length", file.getSize())
        return file.data
<<<

Thanks
- Roman

> -----Original Message-----
> From: grok-dev-bounces at zope.org [mailto:grok-dev-bounces at zope.org] On
> Behalf Of Lacko Roman
> Sent: Monday, January 11, 2010 5:36 PM
> To: Souheil CHELFOUH
> Cc: grok-dev at zope.org
> Subject: Re: [Grok-dev] FW: grok 1.0 and forbidden attribute error
> 
> Hi,
> 
> Sorri, this is more complete template:
> >>>
>   <tal:block tal:repeat="file view/Files" tal:condition="view/Files">
>     <div class="container doc_desc_container">
>       <div class="doc_desc">
>         <a tal:content="file/getFileBaseName"
>           tal:attributes="href
> string:${view/application_url}/files/${file/__name__}/display/@@file/Fi
> le/${file/getFileBaseName}">
>           Title
>         </a>
>         -- <p tal:define="sizekb python:file.File.getSize()/1024"
> tal:replace="sizekb">100</p> KB
>       </div>
>     </div>
>   </tal:block>
> <<<
> 
> The @@file view is from collective.namedfile package and returns the
> DocumentFile instance.
> 
> The ${view/application_url}/files returns grok.Container which contains
> instances of DocumentFile class
> 
> It's just strange that this worked for in grok 0.14 but not in 1.0
> 
> I just want to create url to file like object, so users can download
> file, that is stored in zodb.
> But i'm shore there is better way to do it ?
> 
> Thanks for your help
> - Roman
> 
> > -----Original Message-----
> > From: Souheil CHELFOUH [mailto:trollfot at gmail.com]
> > Sent: Monday, January 11, 2010 5:05 PM
> > To: Lacko Roman
> > Cc: Martijn Faassen; grok-dev at zope.org
> > Subject: Re: [Grok-dev] FW: grok 1.0 and forbidden attribute error
> >
> > Views are not traversable to attributes non present in IBrowserView.
> > I don't understand your code here, though. If the view is "display",
> > why is there a @@file ?
> > Please, paste your whole code, this looks a bit weird to me.
> >
> > 2010/1/11 Lacko Roman <rlacko at gratex.com>:
> > > Hi Martijn,
> > >
> > >> -----Original Message-----
> > >> From: grok-dev-bounces at zope.org [mailto:grok-dev-bounces at zope.org]
> > On
> > >> Behalf Of Martijn Faassen
> > >>
> > >> could you show the implementation of the Display object?
> > >>
> > >> Regards,
> > >>
> > >> Martijn
> > >
> > > Here is the class declaration of 'display' view:
> > >>>>
> > > # Define Display Form for DocumentFile
> > >
> > > class Display(grok.DisplayForm):
> > >    grok.context(DocumentFile)
> > > <<<
> > >
> > > The DocumentFile class just implements IDocumentFile interface
> > >
> > > And here is how i render the DocumentFile in zpt:
> > >>>>
> > >        <a tal:content="file/getFileBaseName"
> > >          tal:attributes="href
> >
> string:${view/application_url}/files/${file/__name__}/display/@@file/Fi
> > le/${file/getFileBaseName}">
> > > <<<
> > >
> > > Thanks
> > > - Roman
> > >
> > > _______________________________________________
> > > Grok-dev mailing list
> > > Grok-dev at zope.org
> > > https://mail.zope.org/mailman/listinfo/grok-dev
> > >
> _______________________________________________
> 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