Remove several instances of datetime.datetime.utcnow().

Change to the timezone-aware django.utils.timezone.now() where django is
available.
This commit is contained in:
Rishi Gupta
2016-11-05 18:49:37 -07:00
committed by Tim Abbott
parent 9e5ec2fd29
commit 9e6e1a1e69
2 changed files with 6 additions and 8 deletions

View File

@@ -290,7 +290,7 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
msg.attach_alternative(html_content, "text/html") msg.attach_alternative(html_content, "text/html")
msg.send() msg.send()
user_profile.last_reminder = datetime.datetime.now() user_profile.last_reminder = timezone.now()
user_profile.save(update_fields=['last_reminder']) user_profile.save(update_fields=['last_reminder'])
def handle_missedmessage_emails(user_profile_id, missed_email_events): def handle_missedmessage_emails(user_profile_id, missed_email_events):
@@ -424,7 +424,7 @@ def send_future_email(recipients, email_html, email_text, subject,
if delay < datetime.timedelta(minutes=1): if delay < datetime.timedelta(minutes=1):
results = mail_client.messages.send(message=message, async=False, ip_pool="Main Pool") results = mail_client.messages.send(message=message, async=False, ip_pool="Main Pool")
else: else:
send_time = (datetime.datetime.utcnow() + delay).__format__("%Y-%m-%d %H:%M:%S") send_time = (timezone.now() + delay).__format__("%Y-%m-%d %H:%M:%S")
results = mail_client.messages.send(message=message, async=False, ip_pool="Main Pool", send_at=send_time) results = mail_client.messages.send(message=message, async=False, ip_pool="Main Pool", send_at=send_time)
problems = [result for result in results if (result['status'] in ('rejected', 'invalid'))] problems = [result for result in results if (result['status'] in ('rejected', 'invalid'))]

View File

@@ -5,7 +5,7 @@ import time
from typing import Any from typing import Any
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.utils.timezone import now from django.utils import timezone
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from zerver.decorator import authenticated_json_post_view from zerver.decorator import authenticated_json_post_view
@@ -28,8 +28,8 @@ def update_active_status_backend(request, user_profile, status=REQ(),
if status_val is None: if status_val is None:
raise JsonableError(_("Invalid presence status: %s") % (status,)) raise JsonableError(_("Invalid presence status: %s") % (status,))
else: else:
update_user_presence(user_profile, request.client, now(), status_val, update_user_presence(user_profile, request.client, timezone.now(),
new_user_input) status_val, new_user_input)
ret = get_status_list(user_profile) ret = get_status_list(user_profile)
if user_profile.realm.is_zephyr_mirror_realm: if user_profile.realm.is_zephyr_mirror_realm:
@@ -42,10 +42,8 @@ def update_active_status_backend(request, user_profile, status=REQ(),
client__name="zephyr_mirror") client__name="zephyr_mirror")
ret['zephyr_mirror_active'] = \ ret['zephyr_mirror_active'] = \
(activity.last_visit.replace(tzinfo=None) > (activity.last_visit > timezone.now() - datetime.timedelta(minutes=5))
datetime.datetime.utcnow() - datetime.timedelta(minutes=5))
except UserActivity.DoesNotExist: except UserActivity.DoesNotExist:
ret['zephyr_mirror_active'] = False ret['zephyr_mirror_active'] = False
return json_success(ret) return json_success(ret)