Changed datetime setter to use utils.timezone instead of naive datetime stamps, as per #728.
This commit is contained in:
parent
b0c71ee924
commit
3ebc55da82
7 changed files with 20 additions and 14 deletions
|
|
@ -19,8 +19,8 @@ ChannelConnect object (this object is necessary to easily
|
||||||
be able to delete connections on the fly).
|
be able to delete connections on the fly).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.utils import timezone
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from evennia.typeclasses.models import TypedObject
|
from evennia.typeclasses.models import TypedObject
|
||||||
from evennia.utils.idmapper.models import SharedMemoryModel
|
from evennia.utils.idmapper.models import SharedMemoryModel
|
||||||
|
|
@ -309,7 +309,7 @@ class TempMsg(object):
|
||||||
self.message = message
|
self.message = message
|
||||||
self.lock_storage = lockstring
|
self.lock_storage = lockstring
|
||||||
self.hide_from = hide_from and make_iter(hide_from) or []
|
self.hide_from = hide_from and make_iter(hide_from) or []
|
||||||
self.date_sent = datetime.now()
|
self.date_sent = timezone.now()
|
||||||
|
|
||||||
@lazy_property
|
@lazy_property
|
||||||
def locks(self):
|
def locks(self):
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ The managers for the custom Player object and permissions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
from django.utils import timezone
|
||||||
from django.contrib.auth.models import UserManager
|
from django.contrib.auth.models import UserManager
|
||||||
#from functools import update_wrapper
|
#from functools import update_wrapper
|
||||||
from evennia.typeclasses.managers import (returns_typeclass_list, returns_typeclass,
|
from evennia.typeclasses.managers import (returns_typeclass_list, returns_typeclass,
|
||||||
|
|
@ -59,7 +60,7 @@ class PlayerDBManager(TypedObjectManager, UserManager):
|
||||||
Returns a QuerySet containing the player User accounts that have been
|
Returns a QuerySet containing the player User accounts that have been
|
||||||
connected within the last <days> days.
|
connected within the last <days> days.
|
||||||
"""
|
"""
|
||||||
end_date = datetime.datetime.now()
|
end_date = timezone.now()
|
||||||
tdelta = datetime.timedelta(days)
|
tdelta = datetime.timedelta(days)
|
||||||
start_date = end_date - tdelta
|
start_date = end_date - tdelta
|
||||||
return self.filter(date_joined__range=(start_date, end_date))
|
return self.filter(date_joined__range=(start_date, end_date))
|
||||||
|
|
@ -72,7 +73,7 @@ class PlayerDBManager(TypedObjectManager, UserManager):
|
||||||
|
|
||||||
days - number of days backwards to check
|
days - number of days backwards to check
|
||||||
"""
|
"""
|
||||||
end_date = datetime.datetime.now()
|
end_date = timezone.now()
|
||||||
tdelta = datetime.timedelta(days)
|
tdelta = datetime.timedelta(days)
|
||||||
start_date = end_date - tdelta
|
start_date = end_date - tdelta
|
||||||
return self.filter(last_login__range=(
|
return self.filter(last_login__range=(
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ instead for most things).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.utils import timezone
|
||||||
from evennia.typeclasses.models import TypeclassBase
|
from evennia.typeclasses.models import TypeclassBase
|
||||||
from evennia.players.manager import PlayerManager
|
from evennia.players.manager import PlayerManager
|
||||||
from evennia.players.models import PlayerDB
|
from evennia.players.models import PlayerDB
|
||||||
|
|
@ -558,7 +558,7 @@ class DefaultPlayer(PlayerDB):
|
||||||
_CONNECT_CHANNEL = ChannelDB.objects.filter(db_key=settings.DEFAULT_CHANNELS[1]["key"])[0]
|
_CONNECT_CHANNEL = ChannelDB.objects.filter(db_key=settings.DEFAULT_CHANNELS[1]["key"])[0]
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log_trace()
|
logger.log_trace()
|
||||||
now = datetime.datetime.now()
|
now = timezone.now()
|
||||||
now = "%02i-%02i-%02i(%02i:%02i)" % (now.year, now.month,
|
now = "%02i-%02i-%02i(%02i:%02i)" % (now.year, now.month,
|
||||||
now.day, now.hour, now.minute)
|
now.day, now.hour, now.minute)
|
||||||
if _CONNECT_CHANNEL:
|
if _CONNECT_CHANNEL:
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ are stored on the Portal side)
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from time import time
|
from time import time
|
||||||
from datetime import datetime
|
from django.utils import timezone
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from evennia.comms.models import ChannelDB
|
from evennia.comms.models import ChannelDB
|
||||||
from evennia.utils import logger
|
from evennia.utils import logger
|
||||||
|
|
@ -106,7 +106,7 @@ class ServerSession(Session):
|
||||||
self.cmdset_storage = settings.CMDSET_SESSION
|
self.cmdset_storage = settings.CMDSET_SESSION
|
||||||
|
|
||||||
# Update account's last login time.
|
# Update account's last login time.
|
||||||
self.player.last_login = datetime.now()
|
self.player.last_login = timezone.now()
|
||||||
self.player.save()
|
self.player.save()
|
||||||
|
|
||||||
# add the session-level cmdset
|
# add the session-level cmdset
|
||||||
|
|
@ -122,7 +122,7 @@ class ServerSession(Session):
|
||||||
if self.puppet:
|
if self.puppet:
|
||||||
player.unpuppet_object(sessid)
|
player.unpuppet_object(sessid)
|
||||||
uaccount = player
|
uaccount = player
|
||||||
uaccount.last_login = datetime.now()
|
uaccount.last_login = timezone.now()
|
||||||
uaccount.save()
|
uaccount.save()
|
||||||
# calling player hook
|
# calling player hook
|
||||||
player.at_disconnect()
|
player.at_disconnect()
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,8 @@ CYCLE_LOGFILES = True
|
||||||
# Local time zone for this installation. All choices can be found here:
|
# Local time zone for this installation. All choices can be found here:
|
||||||
# http://www.postgresql.org/docs/8.0/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
|
# http://www.postgresql.org/docs/8.0/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
# Activate time zone in datetimes
|
||||||
|
USE_TZ = True
|
||||||
# Authentication backends. This is the code used to authenticate a user.
|
# Authentication backends. This is the code used to authenticate a user.
|
||||||
AUTHENTICATION_BACKENDS = (
|
AUTHENTICATION_BACKENDS = (
|
||||||
'evennia.web.utils.backends.CaseInsensitiveModelBackend',)
|
'evennia.web.utils.backends.CaseInsensitiveModelBackend',)
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,13 @@ log_typemsg(). This is for historical, back-compatible reasons.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet.threads import deferToThread
|
from twisted.internet.threads import deferToThread
|
||||||
|
|
||||||
|
|
||||||
_LOGDIR = None
|
_LOGDIR = None
|
||||||
|
_TIMEZONE = None
|
||||||
|
|
||||||
def log_trace(errmsg=None):
|
def log_trace(errmsg=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -114,15 +115,17 @@ def log_file(msg, filename="game.log"):
|
||||||
'game.log'. All logs will appear in the logs directory and log
|
'game.log'. All logs will appear in the logs directory and log
|
||||||
entries will start on new lines following datetime info.
|
entries will start on new lines following datetime info.
|
||||||
"""
|
"""
|
||||||
global LOG_FILE_HANDLES, _LOGDIR
|
global LOG_FILE_HANDLES, _LOGDIR, _TIMEZONE
|
||||||
|
|
||||||
if not _LOGDIR:
|
if not _LOGDIR:
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
_LOGDIR = settings.LOG_DIR
|
_LOGDIR = settings.LOG_DIR
|
||||||
|
if not _TIMEZONE:
|
||||||
|
from django.utils import timezone as _TIMEZONE
|
||||||
|
|
||||||
def callback(filehandle, msg):
|
def callback(filehandle, msg):
|
||||||
"Writing to file and flushing result"
|
"Writing to file and flushing result"
|
||||||
msg = "\n%s [-] %s" % (datetime.now(), msg.strip())
|
msg = "\n%s [-] %s" % (_TIMEZONE.now(), msg.strip())
|
||||||
filehandle.write(msg)
|
filehandle.write(msg)
|
||||||
# since we don't close the handle, we need to flush
|
# since we don't close the handle, we need to flush
|
||||||
# manually or log file won't be written to until the
|
# manually or log file won't be written to until the
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import types
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
import textwrap
|
import textwrap
|
||||||
import datetime
|
|
||||||
import random
|
import random
|
||||||
import traceback
|
import traceback
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
|
@ -21,6 +20,7 @@ from inspect import ismodule, trace
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from twisted.internet import threads, defer, reactor
|
from twisted.internet import threads, defer, reactor
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
|
|
@ -279,7 +279,7 @@ def datetime_format(dtobj):
|
||||||
|
|
||||||
year, month, day = dtobj.year, dtobj.month, dtobj.day
|
year, month, day = dtobj.year, dtobj.month, dtobj.day
|
||||||
hour, minute, second = dtobj.hour, dtobj.minute, dtobj.second
|
hour, minute, second = dtobj.hour, dtobj.minute, dtobj.second
|
||||||
now = datetime.datetime.now()
|
now = timezone.now()
|
||||||
|
|
||||||
if year < now.year:
|
if year < now.year:
|
||||||
# another year
|
# another year
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue