[Zope3-Users] Re: Access request object from content_factory

John Smith jsmith030416 at yahoo.co.uk
Wed Jun 21 07:10:01 EDT 2006


Well, I always like to do things the way the experts
recommend :)

Are there any suggestions for this use case?:

I have a content class, which consists of 2
attributes:

1. a user comment
2. the name of the logged in user

So far, I have been using the browser:addform 
directive to add instances, which generates all my
views for me. (I love this and do not want to lose
it).

I have read about annotations and the DublinCore and I
think I can go digging in __annotations__, if I make
my class IAttributeAnnotable and get the logged in
user name.

The thing is, in this use case, the logged-in-user
attribute is not metadata, it is a fundamental
component of this particular content object.

So, my question boils down to: what is the recommended
way to get at the request object in a content factory
when using browser:addform.

The reason I think this matters is that there are so
many adapters and utilities that need a request
object, it seems unnecessary to deprive a content
factory of the use of them, when the developer chooses
to take advantage of browser:addform.

Best wishes,

John




--- Philipp von Weitershausen
<philipp at weitershausen.de> wrote:

> Marco Mariani wrote:
> > Rupert Redington wrote:
> >> from zope.security.management import
> getInteraction
> >>
> >> request = getInteraction().participations[0]
> >>
> >> Why this works is outlined (IIRC) in
> zope/app/securitypolicy/zopepolicy.txt.
> >>
> >> There may well be better ways to fish for the
> request than this... any
> >> offerings?
> >>   
> > In my understanding, if you need to look for the
> request inside a
> > content object, you're doing something that should
> be done in another
> > place, be it a view or an adapter.
> 
> Indeed.
> 
> > Of course, I've been wrong before :-]
> 
> Not this time :).
> 
> The hack displayed above (going thru the security
> interaction) should
> not be considered a standard procedure for getting
> at the request in
> places where you don't have it. Content objects are
> dull. They do
> nothing. Other stuff does things *to* them. Mats'
> solution is the better
> one.
> 
> Philipp
> 
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
> 



		
___________________________________________________________ 
Inbox full of spam? Get leading spam protection and 1GB storage with All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html


More information about the Zope3-users mailing list