Re: Get function name after....
On 27 mar, 22:26, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > > At the moment we try to remember to fill in most of the details on the > > > wrapped object, but this isn't always possible (for example, the > > > __name__ attribute of a function is read-only in python 2.3). One > Today I tested the same code I tested weeks ago and now it works from django.http import HttpResponse class AuthorizedMiddleware(object): def process_view(self, request, view, args, kwargs): return HttpResponse(str( view.__name__ )) what did you do for this or I'm doing something "wrong"? > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Get function name after....
On Mar 27, 10:26 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > That's way I _need_ the function name :-( > > Understod. There are lots of similar cases where making sure you get the > real function name is useful. So, it's something that will be solved > soon-ish. You just can't have it today. :-) > hum, I'll see what can I do in my views. Thanks for you awser Malcom, Regards! > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Get function name after....
On Wed, 2007-03-28 at 02:22 +, Mario Gonzalez wrote: > On Mar 27, 9:09 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: > > > > This is a known mini-problem and something we need to / will sort out > > prior to 1.0. There are a *lot* of places in Django that wrap views up > > and then expose them to the world. Once you get used to the idiom, it's > > not a bad way of programming, although it does make your brain leak out > > your ears sometimes trying to work out who is actually doing the real > > work. The drawback of this approach is that it's hard to get access to > > the underlying function. > > > > At the moment we try to remember to fill in most of the details on the > > wrapped object, but this isn't always possible (for example, the > > __name__ attribute of a function is read-only in python 2.3). One > > hum, that's a problem because I'm trying to develop a security > middleware to allow/deny applications. So authenticated users could or > not be able to get an application if they've got a permission to do > that. I want to do it using the function name that the user is going > to access and I don't want to do it using urls because sometimes urls > are different than apps names. > > That's way I _need_ the function name :-( Understod. There are lots of similar cases where making sure you get the real function name is useful. So, it's something that will be solved soon-ish. You just can't have it today. :-) Cheers, Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Get function name after....
On Mar 27, 9:09 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > This is a known mini-problem and something we need to / will sort out > prior to 1.0. There are a *lot* of places in Django that wrap views up > and then expose them to the world. Once you get used to the idiom, it's > not a bad way of programming, although it does make your brain leak out > your ears sometimes trying to work out who is actually doing the real > work. The drawback of this approach is that it's hard to get access to > the underlying function. > > At the moment we try to remember to fill in most of the details on the > wrapped object, but this isn't always possible (for example, the > __name__ attribute of a function is read-only in python 2.3). One hum, that's a problem because I'm trying to develop a security middleware to allow/deny applications. So authenticated users could or not be able to get an application if they've got a permission to do that. I want to do it using the function name that the user is going to access and I don't want to do it using urls because sometimes urls are different than apps names. That's way I _need_ the function name :-( > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Get function name after....
On Tue, 2007-03-27 at 19:39 +, Mario Gonzalez wrote: > On Mar 27, 2:13 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > > Also, keep in mind that writing a 'process_view' method instead will > > give you access to the view function the URL resolved to, and will > > execute *before* the view function is actually called. That might be > > I changed and I've got the same name '_wrapped_view'. I think I must > going to include the resolv() rutine inside my code. I'm not sure but > I believe wrapped_view it's something like a pointer. > > class AuthorizedMiddleware(object): > > def process_view(self, request, view, args, kwargs): > return HttpResponse(str( view.__name__ )) This is a known mini-problem and something we need to / will sort out prior to 1.0. There are a *lot* of places in Django that wrap views up and then expose them to the world. Once you get used to the idiom, it's not a bad way of programming, although it does make your brain leak out your ears sometimes trying to work out who is actually doing the real work. The drawback of this approach is that it's hard to get access to the underlying function. At the moment we try to remember to fill in most of the details on the wrapped object, but this isn't always possible (for example, the __name__ attribute of a function is read-only in python 2.3). One solution that has been proposed is to include the third-party decorator module in Python, which takes care of a bunch of that work. There's been no firm decision on that yet, but it's something we will deal with prior to 1.0 -- I think it's practical that we should be able to get a firm decision made on almost every existing open ticket prior to 1.0 that isn't a "some day maybe" enhancement request. Regards, Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Get function name after....
On Mar 27, 3:24 pm, "Mario Gonzalez" <[EMAIL PROTECTED]> wrote: > On Mar 27, 2:10 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > > > 'resolve' returns the actual callable function in all cases, so if you > > want the string name of the function you might want to access its > > '__name__' attribute. > > > Are you using any decorators on these views? > Sorry but I forgot that I'm using a cache backed, so a cache_page decorator. Well I think I found a *bug* and I'd like you tell me if I'm wrong, because the next code will show a _wrapped_view as a name and not what you maybe are looking for. from django.http import HttpResponse class AuthorizedMiddleware(object): def process_view(self, request, view, args, kwargs): return HttpResponse(str( view.__name__ )) If you don't use any decorators this works without a problem. IMVHO this is a bug, the first approach for a solution is change the name to the function as object that is used in django/utils/decorators.py Index: django/utils/decorators.py === --- django/utils/decorators.py (revision 4835) +++ django/utils/decorators.py (working copy) @@ -29,5 +29,6 @@ if result is not None: return result return response +_wrapped_view.__name__ = view_func.__name__ return _wrapped_view return _decorator_from_middleware Patching this file will cause the code above works fine with or without decorators. suggestions? Regards. > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Get function name after....
On Mar 27, 3:24 pm, "Mario Gonzalez" <[EMAIL PROTECTED]> wrote: > On Mar 27, 2:10 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > > > Are you using any decorators on these views? > > no, I'm not using any decorators. Now I found some weird for me return HttpResponse(str( resolve(request.path)[0].__module__ )) gives a 'django.utils.decorators' ?! > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Get function name after....
On Mar 27, 2:13 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > Also, keep in mind that writing a 'process_view' method instead will > give you access to the view function the URL resolved to, and will > execute *before* the view function is actually called. That might be I changed and I've got the same name '_wrapped_view'. I think I must going to include the resolv() rutine inside my code. I'm not sure but I believe wrapped_view it's something like a pointer. class AuthorizedMiddleware(object): def process_view(self, request, view, args, kwargs): return HttpResponse(str( view.__name__ )) > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Get function name after....
On Mar 27, 2:10 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > > 'resolve' returns the actual callable function in all cases, so if you > want the string name of the function you might want to access its > '__name__' attribute. > > Are you using any decorators on these views? > no, I'm not using any decorators. > -- --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Get function name after....
On 3/27/07, Mario Gonzalez <[EMAIL PROTECTED]> wrote: > class AuthorizedMiddleware(object): > > def process_request(self, request): > return HttpResponse(str( resolve(request.path)[0].__name__ )) Also, keep in mind that writing a 'process_view' method instead will give you access to the view function the URL resolved to, and will execute *before* the view function is actually called. That might be another way to get at this. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Get function name after....
On 3/27/07, Mario Gonzalez <[EMAIL PROTECTED]> wrote: > however always I've got a "_wrapped_view" name. Is there a way to > find out, for example if my request.path is one/ to get app_one.idex > as a string? 'resolve' returns the actual callable function in all cases, so if you want the string name of the function you might want to access its '__name__' attribute. Are you using any decorators on these views? -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---