diff --git a/zephyr/management/commands/populate_db.py b/zephyr/management/commands/populate_db.py index 604f9f0bfd..37df4ab81e 100644 --- a/zephyr/management/commands/populate_db.py +++ b/zephyr/management/commands/populate_db.py @@ -1,5 +1,5 @@ from django.core.management.base import BaseCommand -from django.utils.timezone import utc +from django.utils.timezone import utc, now from django.contrib.auth.models import User from django.contrib.sites.models import Site @@ -630,7 +630,7 @@ def send_messages(data): message.subject = stream.name + str(random.randint(1, 3)) saved_data = message.subject - message.pub_date = datetime.datetime.utcnow().replace(tzinfo=utc) + message.pub_date = now() do_send_message(message) recipients[num_messages] = [message_type, message.recipient.id, saved_data] diff --git a/zephyr/tests.py b/zephyr/tests.py index b19d8a5116..f04e226626 100644 --- a/zephyr/tests.py +++ b/zephyr/tests.py @@ -1,6 +1,6 @@ from django.contrib.auth.models import User from django.test import TestCase -from django.utils.timezone import utc +from django.utils.timezone import now from django.db.models import Q from zephyr.models import Message, UserProfile, Stream, Recipient, Subscription, \ @@ -9,7 +9,6 @@ from zephyr.views import json_get_updates from zephyr.decorator import TornadoAsyncException from zephyr.lib.initial_password import initial_password -import datetime import simplejson import subprocess subprocess.check_call("zephyr/tests/generate-fixtures"); @@ -58,7 +57,7 @@ class AuthedTestCase(TestCase): else: recipient = Stream.objects.get(name=recipient_name, realm=sender.realm) recipient = Recipient.objects.get(type_id=recipient.id, type=message_type) - pub_date = datetime.datetime.utcnow().replace(tzinfo=utc) + pub_date = now() (sending_client, _) = Client.objects.get_or_create(name="test suite") do_send_message(Message(sender=sender, recipient=recipient, subject="test", pub_date=pub_date, sending_client=sending_client)) diff --git a/zephyr/views.py b/zephyr/views.py index a7f9cbdf27..7f81ff998e 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render_to_response from django.template import RequestContext -from django.utils.timezone import utc +from django.utils.timezone import utc, now from django.core.exceptions import ValidationError from django.contrib.auth.views import login as django_login_page from zephyr.models import Message, UserProfile, Stream, Subscription, \ @@ -676,7 +676,7 @@ def send_message_backend(request, user_profile, sender, client_name=None): # Forged messages come with a timestamp message.pub_date = datetime.datetime.utcfromtimestamp(float(request.POST['time'])).replace(tzinfo=utc) else: - message.pub_date = datetime.datetime.utcnow().replace(tzinfo=utc) + message.pub_date = now() message.sending_client = get_client(client_name) do_send_message(message)