Improve three-state read-only logic.

This commit is contained in:
Stefan van der Walt 2011-12-01 13:41:47 -08:00
parent 23ff0c2f88
commit 3bf57a7f5d
4 changed files with 25 additions and 12 deletions

View File

@ -137,17 +137,25 @@ class AuthenticatedHandler(RequestHandler):
if not self.application.password and not self.application.read_only:
user_id = 'anonymous'
return user_id
@property
def read_only(self):
if self.application.read_only:
"""Is the notebook read-only?
None -- notebook is read-only, but the user can log-in to edit
True -- notebook is read-only, no log-in available
False -- no read-only mode available, user must log in
"""
user = self.get_current_user()
if user and user != 'anonymous':
return False
elif self.application.read_only:
if self.application.password:
return self.get_current_user() is None
return None
else:
return True
else:
return False
@property
def ws_url(self):
"""websocket url matching the current request

View File

@ -25,7 +25,7 @@
<span id="login_widget">
{% if current_user and current_user != 'anonymous' %}
<button id="logout">Logout</button>
{% else %}
{% elif read_only is None %}
<button id="login">Login</button>
{% end %}
</span>

View File

@ -54,7 +54,7 @@
{% comment when appropriate until notebook.html is templated %}
{% if current_user and current_user != 'anonymous' %}
<button id="logout">Logout</button>
{% else %}
{% elif read_only is None %}
<button id="login">Login</button>
{% end %}
</span>

View File

@ -20,10 +20,15 @@ data-base-kernel-url={{base_kernel_url}}
{% block content_panel %}
<div id="content_toolbar">
<span id="drag_info" class="hidden">Drag files onto the list to import notebooks.</span>
<span id="notebooks_buttons">
<button id="new_notebook" class="hidden">New Notebook</button>
</span>
<span id="drag_info" class="hidden">Drag files onto the list to import
notebooks.</span>
{% if read_only == False %}
<span id="notebooks_buttons">
<button id="new_notebook" class="hidden">New Notebook</button>
</span>
{% end %}
</div>
<div id="notebook_list">
<div id="project_name"><h2>{{project}}</h2></div>