mirror of
https://github.com/zulip/zulip.git
synced 2025-11-22 07:21:23 +00:00
Add new timestamp_to_datetime helper function.
(imported from commit 6791d009ae2e8371abe2c929e87c816a1981f5fe)
This commit is contained in:
5
zephyr/lib/time.py
Normal file
5
zephyr/lib/time.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import datetime
|
||||||
|
from django.utils.timezone import utc
|
||||||
|
|
||||||
|
def timestamp_to_datetime(timestamp):
|
||||||
|
return datetime.datetime.utcfromtimestamp(float(timestamp)).replace(tzinfo=utc)
|
||||||
@@ -15,6 +15,7 @@ from django.db import transaction, connection
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from api.bots import mit_subs_list
|
from api.bots import mit_subs_list
|
||||||
from zephyr.lib.bulk_create import batch_bulk_create
|
from zephyr.lib.bulk_create import batch_bulk_create
|
||||||
|
from zephyr.lib.time import timestamp_to_datetime
|
||||||
|
|
||||||
import simplejson
|
import simplejson
|
||||||
import datetime
|
import datetime
|
||||||
@@ -463,8 +464,7 @@ def restore_saved_messages():
|
|||||||
message.type = type_hash[old_message["type"]]
|
message.type = type_hash[old_message["type"]]
|
||||||
message.content = old_message["content"]
|
message.content = old_message["content"]
|
||||||
message.subject = old_message["subject"]
|
message.subject = old_message["subject"]
|
||||||
ts = float(old_message["timestamp"])
|
message.pub_date = timestamp_to_datetime(old_message["timestamp"])
|
||||||
message.pub_date = datetime.datetime.utcfromtimestamp(ts).replace(tzinfo=utc)
|
|
||||||
|
|
||||||
if message.type == Recipient.PERSONAL:
|
if message.type == Recipient.PERSONAL:
|
||||||
message.recipient = user_recipients[old_message["recipient"][0]["email"]]
|
message.recipient = user_recipients[old_message["recipient"][0]["email"]]
|
||||||
@@ -524,8 +524,8 @@ def restore_saved_messages():
|
|||||||
elif old_message["type"] == "user_activated" or old_message["type"] == "user_created":
|
elif old_message["type"] == "user_activated" or old_message["type"] == "user_created":
|
||||||
# These are rare, so just handle them the slow way
|
# These are rare, so just handle them the slow way
|
||||||
user = User.objects.get(email=old_message["user"])
|
user = User.objects.get(email=old_message["user"])
|
||||||
timestamp=datetime.datetime.utcfromtimestamp(float(old_message['timestamp'])).replace(tzinfo=utc)
|
join_date = timestamp_to_datetime(old_message['timestamp'])
|
||||||
do_activate_user(user, log=False, timestamp=timestamp)
|
do_activate_user(user, log=False, join_date=join_date)
|
||||||
# Update the cache of users to show this user as activated
|
# Update the cache of users to show this user as activated
|
||||||
users_by_id[user.userprofile.id] = UserProfile.objects.get(user=user)
|
users_by_id[user.userprofile.id] = UserProfile.objects.get(user=user)
|
||||||
users[user.email] = user.userprofile
|
users[user.email] = user.userprofile
|
||||||
|
|||||||
@@ -601,10 +601,10 @@ def log_subscription_property_change(user_email, property, property_dict):
|
|||||||
event.update(property_dict)
|
event.update(property_dict)
|
||||||
log_event(event)
|
log_event(event)
|
||||||
|
|
||||||
def do_activate_user(user, log=True, timestamp=time.time()):
|
def do_activate_user(user, log=True, join_date=time.time()):
|
||||||
user.is_active = True
|
user.is_active = True
|
||||||
user.set_password(initial_password(user.email))
|
user.set_password(initial_password(user.email))
|
||||||
user.date_joined = timestamp
|
user.date_joined = join_date
|
||||||
user.save()
|
user.save()
|
||||||
if log:
|
if log:
|
||||||
log_event({'type': 'user_activated',
|
log_event({'type': 'user_activated',
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ from zephyr.decorator import asynchronous, require_post, \
|
|||||||
from zephyr.lib.query import last_n
|
from zephyr.lib.query import last_n
|
||||||
from zephyr.lib.avatar import gravatar_hash
|
from zephyr.lib.avatar import gravatar_hash
|
||||||
from zephyr.lib.response import json_success, json_error
|
from zephyr.lib.response import json_success, json_error
|
||||||
|
from zephyr.lib.time import timestamp_to_datetime
|
||||||
|
|
||||||
from confirmation.models import Confirmation
|
from confirmation.models import Confirmation
|
||||||
|
|
||||||
@@ -690,7 +691,7 @@ def send_message_backend(request, user_profile, client,
|
|||||||
message.subject = subject_name
|
message.subject = subject_name
|
||||||
if forged:
|
if forged:
|
||||||
# Forged messages come with a timestamp
|
# Forged messages come with a timestamp
|
||||||
message.pub_date = datetime.datetime.utcfromtimestamp(float(request.POST['time'])).replace(tzinfo=utc)
|
message.pub_date = timestamp_to_datetime(request.POST['time'])
|
||||||
else:
|
else:
|
||||||
message.pub_date = now()
|
message.pub_date = now()
|
||||||
message.sending_client = client
|
message.sending_client = client
|
||||||
|
|||||||
Reference in New Issue
Block a user