Re: About proper use of mantissa.sharing...
[email protected] Mon, 07 Apr 2008 06:49:27 -0000
| Newsgroups | gmane.comp.python.quotient.dev |
|---|---|
| Message-ID | <20080407064927.21558.219131080.divmod.xquotient.10447@joule.divmod.com> |
On 30 Mar, 09:00 am, [email protected] wrote: >Since I'm returning this ThemedElement (adapted from Foo) from a >renderer, I find myself sometimes doing things like this, which simply >feel wrong: Hi Alex! Sorry it's been a while. >class Whatever(ThemedElement): > def renderFoo(self, request, tag): > # Supposing I want to put this item in the app store... > _store =3D >self.original.store.parent.filesdir.child('app').child('Bar.axiom')).open() > > # and whereas userStore is inmemory()... I feel like there's > # something very wrong with this idiom > return ixmantissa.INavigableFragment(model.Foo(store=3D_store, >userStore=3Dself.original.store)) > page.renderer(renderFoo) The key problem with this is: don't render items in the app store. You = should try to never use store.parent in your application code. The few = places you really do need to use it, you should be aware that this is = because of a missing feature in the infrastructure; in a few months, = there should be literally zero places that these sorts of links are = required. One question: why an app store and not the user store? I don't = understand your use case at all, so I can't really offer a solution (or = even point to all of the relevant open tickets: this is a sticky area of = the infrastructure that we are actively cleaning up). Unfortunately the real, "good" way to do this is blocked on the = resolution of http://divmod.org/trac/ticket/2191 which I am having = trouble finding time to work on. Soon, though: it is my highest Divmod = coding priority. I believe you're also going to need this: = http://divmod.org/trac/ticket/2554 which I need to review. This would = allow you to use items in app stores according to normal sharing rules; = right now they have kind of wonky requirements. Once those tickets are resolved, you can do something like what I = describe below. Hopefully you can either help us resolve them somehow = or do something that is similar in spirit to this summary until they're = done. First of all, don't create any items in a renderer. Ever. Why would = you do that? Don't. This has nothing to do with app stores or user = stores; this is basic model/view separation stuff. If you really, really need to render an app store item in a user store, = create an item in the user store which links to the item in the app = store with the relevant pieces of information. In the future, you = should create this item by sending a message to the app store. For = right now, fake that by doing something simple in the model that uses = self.store.parent. However, think about who owns the data; if you billed for every bit in = your system, are you billing it to the application, or is it owned by a = particular user? Examples of data billed to a user: their blog posts, = their emails, status updates, inventory records, etc. Billed to the = application: indexes, data that is placed on the front page of a public = site, aggregations (top ten lists, etc). Most of the time, the link = actually goes the other way: items in an app store ought to be shallow = copies, and pointers to, relevant information owned by a particular = user. For example, keep in mind that users don't need to be simply end- = users either, you could make a user like "north american continent" if = it's convenient. >class FooElement(ThemedElement): > def foo(self): > primaryRole =3D sharing.getSelfRole(self.original.userStore) > #of course, the above won't work for the unauthenticated user... > > _query =3D self.original.store.query(model.Bar) > return [post.toDict() for post in > sharing.asAccessibleTo(primaryRole, _query)] > athena.expose(foo) > >components.registerAdapter( > FooElement, > model.Foo, > ixmantissa.INavigableFragment >) > >Anyone have suggestions about this? >-- >Alex > >_______________________________________________ >Divmod-dev mailing list >[email protected] >http://divmod.org/users/mailman.twistd/listinfo/divmod-dev