mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
Remove extra parentheses (#4789)
This commit is contained in:
parent
44a99a11c3
commit
4dd71d68d2
|
@ -149,7 +149,7 @@ def to_choices_dict(choices):
|
||||||
# choices = [('Category', ((1, 'First'), (2, 'Second'))), (3, 'Third')]
|
# choices = [('Category', ((1, 'First'), (2, 'Second'))), (3, 'Third')]
|
||||||
ret = OrderedDict()
|
ret = OrderedDict()
|
||||||
for choice in choices:
|
for choice in choices:
|
||||||
if (not isinstance(choice, (list, tuple))):
|
if not isinstance(choice, (list, tuple)):
|
||||||
# single choice
|
# single choice
|
||||||
ret[choice] = choice
|
ret[choice] = choice
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -131,7 +131,7 @@ def _reverse_ordering(ordering_tuple):
|
||||||
ordering and return a new tuple, eg. `('created', '-uuid')`.
|
ordering and return a new tuple, eg. `('created', '-uuid')`.
|
||||||
"""
|
"""
|
||||||
def invert(x):
|
def invert(x):
|
||||||
return x[1:] if (x.startswith('-')) else '-' + x
|
return x[1:] if x.startswith('-') else '-' + x
|
||||||
|
|
||||||
return tuple([invert(item) for item in ordering_tuple])
|
return tuple([invert(item) for item in ordering_tuple])
|
||||||
|
|
||||||
|
|
|
@ -503,7 +503,7 @@ class ManyRelatedField(Field):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
relationship = get_attribute(instance, self.source_attrs)
|
relationship = get_attribute(instance, self.source_attrs)
|
||||||
return relationship.all() if (hasattr(relationship, 'all')) else relationship
|
return relationship.all() if hasattr(relationship, 'all') else relationship
|
||||||
|
|
||||||
def to_representation(self, iterable):
|
def to_representation(self, iterable):
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -540,7 +540,7 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
# If possible, serialize the initial content for the generic form
|
# If possible, serialize the initial content for the generic form
|
||||||
default_parser = view.parser_classes[0]
|
default_parser = view.parser_classes[0]
|
||||||
renderer_class = getattr(default_parser, 'renderer_class', None)
|
renderer_class = getattr(default_parser, 'renderer_class', None)
|
||||||
if (hasattr(view, 'get_serializer') and renderer_class):
|
if hasattr(view, 'get_serializer') and renderer_class:
|
||||||
# View has a serializer defined and parser class has a
|
# View has a serializer defined and parser class has a
|
||||||
# corresponding renderer that can be used to render the data.
|
# corresponding renderer that can be used to render the data.
|
||||||
|
|
||||||
|
@ -598,7 +598,7 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
paginator = getattr(view, 'paginator', None)
|
paginator = getattr(view, 'paginator', None)
|
||||||
if isinstance(data, list):
|
if isinstance(data, list):
|
||||||
pass
|
pass
|
||||||
elif (paginator is not None and data is not None):
|
elif paginator is not None and data is not None:
|
||||||
try:
|
try:
|
||||||
paginator.get_results(data)
|
paginator.get_results(data)
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
|
@ -738,7 +738,7 @@ class AdminRenderer(BrowsableAPIRenderer):
|
||||||
ret = template_render(template, context, request=renderer_context['request'])
|
ret = template_render(template, context, request=renderer_context['request'])
|
||||||
|
|
||||||
# Creation and deletion should use redirects in the admin style.
|
# Creation and deletion should use redirects in the admin style.
|
||||||
if (response.status_code == status.HTTP_201_CREATED) and ('Location' in response):
|
if response.status_code == status.HTTP_201_CREATED and 'Location' in response:
|
||||||
response.status_code = status.HTTP_303_SEE_OTHER
|
response.status_code = status.HTTP_303_SEE_OTHER
|
||||||
response['Location'] = request.build_absolute_uri()
|
response['Location'] = request.build_absolute_uri()
|
||||||
ret = ''
|
ret = ''
|
||||||
|
@ -764,7 +764,7 @@ class AdminRenderer(BrowsableAPIRenderer):
|
||||||
)
|
)
|
||||||
|
|
||||||
paginator = getattr(context['view'], 'paginator', None)
|
paginator = getattr(context['view'], 'paginator', None)
|
||||||
if (paginator is not None and data is not None):
|
if paginator is not None and data is not None:
|
||||||
try:
|
try:
|
||||||
results = paginator.get_results(data)
|
results = paginator.get_results(data)
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
|
|
|
@ -152,7 +152,7 @@ class Request(object):
|
||||||
|
|
||||||
force_user = getattr(request, '_force_auth_user', None)
|
force_user = getattr(request, '_force_auth_user', None)
|
||||||
force_token = getattr(request, '_force_auth_token', None)
|
force_token = getattr(request, '_force_auth_token', None)
|
||||||
if (force_user is not None or force_token is not None):
|
if force_user is not None or force_token is not None:
|
||||||
forced_auth = ForcedAuthentication(force_user, force_token)
|
forced_auth = ForcedAuthentication(force_user, force_token)
|
||||||
self.authenticators = (forced_auth,)
|
self.authenticators = (forced_auth,)
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ class NamespaceVersioning(BaseVersioning):
|
||||||
|
|
||||||
def determine_version(self, request, *args, **kwargs):
|
def determine_version(self, request, *args, **kwargs):
|
||||||
resolver_match = getattr(request, 'resolver_match', None)
|
resolver_match = getattr(request, 'resolver_match', None)
|
||||||
if (resolver_match is None or not resolver_match.namespace):
|
if resolver_match is None or not resolver_match.namespace:
|
||||||
return self.default_version
|
return self.default_version
|
||||||
|
|
||||||
# Allow for possibly nested namespaces.
|
# Allow for possibly nested namespaces.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user