diff --git a/README.rst b/README.rst index 2f2a59498..c4fa69218 100644 --- a/README.rst +++ b/README.rst @@ -1,3 +1,5 @@ +.. nodoctest + .. This README does not explain how to handle installation into versions of Sage which do not yet ship the flask notebook, as the packaging of the notebook's dependencies is still in flux. Please see diff --git a/flask_version/authentication.py b/flask_version/authentication.py index 2b7b6e205..0b4b153ca 100644 --- a/flask_version/authentication.py +++ b/flask_version/authentication.py @@ -21,7 +21,6 @@ def lookup_current_user(): def login(template_dict={}): from sagenb.misc.misc import SAGE_VERSION template_dict.update({'accounts': g.notebook.user_manager().get_accounts(), - 'default_user': g.notebook.user_manager().default_user(), 'recovery': g.notebook.conf()['email'], 'next': request.values.get('next', ''), 'sage_version': SAGE_VERSION, @@ -94,6 +93,8 @@ def logout(): @authentication.route('/register', methods = ['GET','POST']) @with_lock def register(): + if not g.notebook.user_manager().get_accounts(): + return redirect(url_for('base.index')) from sagenb.notebook.misc import is_valid_username, is_valid_password, \ is_valid_email, do_passwords_match from sagenb.notebook.challenge import challenge @@ -243,7 +244,6 @@ def register(): # Go to the login page. from sagenb.misc.misc import SAGE_VERSION template_dict = {'accounts': g.notebook.user_manager().get_accounts(), - 'default_user': g.notebook.user_manager().default_user(), 'welcome_user': username, 'recovery': g.notebook.conf()['email'], 'sage_version': SAGE_VERSION} diff --git a/flask_version/base.py b/flask_version/base.py index 0920e7677..fe0400b33 100755 --- a/flask_version/base.py +++ b/flask_version/base.py @@ -22,23 +22,23 @@ def __init__(self, *args, **kwds): self.root_path = SAGENB_ROOT - self.add_static_path('/css', os.path.join(DATA, "sage", "css")) + self.add_static_path('/css', os.path.join(DATA, "sage", "css")) self.add_static_path('/images', os.path.join(DATA, "sage", "images")) self.add_static_path('/javascript', DATA) self.add_static_path('/static', DATA) self.add_static_path('/java', DATA) self.add_static_path('/java/jmol', os.path.join(os.environ["SAGE_ROOT"],"local","share","jmol")) - import mimetypes + import mimetypes mimetypes.add_type('text/plain','.jmol') - + ####### # Doc # ####### #These "should" be in doc.py DOC = os.path.join(SAGE_DOC, 'output', 'html', 'en') self.add_static_path('/pdf', os.path.join(SAGE_DOC, 'output', 'pdf')) - self.add_static_path('/doc/static', DOC) + self.add_static_path('/doc/static', DOC) #self.add_static_path('/doc/static/reference', os.path.join(SAGE_DOC, 'reference')) def create_jinja_environment(self): @@ -108,14 +108,14 @@ def index(): response.set_cookie('nb_session_%s'%g.notebook.port) response.set_cookie('cookie_test_%s'%g.notebook.port, expires=1) return response - + from authentication import login - + if current_app.startup_token is not None and 'startup_token' in request.args: if request.args['startup_token'] == current_app.startup_token: - g.username = session['username'] = 'admin' + g.username = session['username'] = 'admin' session.modified = True - current_app.startup_token = -1 + current_app.startup_token = None return index() return login() @@ -192,7 +192,7 @@ def keyboard_js(browser_os): ############### @base.route('/css/main.css') def main_css(): - from sagenb.notebook.css import css + from sagenb.notebook.css import css data,datahash = css() if request.environ.get('HTTP_IF_NONE_MATCH', None) == datahash: response = make_response('',304) @@ -260,7 +260,7 @@ def create_or_login(resp): session['username'] = g.username = username session.modified = True except KeyError: - session['openid_response'] = resp + session['openid_response'] = resp session.modified = True return redirect(url_for('set_profiles')) return redirect(request.values.get('next', url_for('base.index'))) @@ -272,7 +272,7 @@ def set_profiles(): from sagenb.notebook.challenge import challenge - + show_challenge=g.notebook.conf()['challenge'] if show_challenge: chal = challenge(g.notebook.conf(), @@ -326,14 +326,14 @@ def set_profiles(): if not is_valid_username(username): parse_dict['username_invalid'] = True - raise ValueError + raise ValueError if g.notebook.user_manager().user_exists(username): parse_dict['username_taken'] = True - raise ValueError + raise ValueError if not is_valid_email(request.form.get('email')): parse_dict['email_invalid'] = True raise ValueError - try: + try: new_user = User(username, '', email = resp.email, account_type='user') g.notebook.user_manager().add_user_object(new_user) except ValueError: @@ -357,7 +357,7 @@ def set_profiles(): def init_updates(): global save_interval, idle_interval, last_save_time, last_idle_time from sagenb.misc.misc import walltime - + save_interval = notebook.conf()['save_interval'] idle_interval = notebook.conf()['idle_check_interval'] last_save_time = walltime() @@ -410,7 +410,7 @@ def create_app(path_to_notebook, *args, **kwds): """ global notebook startup_token = kwds.pop('startup_token', None) - + ############# # OLD STUFF # ############# @@ -436,7 +436,7 @@ def set_notebook_object(): #################################### babel = Babel(app, default_locale=notebook.conf()['default_language'], default_timezone='UTC', - date_formats=None, configure_jinja=True) + date_formats=None, configure_jinja=True) ######################## # Register the modules # @@ -444,7 +444,7 @@ def set_notebook_object(): app.register_blueprint(base) from worksheet_listing import worksheet_listing - app.register_blueprint(worksheet_listing) + app.register_blueprint(worksheet_listing) from admin import admin app.register_blueprint(admin) @@ -473,10 +473,10 @@ def autoindex(path='.'): if os.path.isfile(filename): from cgi import escape src = escape(open(filename).read().decode('utf-8','ignore')) - if (os.path.splitext(filename)[1] in + if (os.path.splitext(filename)[1] in ['.py','.c','.cc','.h','.hh','.pyx','.pxd']): return render_template(os.path.join('html', 'source_code.html'), - src_filename=path, + src_filename=path, src=src, username = g.username) return src return idx.render_autoindex(path) diff --git a/flask_version/decorators.py b/flask_version/decorators.py index 00a4b3282..7ef65799d 100644 --- a/flask_version/decorators.py +++ b/flask_version/decorators.py @@ -10,18 +10,13 @@ def login_required(f): @wraps(f) def wrapper(*args, **kwds): if 'username' not in session: - if not g.notebook.conf()['require_login']: - g.username = session['username'] = 'admin' - session.modified = True + #XXX: Do we have to specify this for the publised + #worksheets here? + if request.path.startswith('/home/_sage_/'): + g.username = 'guest' return f(*args, **kwds) else: - #XXX: Do we have to specify this for the publised - #worksheets here? - if request.path.startswith('/home/_sage_/'): - g.username = 'guest' - return f(*args, **kwds) - else: - return redirect(url_for('base.index', next=request.url)) + return redirect(url_for('base.index', next=request.url)) else: g.username = session['username'] return f(*args, **kwds) diff --git a/flask_version/settings.py b/flask_version/settings.py index 00057d66e..65b2a6c25 100644 --- a/flask_version/settings.py +++ b/flask_version/settings.py @@ -71,6 +71,7 @@ def settings_page(): td['email_confirmed'] = 'Not confirmed' td['admin'] = nu.is_admin() + td['form_email'] = nu.may_change_email() return render_template(os.path.join('html', 'settings', 'account_settings.html'), **td) diff --git a/flask_version/worksheet_listing.py b/flask_version/worksheet_listing.py index f9493bf4b..32c68e7c5 100644 --- a/flask_version/worksheet_listing.py +++ b/flask_version/worksheet_listing.py @@ -31,18 +31,11 @@ def render_worksheet_list(args, pub, username): from sagenb.notebook.notebook import sort_worksheet_list from sagenb.misc.misc import unicode_str, SAGE_VERSION - from sagenb.notebook.pagination import Paginator - + typ = args['typ'] if 'typ' in args else 'active' search = unicode_str(args['search']) if 'search' in args else None sort = args['sort'] if 'sort' in args else 'last_edited' reverse = (args['reverse'] == 'True') if 'reverse' in args else False - page = 1 - if 'page' in args: - try: - page = int(args['page']) - except ValueError as E: - print "Error improper page input", E try: if not pub: @@ -56,19 +49,6 @@ def render_worksheet_list(args, pub, username): print "Error displaying worksheet listing: ", E return current_app.message(_("Error displaying worksheet listing.")) - paginator = Paginator(worksheets, 25) #25 is number of items per page, change this value to change the number of objects per page. - - try: - pages = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - pages = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - pages = paginator.page(paginator.num_pages) - - worksheets = pages.object_list - worksheet_filenames = [x.filename() for x in worksheets] if pub and (not username or username == tuple([])): diff --git a/sagenb/data/sage/html/login.html b/sagenb/data/sage/html/login.html index e090ee9a4..c16a1b371 100644 --- a/sagenb/data/sage/html/login.html +++ b/sagenb/data/sage/html/login.html @@ -64,7 +64,7 @@