add User.running

as the one true way to check whether a user is running or not

User.running will be True if spawn or stop is pending.
This commit is contained in:
Min RK
2015-02-06 14:46:34 -08:00
parent 1fd139418a
commit b5eda9d785
4 changed files with 17 additions and 8 deletions

View File

@@ -17,7 +17,7 @@ class BaseUserHandler(APIHandler):
return { return {
'name': user.name, 'name': user.name,
'admin': user.admin, 'admin': user.admin,
'server': user.server.base_url if user.server and not (user.spawn_pending or user.stop_pending) else None, 'server': user.server.base_url if user.running and not (user.spawn_pending or user.stop_pending) else None,
'last_activity': user.last_activity.isoformat(), 'last_activity': user.last_activity.isoformat(),
} }
@@ -150,7 +150,7 @@ class UserServerAPIHandler(BaseUserHandler):
if user.stop_pending: if user.stop_pending:
self.set_status(202) self.set_status(202)
return return
if user.spawner is None: if not user.running:
raise web.HTTPError(400, "%s's server is not running" % name) raise web.HTTPError(400, "%s's server is not running" % name)
status = yield user.spawner.poll() status = yield user.spawner.poll()
if status is not None: if status is not None:
@@ -175,8 +175,8 @@ class UserAdminAccessAPIHandler(BaseUserHandler):
user = self.find_user(name) user = self.find_user(name)
if user is None: if user is None:
raise web.HTTPError(404) raise web.HTTPError(404)
if user.server is None: if not user.running:
raise web.HTTPError(400, "%s has no server running" % name) raise web.HTTPError(400, "%s's server is not running" % name)
self.set_server_cookie(user) self.set_server_cookie(user)

View File

@@ -267,6 +267,15 @@ class User(Base):
name=self.name, name=self.name,
) )
@property
def running(self):
"""property for whether a user has a running server"""
if self.spawner is None:
return False
if self.server is None:
return False
return True
def new_api_token(self): def new_api_token(self):
"""Create a new API token""" """Create a new API token"""
assert self.id is not None assert self.id is not None

View File

@@ -42,11 +42,11 @@
<td class="admin-col col-sm-2">{% if u.admin %}admin{% endif %}</td> <td class="admin-col col-sm-2">{% if u.admin %}admin{% endif %}</td>
<td class="time-col col-sm-3">{{u.last_activity.isoformat() + 'Z'}}</td> <td class="time-col col-sm-3">{{u.last_activity.isoformat() + 'Z'}}</td>
<td class="server-col col-sm-3 text-center"> <td class="server-col col-sm-3 text-center">
<span class="stop-server btn btn-xs btn-danger {% if not u.server %}hidden{% endif %}">stop server</span> <span class="stop-server btn btn-xs btn-danger {% if not u.running %}hidden{% endif %}">stop server</span>
{% if admin_access %} {% if admin_access %}
<span class="access-server btn btn-xs btn-success {% if not u.server %}hidden{% endif %}">access server</span> <span class="access-server btn btn-xs btn-success {% if not u.running %}hidden{% endif %}">access server</span>
{% endif %} {% endif %}
<span class="start-server btn btn-xs btn-success {% if u.server %}hidden{% endif %}">start server</span> <span class="start-server btn btn-xs btn-success {% if u.running %}hidden{% endif %}">start server</span>
</td> </td>
<td class="edit-col col-sm-2"> <td class="edit-col col-sm-2">
<span class="edit-user btn btn-xs btn-primary">edit</span> <span class="edit-user btn btn-xs btn-primary">edit</span>

View File

@@ -5,7 +5,7 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="text-center"> <div class="text-center">
{% if user.server %} {% if user.running %}
<a id="stop" class="btn btn-lg btn-danger">Stop My Server</a> <a id="stop" class="btn btn-lg btn-danger">Stop My Server</a>
{% endif %} {% endif %}
<a id="start" class="btn btn-lg btn-success" <a id="start" class="btn btn-lg btn-success"