Re: Deprecate HttpRequest.is_ajax

2019-11-17 Thread Adam Johnson
Right - Flask's error message also points to something I was mistaken
about. XMLHttpRequest does not set this header. jQuery adds it (
https://api.jquery.com/jquery.ajax/#jQuery-ajax-settings ), and presumably
some other JS libraries.

In my opinion there are not many good reasons to have to change behaviour
> if a request is made via XHR. I think the most common usage is to have a
> single view that returns a JSON response or a HTML response depending on if
> XHR is used (
> https://github.com/search?l=Python&q=request.is_ajax&type=Code), which
> isn’t great and isn’t reliable.
>

Riight too. A better way would be to check the Accept header. DRF does
this: https://www.django-rest-framework.org/api-guide/content-negotiation/
. Django doesn't provide any tools at the moment for parsing Accept. We
could add an API like https://pypi.org/project/django-accept-header/ ?

On Sat, 16 Nov 2019 at 16:16, Tom Forbes  wrote:

> I would agree. Flask has done the same:
>
> DeprecationWarning: Request.is_xhr is deprecated. Given that the
> X-Requested-With header is not a part of any spec, it is not reliable
>
> In my opinion there are not many good reasons to have to change behaviour
> if a request is made via XHR. I think the most common usage is to have a
> single view that returns a JSON response or a HTML response depending on if
> XHR is used (
> https://github.com/search?l=Python&q=request.is_ajax&type=Code), which
> isn’t great and isn’t reliable.
>
>
> On 16 Nov 2019, at 16:08, Adam Johnson  wrote:
>
> Django's HttpRequest.is_ajax method determines whether the request was
> made with the JS API XMLHttpRequest
> https://docs.djangoproject.com/en/2.2/ref/request-response/#django.http.HttpRequest.is_ajax
> . It does so by checking the X-Requested-With header.
>
> The new way of making "AJAX" requests from the browser is the JavaScript
> fetch() API : https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API .
>
> I think the  is_ajax() documentation is at least a little misleading in
> pretending XMLHttpRequest is the only JS API. There also aren't any special
> headers set by fetch() so it's not possible to detect its requests.
>
> I propose deprecating is_ajax() with no replacement.
>
> Thoughts?
>
> --
> Adam
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAMyDDM0i-p0ZxBj-fSheGs-2pMXH7K7Oka%3DCjy1YXx-emBu3mw%40mail.gmail.com
> 
> .
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/84DCD242-69A8-4B8D-9EB6-243312B5F77F%40tomforb.es
> 
> .
>


-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM12ozNou4y6s-AktSwnMfBLDR5FJjYAw-n0kofZ3%3DYtoA%40mail.gmail.com.


Re: Deprecate HttpRequest.is_ajax

2019-11-17 Thread Jani Tiainen
Hi.

I would be really favorable suggested approach which would open up more
possibilities to responses. And in general sounds good direction.

su 17. marrask. 2019 klo 10.00 Adam Johnson  kirjoitti:

> Right - Flask's error message also points to something I was mistaken
> about. XMLHttpRequest does not set this header. jQuery adds it (
> https://api.jquery.com/jquery.ajax/#jQuery-ajax-settings ), and
> presumably some other JS libraries.
>
> In my opinion there are not many good reasons to have to change behaviour
>> if a request is made via XHR. I think the most common usage is to have a
>> single view that returns a JSON response or a HTML response depending on if
>> XHR is used (
>> https://github.com/search?l=Python&q=request.is_ajax&type=Code), which
>> isn’t great and isn’t reliable.
>>
>
> Riight too. A better way would be to check the Accept header. DRF does
> this: https://www.django-rest-framework.org/api-guide/content-negotiation/
> . Django doesn't provide any tools at the moment for parsing Accept. We
> could add an API like https://pypi.org/project/django-accept-header/ ?
>
> On Sat, 16 Nov 2019 at 16:16, Tom Forbes  wrote:
>
>> I would agree. Flask has done the same:
>>
>> DeprecationWarning: Request.is_xhr is deprecated. Given that the
>> X-Requested-With header is not a part of any spec, it is not reliable
>>
>> In my opinion there are not many good reasons to have to change behaviour
>> if a request is made via XHR. I think the most common usage is to have a
>> single view that returns a JSON response or a HTML response depending on if
>> XHR is used (
>> https://github.com/search?l=Python&q=request.is_ajax&type=Code), which
>> isn’t great and isn’t reliable.
>>
>>
>> On 16 Nov 2019, at 16:08, Adam Johnson  wrote:
>>
>> Django's HttpRequest.is_ajax method determines whether the request was
>> made with the JS API XMLHttpRequest
>> https://docs.djangoproject.com/en/2.2/ref/request-response/#django.http.HttpRequest.is_ajax
>> . It does so by checking the X-Requested-With header.
>>
>> The new way of making "AJAX" requests from the browser is the JavaScript
>> fetch() API : https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
>> .
>>
>> I think the  is_ajax() documentation is at least a little misleading in
>> pretending XMLHttpRequest is the only JS API. There also aren't any special
>> headers set by fetch() so it's not possible to detect its requests.
>>
>> I propose deprecating is_ajax() with no replacement.
>>
>> Thoughts?
>>
>> --
>> Adam
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-developers+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-developers/CAMyDDM0i-p0ZxBj-fSheGs-2pMXH7K7Oka%3DCjy1YXx-emBu3mw%40mail.gmail.com
>> 
>> .
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-developers+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-developers/84DCD242-69A8-4B8D-9EB6-243312B5F77F%40tomforb.es
>> 
>> .
>>
>
>
> --
> Adam
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAMyDDM12ozNou4y6s-AktSwnMfBLDR5FJjYAw-n0kofZ3%3DYtoA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAHn91ofvv3JXppzfGojGgOrQSRrXPhwAMmt_xos4GUsi_BFZdA%40mail.gmail.com.


Re: Deprecate HttpRequest.is_ajax

2019-11-17 Thread Asif Saif Uddin
any plan with 
https://github.com/django/deps/blob/master/draft/content-negotiation.rst 
one?

On Sunday, November 17, 2019 at 2:00:26 PM UTC+6, Adam Johnson wrote:
>
> Right - Flask's error message also points to something I was mistaken 
> about. XMLHttpRequest does not set this header. jQuery adds it ( 
> https://api.jquery.com/jquery.ajax/#jQuery-ajax-settings ), and 
> presumably some other JS libraries.
>
> In my opinion there are not many good reasons to have to change behaviour 
>> if a request is made via XHR. I think the most common usage is to have a 
>> single view that returns a JSON response or a HTML response depending on if 
>> XHR is used (
>> https://github.com/search?l=Python&q=request.is_ajax&type=Code), which 
>> isn’t great and isn’t reliable.
>>
>
> Riight too. A better way would be to check the Accept header. DRF does 
> this: https://www.django-rest-framework.org/api-guide/content-negotiation/ 
> . Django doesn't provide any tools at the moment for parsing Accept. We 
> could add an API like https://pypi.org/project/django-accept-header/ ?
>
> On Sat, 16 Nov 2019 at 16:16, Tom Forbes > 
> wrote:
>
>> I would agree. Flask has done the same:
>>
>> DeprecationWarning: Request.is_xhr is deprecated. Given that the 
>> X-Requested-With header is not a part of any spec, it is not reliable
>>
>> In my opinion there are not many good reasons to have to change behaviour 
>> if a request is made via XHR. I think the most common usage is to have a 
>> single view that returns a JSON response or a HTML response depending on if 
>> XHR is used (
>> https://github.com/search?l=Python&q=request.is_ajax&type=Code), which 
>> isn’t great and isn’t reliable.
>>
>>
>> On 16 Nov 2019, at 16:08, Adam Johnson > 
>> wrote:
>>
>> Django's HttpRequest.is_ajax method determines whether the request was 
>> made with the JS API XMLHttpRequest 
>> https://docs.djangoproject.com/en/2.2/ref/request-response/#django.http.HttpRequest.is_ajax
>>  
>> . It does so by checking the X-Requested-With header.
>>
>> The new way of making "AJAX" requests from the browser is the JavaScript 
>> fetch() API : https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API 
>> .
>>
>> I think the  is_ajax() documentation is at least a little misleading in 
>> pretending XMLHttpRequest is the only JS API. There also aren't any special 
>> headers set by fetch() so it's not possible to detect its requests.
>>
>> I propose deprecating is_ajax() with no replacement.
>>
>> Thoughts?
>>
>> -- 
>> Adam
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-d...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-developers/CAMyDDM0i-p0ZxBj-fSheGs-2pMXH7K7Oka%3DCjy1YXx-emBu3mw%40mail.gmail.com
>>  
>> 
>> .
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-d...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-developers/84DCD242-69A8-4B8D-9EB6-243312B5F77F%40tomforb.es
>>  
>> 
>> .
>>
>
>
> -- 
> Adam
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/48b34cca-02bf-4f2c-817d-65afbd1ab125%40googlegroups.com.


Re: Deprecate HttpRequest.is_ajax

2019-11-17 Thread Claude Paroz
I'm afraid that implementing a whole content negociation framework is a bit 
ambitious, unless someone has much time to devote to that.

We could start smaller, similar to django-accept-header. I quickly sketched 
what it could look like in:
https://github.com/django/django/compare/master...claudep:accept_header?expand=1

Claude

Le dimanche 17 novembre 2019 12:32:50 UTC+1, Asif Saif Uddin a écrit :
>
> any plan with 
> https://github.com/django/deps/blob/master/draft/content-negotiation.rst 
> one?
>
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/7aff16cc-aeff-4b5e-b402-e4d587bc9315%40googlegroups.com.


Re: Deprecate HttpRequest.is_ajax

2019-11-17 Thread Tom Forbes
I think this is a good starting point. What do we think about adding a 
“accepts_json” helper of some kind? It seems that the vast, vast majority of 
usages I can find of “is_ajax” is to return a JSON response, which I feel could 
be served nicely with a helper. There are also, annoyingly, two different JSON 
content types that are sent (the correct application/json and the incorrect 
text/json), which a helper could take care of. 


> On 17 Nov 2019, at 12:56, Claude Paroz  wrote:
> 
> I'm afraid that implementing a whole content negociation framework is a bit 
> ambitious, unless someone has much time to devote to that.
> 
> We could start smaller, similar to django-accept-header. I quickly sketched 
> what it could look like in:
> https://github.com/django/django/compare/master...claudep:accept_header?expand=1
> 
> Claude
> 
> Le dimanche 17 novembre 2019 12:32:50 UTC+1, Asif Saif Uddin a écrit :
> any plan with 
> https://github.com/django/deps/blob/master/draft/content-negotiation.rst 
>  
> one?
>  
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-developers+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-developers/7aff16cc-aeff-4b5e-b402-e4d587bc9315%40googlegroups.com
>  
> .

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/22260C6C-702C-40F3-A847-38C0A69D3C43%40tomforb.es.