mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 08:29:59 +03:00
Replace inline if
statements with or
example: (x = something if (x is None) else x ) --> (x = x or something)
This commit is contained in:
parent
efc7c1d664
commit
06040c4d26
|
@ -18,7 +18,7 @@ def api_view(http_method_names=None):
|
||||||
Decorator that converts a function-based view into an APIView subclass.
|
Decorator that converts a function-based view into an APIView subclass.
|
||||||
Takes a list of allowed methods for the view as an argument.
|
Takes a list of allowed methods for the view as an argument.
|
||||||
"""
|
"""
|
||||||
http_method_names = ['GET'] if (http_method_names is None) else http_method_names
|
http_method_names = http_method_names or ['GET']
|
||||||
|
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
|
|
||||||
|
@ -142,8 +142,7 @@ def action(methods=None, detail=None, url_path=None, url_name=None, **kwargs):
|
||||||
how the `@renderer_classes` etc. decorators work for function-
|
how the `@renderer_classes` etc. decorators work for function-
|
||||||
based API views.
|
based API views.
|
||||||
"""
|
"""
|
||||||
methods = ['get'] if methods is None else methods
|
methods = [method.lower() for method in methods or ['get']]
|
||||||
methods = [method.lower() for method in methods]
|
|
||||||
|
|
||||||
assert detail is not None, (
|
assert detail is not None, (
|
||||||
"@action() missing required argument: 'detail'"
|
"@action() missing required argument: 'detail'"
|
||||||
|
|
|
@ -345,7 +345,7 @@ class Field:
|
||||||
self.initial = self.initial if (initial is empty) else initial
|
self.initial = self.initial if (initial is empty) else initial
|
||||||
self.label = label
|
self.label = label
|
||||||
self.help_text = help_text
|
self.help_text = help_text
|
||||||
self.style = {} if style is None else style
|
self.style = style or {}
|
||||||
self.allow_null = allow_null
|
self.allow_null = allow_null
|
||||||
|
|
||||||
if self.default_empty_html is not empty:
|
if self.default_empty_html is not empty:
|
||||||
|
|
|
@ -45,7 +45,7 @@ def order_by_precedence(media_type_lst):
|
||||||
|
|
||||||
class _MediaType:
|
class _MediaType:
|
||||||
def __init__(self, media_type_str):
|
def __init__(self, media_type_str):
|
||||||
self.orig = '' if (media_type_str is None) else media_type_str
|
self.orig = media_type_str or ''
|
||||||
self.full_type, self.params = parse_header(self.orig.encode(HTTP_HEADER_ENCODING))
|
self.full_type, self.params = parse_header(self.orig.encode(HTTP_HEADER_ENCODING))
|
||||||
self.main_type, sep, self.sub_type = self.full_type.partition('/')
|
self.main_type, sep, self.sub_type = self.full_type.partition('/')
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ class URLPathVersioning(BaseVersioning):
|
||||||
|
|
||||||
def reverse(self, viewname, args=None, kwargs=None, request=None, format=None, **extra):
|
def reverse(self, viewname, args=None, kwargs=None, request=None, format=None, **extra):
|
||||||
if request.version is not None:
|
if request.version is not None:
|
||||||
kwargs = {} if (kwargs is None) else kwargs
|
kwargs = kwargs or {}
|
||||||
kwargs[self.version_param] = request.version
|
kwargs[self.version_param] = request.version
|
||||||
|
|
||||||
return super().reverse(
|
return super().reverse(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user