mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-19 16:03:00 +00:00
allow isoformat(None)
simplifies "if timestamp is None" cases when we are just using it to serialize nullable timestamps to JSON
This commit is contained in:
@@ -99,14 +99,9 @@ class APIHandler(BaseHandler):
|
|||||||
|
|
||||||
def server_model(self, spawner):
|
def server_model(self, spawner):
|
||||||
"""Get the JSON model for a Spawner"""
|
"""Get the JSON model for a Spawner"""
|
||||||
last_activity = spawner.orm_spawner.last_activity
|
|
||||||
# don't call isoformat if last_activity is None
|
|
||||||
if last_activity:
|
|
||||||
last_activity = isoformat(last_activity)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'name': spawner.name,
|
'name': spawner.name,
|
||||||
'last_activity': last_activity,
|
'last_activity': isoformat(spawner.orm_spawner.last_activity),
|
||||||
'started': isoformat(spawner.orm_spawner.started),
|
'started': isoformat(spawner.orm_spawner.started),
|
||||||
'pending': spawner.pending,
|
'pending': spawner.pending,
|
||||||
'url': url_path_join(spawner.user.url, spawner.name, '/'),
|
'url': url_path_join(spawner.user.url, spawner.name, '/'),
|
||||||
@@ -118,12 +113,6 @@ class APIHandler(BaseHandler):
|
|||||||
if isinstance(user, orm.User):
|
if isinstance(user, orm.User):
|
||||||
user = self.users[user.id]
|
user = self.users[user.id]
|
||||||
|
|
||||||
|
|
||||||
last_activity = user.last_activity
|
|
||||||
# don't call isoformat if last_activity is None
|
|
||||||
if last_activity:
|
|
||||||
last_activity = isoformat(last_activity)
|
|
||||||
|
|
||||||
model = {
|
model = {
|
||||||
'kind': 'user',
|
'kind': 'user',
|
||||||
'name': user.name,
|
'name': user.name,
|
||||||
@@ -133,8 +122,8 @@ class APIHandler(BaseHandler):
|
|||||||
'progress_url': user.spawner._progress_url if user.active else None,
|
'progress_url': user.spawner._progress_url if user.active else None,
|
||||||
'pending': None,
|
'pending': None,
|
||||||
'created': isoformat(user.created),
|
'created': isoformat(user.created),
|
||||||
'last_activity': last_activity,
|
|
||||||
'started': None,
|
'started': None,
|
||||||
|
'last_activity': isoformat(user.last_activity),
|
||||||
}
|
}
|
||||||
if '' in user.spawners:
|
if '' in user.spawners:
|
||||||
server_model = self.server_model(user.spawners[''])
|
server_model = self.server_model(user.spawners[''])
|
||||||
|
@@ -45,6 +45,10 @@ def isoformat(dt):
|
|||||||
|
|
||||||
Naïve datetime objects are assumed to be UTC
|
Naïve datetime objects are assumed to be UTC
|
||||||
"""
|
"""
|
||||||
|
# allow null timestamps to remain None without
|
||||||
|
# having to check if isoformat should be called
|
||||||
|
if dt is None:
|
||||||
|
return None
|
||||||
if dt.tzinfo:
|
if dt.tzinfo:
|
||||||
dt = dt.astimezone(timezone.utc).replace(tzinfo=None)
|
dt = dt.astimezone(timezone.utc).replace(tzinfo=None)
|
||||||
return dt.isoformat() + 'Z'
|
return dt.isoformat() + 'Z'
|
||||||
|
Reference in New Issue
Block a user