Modelviewset action decorators

2022-12-15 Thread Glossy Webs
hello guys im a junior developer learning django right now am in viewset concept rightnw but i could find the right answer for what is action decorater default=True/false in modelviewset. what does that exactly do on the internet can someone explain me what does that exactly do in detail? -- Y

About translation Django's Rest API through decorators

2021-04-06 Thread AlainWebDev
Hey. I don't understand the logic of a method i had to use around my Rest Api translation messages. I had used gettext on all messages i needed on my project. And in some parts i needed to use decorator method, like this : @method_decorator( reponse_toast_decorator(Toast(message=gettext("Votre no

Re: write custom decorators in django to authenticate the user

2017-11-02 Thread yves . mueller
Can you post an example of how you are using the decorator? If you are using it on a dispatch/get/post ... method of a class based views, it will still get the instance (self) as a first parameter. So you should take also self as an argument to your inner wrap method. Unrelated: Your wrap metho

Re: write custom decorators in django to authenticate the user

2017-11-01 Thread rohit . autosoft
On Thursday, 2 November 2017 09:53:33 UTC+5:30, rohit.a...@gmail.com wrote: > > def authenticated(f): > def wrap(request, *args, **kwargs): > token = request.META.get('HTTP_AUTHORIZATION') > entry = Person.objects.get(pk=kwargs['entry_id']) > payload = jwt.decode(token, SECRET) > user = Person.ob

write custom decorators in django to authenticate the user

2017-11-01 Thread rohit . autosoft
def authenticated(f): def wrap(request, *args, **kwargs): token = request.META.get('HTTP_AUTHORIZATION') entry = Person.objects.get(pk=kwargs['entry_id']) payload = jwt.decode(token, SECRET) user = Person.objects.get( username=payload.get('username'), pk=payload.get('id')) wrap.__doc__=f.__doc__ w

Re: get_ip_address() not working when used Custom Decorators

2017-10-01 Thread mitesh_django
Manu, Try print kwargs.get('request')... You should get Django HTTPRequest Object, pass that to get_client_ip method. On Thursday, September 28, 2017 at 3:03:09 PM UTC-4, Mannu Gupta wrote: > > While making a customer decorator in django, the code is here :- > > def owner_required(function): >

Re: get_ip_address() not working when used Custom Decorators

2017-10-01 Thread Constantine Covtushenko
Sorry for late response, I meant that you might using that decorator in 2 places. And asked about that. It seems like you specified `@owner_required` to decorate your view function. But that decorator behave like `@owner_required()`. With your last response I see that decorated function instead

Re: get_ip_address() not working when used Custom Decorators

2017-09-30 Thread Mannu Gupta
Hello Constantine C, Thanks for your reply! What do you mean to say just one place ? I just printed the request using `print(request)` and getting this `` ( don't know what this actually is ) Am i using the following approach. On Saturday, September 30, 2017 at 8:08:22 AM UTC+5:30, Constantine

Re: get_ip_address() not working when used Custom Decorators

2017-09-29 Thread Constantine Covtushenko
Hi Mannu, It seems like all are ok. Sorry, but do you use it in just one place? And do you see response in console from your print? Regards, Constantine C. On Thu, Sep 28, 2017 at 4:36 PM, Mannu Gupta wrote: > I am just using it in a view function. For example:- > > @owner_required > def all(r

Re: get_ip_address() not working when used Custom Decorators

2017-09-28 Thread Mannu Gupta
I am just using it in a view function. For example:- @owner_required def all(request, **kwargs): pass On Friday, September 29, 2017 at 12:33:09 AM UTC+5:30, Mannu Gupta wrote: > > While making a customer decorator in django, the code is here :- > > def owner_required(function): > def wra

Re: get_ip_address() not working when used Custom Decorators

2017-09-28 Thread Daniel Roseman
On Thursday, 28 September 2017 20:03:09 UTC+1, Mannu Gupta wrote: > > While making a customer decorator in django, the code is here :- > > def owner_required(function): > def wrap(request, *args, **kwargs): > print(request) > ip_address = get_client_ip(request) > ip_exis

get_ip_address() not working when used Custom Decorators

2017-09-28 Thread Mannu Gupta
While making a customer decorator in django, the code is here :- def owner_required(function): def wrap(request, *args, **kwargs): print(request) ip_address = get_client_ip(request) ip_exist = Node.objects.get(ip_address=ip_address) if ip_exist: retu

Re: How modify Django to set URLs with decorators on the view functions like Flask? (rather than using urls.py)

2016-09-10 Thread Michal Petrucha
On Fri, Sep 09, 2016 at 10:11:25PM -0700, Chris Seberino wrote: > Flask has a neat design where instead of having a urls.py file they bind > URLs to view functions with decorators. > > Possible to do something similar with Django? What modifications would be > needed? Person

How modify Django to set URLs with decorators on the view functions like Flask? (rather than using urls.py)

2016-09-09 Thread Chris Seberino
Flask has a neat design where instead of having a urls.py file they bind URLs to view functions with decorators. Possible to do something similar with Django? What modifications would be needed? Thanks, cs -- You received this message because you are subscribed to the Google Groups

Re: 'type' object is not iterable when I use any decorators

2015-05-06 Thread Shekar Tippur
Vijay, Thanks a lot. That helped. - Shekar On Sunday, 3 May 2015 15:27:58 UTC-7, Vijay Khemlani wrote: > > user_passes_test is for decorating functions, not classes > > Django Rest Framework has its own system for permissions (and you seem to > be already using it) > > http://www.django-rest-fr

Re: 'type' object is not iterable when I use any decorators

2015-05-03 Thread Vijay Khemlani
user_passes_test is for decorating functions, not classes Django Rest Framework has its own system for permissions (and you seem to be already using it) http://www.django-rest-framework.org/api-guide/permissions/ Use that instead I think On Sun, May 3, 2015 at 2:35 PM, Shekar Tippur wrote: >

'type' object is not iterable when I use any decorators

2015-05-03 Thread Shekar Tippur
Hello, Here is a decorator that I am trying ot use to restrict access to the class to only super users: Can someone please point me to what could be wrong. If I take the decorator, I am able to get thro but it is not restricted to only super users. @user_passes_test(lambda u: u.is_superuser) c

Re: simplifying double decorators?

2014-12-01 Thread Collin Anderson
Hi, Yes, decorators are just fancy syntax. These two code blocks are the same: @the_decorator def the_view(*args): # etc def the_view(*args): # etc the_view = the_decorator(the_view) Collin On Sunday, November 30, 2014 3:19:07 PM UTC-5, Richard Brockie wrote: > > Hi, > >

Re: simplifying double decorators?

2014-11-30 Thread Richard Brockie
return decorator1(kwarg2='testing')(view) @triple_decorator() def my_view... Thanks very much! R. On Sun, Nov 30, 2014 at 11:48 AM, Arnold Krille wrote: > On Sun, 30 Nov 2014 10:30:29 -0800 Richard Brockie > wrote: > > I'm running into the situation

Re: simplifying double decorators?

2014-11-30 Thread Arnold Krille
On Sun, 30 Nov 2014 10:30:29 -0800 Richard Brockie wrote: > I'm running into the situation where I have several views with the > same set of decorators: > @login_required() > @user_passes_test(some_test_function, login_url='/', > redirect_field_name=None) > def

Re: simplifying double decorators?

2014-11-30 Thread Collin Anderson
into the situation where I have several views with the same > set of decorators: > > @login_required() > @user_passes_test(some_test_function, login_url='/', > redirect_field_name=None) > def some_view(request): > # some code > return render(request, '

simplifying double decorators?

2014-11-30 Thread Richard Brockie
Hi, I'm running into the situation where I have several views with the same set of decorators: @login_required() @user_passes_test(some_test_function, login_url='/', redirect_field_name=None) def some_view(request): # some code return render(request, 'some_template.h

Re: View decorators before CSRF verification?

2013-12-15 Thread Simon Charette
and appropriate for the attempted action. IMO the whole require_http_methods family should be fixed to work with the CSRF machinery or at least it should be documented that when using those decorators and allowing *non-safe* methods you must exempt the decorated views from CSRF che

View decorators before CSRF verification?

2013-12-15 Thread Dalton Hubble
esponse is more descriptive and appropriate for the attempted action. However, if there were some middleware to check view decorators and that middleware class was ordered earlier than the CsrfViewMiddleware, caution would be needed - Django builtin view decorators<https://docs.djangoproje

Re: cache decorators in urls.py error

2012-04-13 Thread Phang Mulianto
Hi Tom, i already fix it, it is because "then probably the error is that you have not imported your view function. It's hard to tell, as you just say 'different errors come out'." i just realize i not import my view in the url.py , as in documentation is not said i have to import it first before

Re: cache decorators in urls.py error

2012-04-13 Thread Tom Evans
On Fri, Apr 13, 2012 at 1:51 PM, Phang Mulianto wrote: > Hi , > > i already try Randomly trying things is unlikely to fix anything. cache_page decorates a function. Therefore, if this doesn't work: > (r'^$',cache_page(index), { 'template_name': > 'blog/public_list.html'}, >> 'index'), > then p

Re: cache decorators in urls.py error

2012-04-13 Thread Phang Mulianto
Hi , i already try (r'^$',cache_page(index), { 'template_name': 'blog/public_list.html'}, > 'index'), and even : (r'^$',cache_page(index()), { 'template_name': 'blog/public_list.html'}, > 'index'), but different error comes out... i don't know whats wrong.. anyone can help point it out.. O

Re: cache decorators in urls.py error

2012-04-10 Thread Tom Evans
On Sat, Apr 7, 2012 at 3:53 PM, Phang Mulianto wrote: > Hi, > > i have my apps and try to use cache decorator in url.py but got error. > > Here are the urls.py > > from django.views.decorators.cache import cache_page > > urlpatterns = patterns('article.views', >     #(r'^$','index', { 'template_na

cache decorators in urls.py error

2012-04-07 Thread Phang Mulianto
Hi, i have my apps and try to use cache decorator in url.py but got error. Here are the urls.py from django.views.decorators.cache import cache_page urlpatterns = patterns('article.views', #(r'^$','index', { 'template_name': 'blog/public_list.html'}, 'index'), (r'^$',cache_page('index')

Re: Alternative to Decorators for Class-Based View

2011-10-11 Thread Kurtis Mullins
m/en/dev/topics/class-based-views/#decorating-the-class > > Good luck! > > On Oct 5, 11:42 am, Kurtis wrote: > > Hey, > > > > What's the best way to go about doing things for class-based views > > such as requiring logins? In the function-based views

Re: Alternative to Decorators for Class-Based View

2011-10-05 Thread Dan Gentry
hat's the best way to go about doing things for class-based views > such as requiring logins? In the function-based views it was easy to > use decorators. > > Should I just replace the functionality that I would previously have > put into decorators into abstract classes that I

Alternative to Decorators for Class-Based View

2011-10-05 Thread Kurtis
Hey, What's the best way to go about doing things for class-based views such as requiring logins? In the function-based views it was easy to use decorators. Should I just replace the functionality that I would previously have put into decorators into abstract classes that I extend? If so

Interesting race condition in Django views with decorators (fix included)

2011-04-25 Thread Cal Leeming [Simplicity Media Ltd]
So, here's an interesting race condition, which causes request bleeding to happen. If you use a decorator on a view method, where the decorator is a class, the class isn't created per request, it seems to stay the same throughout. So, if you define any logic within this class, which depends on 'in

Re: Python Decorators

2011-04-06 Thread cootetom
Yeah it's really odd. Since I posted I did the test that you've just shown and it's works fine. As soon as I put the same decorator on a django view function the as_string parameter is not defined in the wrapper. It's baffled me! On Apr 6, 10:48 am, Jonathan S wrote: > Your code looks perfect.

Re: Python Decorators

2011-04-06 Thread Jonathan S
Your code looks perfect. Following does print 'True'. def widget(widget_switch, as_string=False): def decorator(func): def wrapper(*args, **kwargs): # logic in here can access the value of 'widget_switch' but 'as_string' is not defined? print as_string

RE: Python Decorators

2011-04-05 Thread Chris Matthews
Hi cootetom, For decorators you must have a look at the excellent articles/tutorials: http://www.artima.com/weblogs/viewpost.jsp?thread=240808 http://www.artima.com/weblogs/viewpost.jsp?thread=240845 It covers decorators with (what you want to do) and without parameters. Regards

Re: Do you combine you Django decorators?

2011-04-04 Thread andy
am Walters wrote: > Hi Andy > > I dont combine them... however: > I was using a couple of decorators for almost every view in one > project. Ended up putting them in middleware. > Are these decorators for every view? Maybe you should consider middleware too. > > cheers >

Python Decorators

2011-04-04 Thread cootetom
Hi all, not exactly a django question but here goes... I'm trying to implement a decorator with one positional argument and one keyword argument. My wrapper function gets the positional argument just fine but the keyword argument throws an error "NameError: name 'as_string' is not defined." Code i

Re: Do you combine you Django decorators?

2011-04-04 Thread Sam Walters
Hi Andy I dont combine them... however: I was using a couple of decorators for almost every view in one project. Ended up putting them in middleware. Are these decorators for every view? Maybe you should consider middleware too. cheers sam_w On Mon, Apr 4, 2011 at 3:26 AM, andy wrote: >

Do you combine you Django decorators?

2011-04-03 Thread andy
Do you use several Django decorators for your views or do you combine the common ones into one or two custom decorators? This is just something that I have been a bit curious about for a while now as I tend to hate using more that one decorator per view. I have often thought about combining them

Re: decorators and generic views

2011-03-24 Thread Łukasz Rekucki
On 24 March 2011 15:32, Ian Stokes-Rees wrote: > I think with the move to class-based Generic Views it is necessary to update > this documentation: > > Limiting access to generic views > > To limit access to a generic view, write a thin wrapper around the view, and > point your URLconf to your wra

decorators and generic views

2011-03-24 Thread Ian Stokes-Rees
I think with the move to class-based Generic Views it is necessary to update this documentation: Limiting access to generic views To limit access to a *generic view*, write a thin wrapper around the view, and point your URLconf to your

Pydev, decorators, and breakpoints

2011-01-03 Thread CrabbyPete
I use pydev to debug my python apps, but I can not break on a decorated function. Anyone know why and how to fix it? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscri

django-pluggables and decorators

2010-05-17 Thread imgrey
Have someone tried to use this: http://github.com/nowells/django-pluggables ? I tried to use decorators like this. class WebmoneyApp(PluggableApp): urlpatterns = patterns('', url(r'^(?P\d+)/$', 'invoice'), ) @login_required @csrf_protect

Re: decorators

2010-04-05 Thread Vasil Vangelovski
It's a deprecation warning. It means that some code in facebook.djangofb uses some part of the standard library that will be gone from future releases of python (for example python 2.7). Since it's not in your code but in some package you are using, it's the responsibility of the maintainers of tha

decorators

2010-04-04 Thread CrabbyPete
I am using pyfacebook and when I run the debug server I get the following: C:\Python26\lib\site-packages\facebook\djangofb\__init__.py:185: DeprecationWarning: Calling the deprecated function 'new_wrapper' Downgrade to decorator 2.3 if you want to use this functionality return decorator.new_wrap

Using decorators like login_required with FormPreview

2008-12-09 Thread jb0t
Recently, I tried to add multiple decorators to FormPreview http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-preview/ The only documented examples of how to accomplish this I could find were here... http://scompt.com/archives/2007/11/07/using-djangos-formpreview-with

Writing tests for views that use built-in decorators

2008-07-01 Thread Manoj Govindan
I routinely write views which use two built-in decorators, viz., login_required and transaction.commit_on_success. I am able to easily write test cases for the former. A typical test case looks like this: self.client.logout() response = self.client.get(reverse('my_view')) re

Re: checking for decorators or view meta properties

2008-06-28 Thread Julien
ttribute (which is exposed via > RequestContext and a contextprocessor if necessary) and render the > appropriate text. > > However, decorators in python aren't at all similar to annotations and > I'm not sure if it even makes sense to be able to ask a function object

checking for decorators or view meta properties

2008-06-28 Thread Leo Shklovskii
) and render the appropriate text. However, decorators in python aren't at all similar to annotations and I'm not sure if it even makes sense to be able to ask a function object if it's been decorated (it doesn't really know since decorators just wrap functions). I could che

Re: admin-doc: views with decorators bug?

2007-08-17 Thread Malcolm Tredinnick
On Fri, 2007-08-17 at 01:58 -0700, patrickk wrote: > thanks. I did a search for tickets before, but I didn´t find one (I > probably used the wrong keywords). I initially bailed on giving you numbers for that reason, too. In the interim I remembered how to find them. Tickets #1840 and #3694 are re

Re: admin-doc: views with decorators bug?

2007-08-17 Thread patrickk
dmin/doc/) with docutils > > for the first time. > > from my point of view, that´s a really cool feature. > > > however, I´m having some problems with views and decorators. > > e.g., the url /admin/filebrowser/ points to a view with this decorator: > >

Re: admin-doc: views with decorators bug?

2007-08-17 Thread Malcolm Tredinnick
On Fri, 2007-08-17 at 10:43 +0200, patrickk wrote: > I just used the integrated documentation (/admin/doc/) with docutils > for the first time. > from my point of view, that´s a really cool feature. > > however, I´m having some problems with views and decorators. > e.

admin-doc: views with decorators bug?

2007-08-17 Thread patrickk
I just used the integrated documentation (/admin/doc/) with docutils for the first time. from my point of view, that´s a really cool feature. however, I´m having some problems with views and decorators. e.g., the url /admin/filebrowser/ points to a view with this decorator: index

Re: /admin/doc/ problem with decorators

2007-06-14 Thread Malcolm Tredinnick
On Thu, 2007-06-14 at 15:35 +0200, Wolfram Kriesing wrote: > i found out that the admin site provides docs, which is pretty cool, > but the problem when clicking on a view-function that has a decorator > (no matter if it is login_required or transaction.*) I always get an > error page > > below t

/admin/doc/ problem with decorators

2007-06-14 Thread Wolfram Kriesing
i found out that the admin site provides docs, which is pretty cool, but the problem when clicking on a view-function that has a decorator (no matter if it is login_required or transaction.*) I always get an error page below the link it says: View function: django.contrib.auth.decorators._ch

URLConf parameter passing and Decorators

2007-06-08 Thread [EMAIL PROTECTED]
tterns('builder_views', (r'^(?P\d+)/profile/$', 'builder_profile'), ) #builder_views.py from django.contrib.auth import decorators from decorators import * @decorators.login_required @builder_ok def builder_profile( request, builder_id ): "&quo

can Transcation middleware work with Transcation decorators?

2006-05-23 Thread favo
Can they work together? --~--~-~--~~~---~--~~ 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 P