Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use inline if
  • Loading branch information
longhotsummer committed Feb 4, 2015
commit d920683237bd2eb17d110a80fc09708a67340f01
11 changes: 5 additions & 6 deletions rest_framework/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def api_view(http_method_names=None):
Decorator that converts a function-based view into an APIView subclass.
Takes a list of allowed methods for the view as an argument.
"""
if http_method_names is None:
http_method_names = ['GET']
http_method_names = ['GET'] if http_method_names is None else http_method_names

def decorator(func):

Expand Down Expand Up @@ -113,8 +112,8 @@ def detail_route(methods=None, **kwargs):
"""
Used to mark a method on a ViewSet that should be routed for detail requests.
"""
if methods is None:
methods = ['get']
methods = ['get'] if methods is None else methods
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor one, this, but I tend to prefer using brackets around the if clause for visual clarity, so I normally do...

['get'] if (methods is None) else methods


def decorator(func):
func.bind_to_methods = methods
func.detail = True
Expand All @@ -127,8 +126,8 @@ def list_route(methods=None, **kwargs):
"""
Used to mark a method on a ViewSet that should be routed for list requests.
"""
if methods is None:
methods = ['get']
methods = ['get'] if methods is None else methods

def decorator(func):
func.bind_to_methods = methods
func.detail = False
Expand Down