mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
Make Fleet-up datetimes timezone aware (#856)
Additionally fix logger depreciation warnings
This commit is contained in:
parent
8028660a8f
commit
049c1c66aa
@ -1,6 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
from django.utils import timezone
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -17,6 +18,8 @@ class FleetUpManager:
|
|||||||
GROUP_ID = settings.FLEETUP_GROUP_ID
|
GROUP_ID = settings.FLEETUP_GROUP_ID
|
||||||
BASE_URL = "http://api.fleet-up.com/Api.svc/{}/{}/{}".format(APP_KEY, USER_ID, API_ID)
|
BASE_URL = "http://api.fleet-up.com/Api.svc/{}/{}/{}".format(APP_KEY, USER_ID, API_ID)
|
||||||
|
|
||||||
|
TZ = timezone.utc
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -60,7 +63,7 @@ class FleetUpManager:
|
|||||||
cache.set(cache_key, json, cls._cache_until_seconds(json['CachedUntilUTC']))
|
cache.set(cache_key, json, cls._cache_until_seconds(json['CachedUntilUTC']))
|
||||||
return json
|
return json
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
logger.warn("Can't connect to Fleet-Up API, is it offline?!")
|
logger.warning("Can't connect to Fleet-Up API, is it offline?!")
|
||||||
except requests.HTTPError:
|
except requests.HTTPError:
|
||||||
logger.exception("Error accessing Fleetup API")
|
logger.exception("Error accessing Fleetup API")
|
||||||
return None
|
return None
|
||||||
@ -87,8 +90,10 @@ class FleetUpManager:
|
|||||||
if foperations is None:
|
if foperations is None:
|
||||||
return None
|
return None
|
||||||
return {row["StartString"]: {"subject": row["Subject"],
|
return {row["StartString"]: {"subject": row["Subject"],
|
||||||
"start": datetime.strptime(row["StartString"], "%Y-%m-%d %H:%M:%S"),
|
"start": timezone.make_aware(
|
||||||
"end": datetime.strptime(row["EndString"], "%Y-%m-%d %H:%M:%S"),
|
datetime.strptime(row["StartString"], "%Y-%m-%d %H:%M:%S"), cls.TZ),
|
||||||
|
"end": timezone.make_aware(
|
||||||
|
datetime.strptime(row["EndString"], "%Y-%m-%d %H:%M:%S"), cls.TZ),
|
||||||
"operation_id": row["OperationId"],
|
"operation_id": row["OperationId"],
|
||||||
"location": row["Location"],
|
"location": row["Location"],
|
||||||
"location_info": row["LocationInfo"],
|
"location_info": row["LocationInfo"],
|
||||||
@ -109,9 +114,9 @@ class FleetUpManager:
|
|||||||
"owner": row["Owner"],
|
"owner": row["Owner"],
|
||||||
"type": row["Type"],
|
"type": row["Type"],
|
||||||
"timer_type": row["TimerType"],
|
"timer_type": row["TimerType"],
|
||||||
"expires": (datetime.strptime(row["ExpiresString"], "%Y-%m-%d %H:%M:%S")),
|
"expires": timezone.make_aware(
|
||||||
|
datetime.strptime(row["ExpiresString"], "%Y-%m-%d %H:%M:%S"), cls.TZ),
|
||||||
"notes": row["Notes"]} for row in ftimers["Data"]}
|
"notes": row["Notes"]} for row in ftimers["Data"]}
|
||||||
return {}
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fleetup_doctrines(cls):
|
def get_fleetup_doctrines(cls):
|
||||||
@ -143,9 +148,10 @@ class FleetUpManager:
|
|||||||
"estimated": row["EstPrice"],
|
"estimated": row["EstPrice"],
|
||||||
"faction": row["Faction"],
|
"faction": row["Faction"],
|
||||||
"categories": row["Categories"],
|
"categories": row["Categories"],
|
||||||
"last_update": (
|
"last_update":
|
||||||
datetime.strptime(row["LastUpdatedString"], "%Y-%m-%d %H:%M:%S"))} for row in
|
timezone.make_aware(
|
||||||
ffittings["Data"]}
|
datetime.strptime(row["LastUpdatedString"], "%Y-%m-%d %H:%M:%S"), cls.TZ)}
|
||||||
|
for row in ffittings["Data"]}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fleetup_fitting(cls, fittingnumber):
|
def get_fleetup_fitting(cls, fittingnumber):
|
||||||
@ -156,7 +162,7 @@ class FleetUpManager:
|
|||||||
return None
|
return None
|
||||||
return {"fitting_data": ffitting["Data"]}
|
return {"fitting_data": ffitting["Data"]}
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.warn("Failed to retrieve fleetup fitting number %s" % fittingnumber)
|
logger.warning("Failed to retrieve fleetup fitting number %s" % fittingnumber)
|
||||||
return {"fitting_data": {}}
|
return {"fitting_data": {}}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -180,5 +186,5 @@ class FleetUpManager:
|
|||||||
return None
|
return None
|
||||||
return {"fitting_eft": ffittingeft["Data"]["FittingData"]}
|
return {"fitting_eft": ffittingeft["Data"]["FittingData"]}
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.warn("Fleetup fitting eft not found for fitting number %s" % fittingnumber)
|
logger.warning("Fleetup fitting eft not found for fitting number %s" % fittingnumber)
|
||||||
return {"fitting_eft": {}}
|
return {"fitting_eft": {}}
|
||||||
|
@ -12,6 +12,7 @@ import json
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from django.utils.timezone import make_aware, utc
|
||||||
|
|
||||||
from fleetup.managers import FleetUpManager
|
from fleetup.managers import FleetUpManager
|
||||||
|
|
||||||
@ -148,8 +149,8 @@ class FleetupManagerTestCase(TestCase):
|
|||||||
expected_result = {
|
expected_result = {
|
||||||
'2017-05-06 11:11:11': {
|
'2017-05-06 11:11:11': {
|
||||||
'subject': 'test_operation',
|
'subject': 'test_operation',
|
||||||
'start': datetime.datetime(2017, 5, 6, 11, 11, 11),
|
'start': make_aware(datetime.datetime(2017, 5, 6, 11, 11, 11), utc),
|
||||||
'end': datetime.datetime(2017, 5, 6, 12, 12, 12),
|
'end': make_aware(datetime.datetime(2017, 5, 6, 12, 12, 12), utc),
|
||||||
'operation_id': 1234,
|
'operation_id': 1234,
|
||||||
'location': 'Jita',
|
'location': 'Jita',
|
||||||
'location_info': '4-4',
|
'location_info': '4-4',
|
||||||
@ -208,7 +209,7 @@ class FleetupManagerTestCase(TestCase):
|
|||||||
FleetUpManager.GROUP_ID)
|
FleetUpManager.GROUP_ID)
|
||||||
expected_result = {
|
expected_result = {
|
||||||
'2017-05-06 11:11:11': {
|
'2017-05-06 11:11:11': {
|
||||||
'expires': datetime.datetime(2017, 5, 6, 11, 11, 11),
|
'expires': make_aware(datetime.datetime(2017, 5, 6, 11, 11, 11), utc),
|
||||||
'solarsystem': 'Jita',
|
'solarsystem': 'Jita',
|
||||||
'planet': '4',
|
'planet': '4',
|
||||||
'moon': '4',
|
'moon': '4',
|
||||||
@ -361,7 +362,7 @@ class FleetupManagerTestCase(TestCase):
|
|||||||
'estimated': 500000000,
|
'estimated': 500000000,
|
||||||
'faction': 'Amarr',
|
'faction': 'Amarr',
|
||||||
'categories': ["Armor", "Laser"],
|
'categories': ["Armor", "Laser"],
|
||||||
'last_update': datetime.datetime(2017, 5, 6, 11, 11, 11)
|
'last_update': make_aware(datetime.datetime(2017, 5, 6, 11, 11, 11), utc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.assertDictEqual(expected_result, result)
|
self.assertDictEqual(expected_result, result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user