On Fri, Feb 15, 2008 at 2:31 PM, Dj Gilcrease <[EMAIL PROTECTED]> wrote: > > On Thu, Feb 14, 2008 at 12:41 PM, Johan Liseborn > <[EMAIL PROTECTED]> wrote: > > I tried your suggested approach, wrote a small middleware class, and > > I actually got it working quite quickly, thanks! > > > > The thing I am thinking about now is if there is a way to make the > > filtering part more "automagic" (like I think the sites-stuff does > > it); I was looking at custom managers, but it seems I cannot really do > > it like that, because the filter criteria needs to be known when you > > define the custom manager, whereas my filter criteria is only known at > > run-time, when a specific request hits the server. (What I am worried > > about is that I will forget to do the filtering for a view and > > accidentally return too much data.) > > Should be able to do this relatively simple within the middleware your > created by following the example @ > http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser to get > the current user outside a request, you just adapt it to get the > current site outside a request. Then your Manager looks something like > http://dpaste.com/35305/
Sweet, thanks! I managed to use the stuff you provided to accomplish what I want; now, in views, I can just use Foo.object.all() (or similar) and the returned set will have already been filtered according to the "domain" of the user. Now I only have to figure out exactly what it is I've done... :-) I guess the principle is that a single request/response always runs in one and only one thread, so therefore I can tuck stuff away in thread local storage and access it down the line during the same request/response "cycle", right? Thanks again! Regards, johan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---