#32922: Adding "preferred_language" property to "HttpRequest" object
-------------------------------+--------------------------------------
     Reporter:  pixel365       |                    Owner:  nobody
         Type:  New feature    |                   Status:  new
    Component:  HTTP handling  |                  Version:  3.2
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Description changed by pixel365:

Old description:

> Sometimes it is useful to get the client's preferred language from the
> request and then pass it somewhere, for example, apply a filter to fetch
> data.
> Therefore, it is useful to access this property in the object.
>

>
> {{{
> @property
> def preferred_language(self):
>     """Returns the client's language in order of priority from the
> "Accept-Language" header"""
>     languages = [_.strip() for _ in self.headers.get('Accept-Language',
> '*').split(',')]
>     for language in languages:
>         if language.split(';')[0] == language:
>             return language
>         return language.split(';')[0]
>     return '*'
> }}}

New description:

 Sometimes it is useful to get the client's preferred language from the
 request and then pass it somewhere, for example, apply a filter to fetch
 data.
 Therefore, it is useful to access this property in the object.



 {{{
 @property
 def preferred_language(self):
     """Returns the client's language in order of priority from the
 "Accept-Language" header"""
     languages = [_.strip() for _ in self.headers.get('Accept-Language',
 '*').split(',')]
     return languages[0].split(';')[0]
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32922#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

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

Reply via email to