summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-05-26 12:16:26 +0200
committerGitHub <noreply@github.com>2023-05-26 12:16:26 +0200
commitd3d173425fc0a1107836da5b4567f1c88253191b (patch)
treea4a4c7a1bfe59d9762e77255136a52c8e804f8ed
parent881cc139e2d53cc1d3ccea7f38faa960f9e56597 (diff)
Optimized @condition decorator a bit.
This removes unnecessary get_last_modified() hook.
-rw-r--r--django/views/decorators/http.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/django/views/decorators/http.py b/django/views/decorators/http.py
index 6d88a633eb..4ad520fb25 100644
--- a/django/views/decorators/http.py
+++ b/django/views/decorators/http.py
@@ -86,19 +86,15 @@ def condition(etag_func=None, last_modified_func=None):
@wraps(func)
def inner(request, *args, **kwargs):
# Compute values (if any) for the requested resource.
- def get_last_modified():
- if last_modified_func:
- dt = last_modified_func(request, *args, **kwargs)
- if dt:
- if not timezone.is_aware(dt):
- dt = timezone.make_aware(dt, datetime.timezone.utc)
- return int(dt.timestamp())
-
+ res_last_modified = None
+ if last_modified_func:
+ if dt := last_modified_func(request, *args, **kwargs):
+ if not timezone.is_aware(dt):
+ dt = timezone.make_aware(dt, datetime.timezone.utc)
+ res_last_modified = int(dt.timestamp())
# The value from etag_func() could be quoted or unquoted.
res_etag = etag_func(request, *args, **kwargs) if etag_func else None
res_etag = quote_etag(res_etag) if res_etag is not None else None
- res_last_modified = get_last_modified()
-
response = get_conditional_response(
request,
etag=res_etag,