mirror of https://github.com/django/django.git
Optimized @condition decorator a bit.
This removes unnecessary get_last_modified() hook.
This commit is contained in:
parent
881cc139e2
commit
d3d173425f
|
@ -86,19 +86,15 @@ def condition(etag_func=None, last_modified_func=None):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def inner(request, *args, **kwargs):
|
def inner(request, *args, **kwargs):
|
||||||
# Compute values (if any) for the requested resource.
|
# Compute values (if any) for the requested resource.
|
||||||
def get_last_modified():
|
res_last_modified = None
|
||||||
if last_modified_func:
|
if last_modified_func:
|
||||||
dt = last_modified_func(request, *args, **kwargs)
|
if dt := last_modified_func(request, *args, **kwargs):
|
||||||
if dt:
|
if not timezone.is_aware(dt):
|
||||||
if not timezone.is_aware(dt):
|
dt = timezone.make_aware(dt, datetime.timezone.utc)
|
||||||
dt = timezone.make_aware(dt, datetime.timezone.utc)
|
res_last_modified = int(dt.timestamp())
|
||||||
return int(dt.timestamp())
|
|
||||||
|
|
||||||
# The value from etag_func() could be quoted or unquoted.
|
# The value from etag_func() could be quoted or unquoted.
|
||||||
res_etag = etag_func(request, *args, **kwargs) if etag_func else None
|
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_etag = quote_etag(res_etag) if res_etag is not None else None
|
||||||
res_last_modified = get_last_modified()
|
|
||||||
|
|
||||||
response = get_conditional_response(
|
response = get_conditional_response(
|
||||||
request,
|
request,
|
||||||
etag=res_etag,
|
etag=res_etag,
|
||||||
|
|
Loading…
Reference in New Issue