confirmation: Avoid fetching time twice creating confirmation link.

This avoids a quirk where the expiry date would be a few microseconds
before the time that would be expected from the creation timestamp.
This commit is contained in:
Tim Abbott 2021-09-10 16:54:09 -07:00
parent ad188130ba
commit e5c1b8e614
1 changed files with 4 additions and 3 deletions

View File

@ -98,17 +98,18 @@ def create_confirmation_link(
elif hasattr(obj, "realm"):
realm = obj.realm
current_time = timezone_now()
expiry_date = None
if validity_in_days:
expiry_date = timezone_now() + datetime.timedelta(days=validity_in_days)
expiry_date = current_time + datetime.timedelta(days=validity_in_days)
else:
expiry_date = timezone_now() + datetime.timedelta(
expiry_date = current_time + datetime.timedelta(
days=_properties[confirmation_type].validity_in_days
)
Confirmation.objects.create(
content_object=obj,
date_sent=timezone_now(),
date_sent=current_time,
confirmation_key=key,
realm=realm,
expiry_date=expiry_date,