ソースを参照

fix(api): rework timezone stuff, closes #122

In #122, I suggested that timezone support is unnecessary. After some
investigation, it turns out that Django enables timezone support by
default to set up time normalization to UTC. While one can remove
that and always use UTC manually, that's not the recommended way. [1]
All in all, that means things don't really need to be changed.

https://docs.djangoproject.com/en/2.1/topics/i18n/timezones/#naive-datetime-objects
Peter Thomassen 6 年 前
コミット
11a23da1d2
2 ファイル変更3 行追加4 行削除
  1. 1 1
      api/api/settings.py
  2. 2 3
      api/desecapi/models.py

+ 1 - 1
api/api/settings.py

@@ -71,11 +71,11 @@ DATABASES = {
 
 }
 
+# This is necessary because the default is America/Chicago
 TIME_ZONE = 'UTC'
 
 USE_TZ = True
 
-
 REST_FRAMEWORK = {
     'DEFAULT_AUTHENTICATION_CLASSES': (
         'desecapi.authentication.TokenAuthentication',

+ 2 - 3
api/desecapi/models.py

@@ -8,8 +8,7 @@ import datetime, uuid
 from django.core.validators import MinValueValidator
 from collections import OrderedDict
 import rest_framework.authtoken.models
-from time import time
-import random
+import time, random
 from os import urandom
 from base64 import b64encode
 
@@ -405,7 +404,7 @@ def get_default_value_due():
 
 
 def get_default_value_mref():
-    return "ONDON" + str((timezone.now() - timezone.datetime(1970,1,1,tzinfo=timezone.utc)).total_seconds())
+    return "ONDON" + str(time.time())
 
 
 class Donation(models.Model):