Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #152 from ohanar/flask_version

Make flask_version a submodule of sagenb
  • Loading branch information...
commit 4c40f2ed87cf8e191dd439f1d352103e10419845 2 parents 64cc9cf + 6790641
Keshav Kini kini authored
8 flask_version/admin.py
View
@@ -4,7 +4,7 @@
from flask.ext.babel import Babel, gettext, ngettext, lazy_gettext
_ = gettext
-admin = Module('flask_version.admin')
+admin = Module('sagenb.flask_version.admin')
@admin.route('/users')
@admin.route('/users/reset/<reset>')
@@ -104,18 +104,18 @@ def notebook_settings():
updated = {}
if 'form' in request.values:
updated = g.notebook.conf().update_from_form(request.values)
-
+
#Make changes to the default language used
if 'default_language' in request.values:
from flask.ext.babel import refresh
refresh()
current_app.config['BABEL_DEFAULT_LOCALE'] = request.values['default_language']
-
+
template_dict = {}
template_dict['auto_table'] = g.notebook.conf().html_table(updated)
template_dict['admin'] = g.notebook.user_manager().user(g.username).is_admin()
template_dict['username'] = g.username
-
+
return render_template(os.path.join('html', 'settings', 'notebook_settings.html'),
**template_dict)
10 flask_version/authentication.py
View
@@ -5,7 +5,7 @@
from flask.ext.babel import gettext, ngettext, lazy_gettext
_ = gettext
-authentication = Module('flask_version.authentication')
+authentication = Module('sagenb.flask_version.authentication')
##################
# Authentication #
@@ -22,12 +22,12 @@ def login(template_dict={}):
from sagenb.misc.misc import SAGE_VERSION
template_dict.update({'accounts': g.notebook.user_manager().get_accounts(),
'recovery': g.notebook.conf()['email'],
- 'next': request.values.get('next', ''),
+ 'next': request.values.get('next', ''),
'sage_version': SAGE_VERSION,
'openid': g.notebook.conf()['openid'],
'username_error': False,
'password_error': False})
-
+
if request.method == 'POST':
username = request.form['email']
password = request.form['password']
@@ -56,7 +56,7 @@ def login(template_dict={}):
if U is None:
pass
- elif (is_valid_password(password, username) and
+ elif (is_valid_password(password, username) and
g.notebook.user_manager().check_password(username, password)):
if U.is_suspended():
#suspended
@@ -257,7 +257,7 @@ def confirm():
if not g.notebook.conf()['email']:
return current_app.message(_('The confirmation system is not active.'))
key = int(request.values.get('key', '-1'))
-
+
invalid_confirm_key = _("""\
<h1>Invalid confirmation key</h1>
<p>You are reporting a confirmation key that has not been assigned by this
16 flask_version/base.py
View
@@ -6,7 +6,11 @@
from decorators import global_lock
from flask.ext.autoindex import AutoIndex
-SRC = os.path.join(os.environ['SAGE_ROOT'], 'devel', 'sage', 'sage')
+try:
+ from sage.env import SAGE_SRC
+except ImportError:
+ SAGE_SRC = os.environ.get('SAGE_SRC', os.path.join(os.environ['SAGE_ROOT'], 'devel', 'sage'))
+SRC = os.path.join(SAGE_SRC, 'sage')
from flask.ext.openid import OpenID
from flask.ext.babel import Babel, gettext, ngettext, lazy_gettext, get_locale
from sagenb.misc.misc import SAGENB_ROOT, DATA, SAGE_DOC, translations_path
@@ -84,7 +88,7 @@ def message(self, msg, cont='/', username=None, **kwds):
return render_template(os.path.join('html', 'error_message.html'),
**template_dict)
-base = Module('flask_version.base')
+base = Module('sagenb.flask_version.base')
#############
# Main Page #
@@ -212,7 +216,7 @@ def help():
@base.route('/history')
@login_required
def history():
- return render_template(os.path.join('html', 'history.html'), username = g.username,
+ return render_template(os.path.join('html', 'history.html'), username = g.username,
text = g.notebook.user_history_text(g.username), actions = False)
@base.route('/live_history')
@@ -285,7 +289,7 @@ def set_profiles():
if show_challenge:
template_dict['challenge_html'] = chal.html()
- return render_template('html/accounts/openid_profile.html', resp=openid_resp,
+ return render_template('html/accounts/openid_profile.html', resp=openid_resp,
challenge=show_challenge, **template_dict)
else:
return redirect(url_for('base.index'))
@@ -329,7 +333,7 @@ def set_profiles():
parse_dict['email_invalid'] = True
raise ValueError
try:
- new_user = User(username, '', email = resp.email, account_type='user')
+ new_user = User(username, '', email = resp.email, account_type='user')
g.notebook.user_manager().add_user_object(new_user)
except ValueError:
parse_dict['creation_error'] = True
@@ -338,7 +342,7 @@ def set_profiles():
session['username'] = g.username = username
session.modified = True
except ValueError:
- return render_template('html/accounts/openid_profile.html', **parse_dict)
+ return render_template('html/accounts/openid_profile.html', **parse_dict)
return redirect(url_for('base.index'))
4 flask_version/doc.py
View
@@ -17,9 +17,9 @@
from flask import Module, url_for, render_template, request, session, redirect, g, current_app
from decorators import login_required, guest_or_login_required
-doc = Module('flask_version.doc')
+doc = Module('sagenb.flask_version.doc')
-from sagenb.misc.misc import SAGE_DOC
+from sagenb.misc.misc import SAGE_DOC
DOC = os.path.join(SAGE_DOC, 'output', 'html', 'en')
################
2  flask_version/settings.py
View
@@ -3,7 +3,7 @@
from flask import Module, url_for, render_template, request, session, redirect, g, current_app
from decorators import login_required, with_lock
-settings = Module('flask_version.settings')
+settings = Module('sagenb.flask_version.settings')
@settings.route('/settings', methods = ['GET','POST'])
@login_required
64 flask_version/worksheet.py
View
@@ -9,13 +9,13 @@
from sagenb.notebook.interact import INTERACT_UPDATE_PREFIX
from sagenb.notebook.misc import encode_response
-ws = Module('flask_version.worksheet')
+ws = Module('sagenb.flask_version.worksheet')
worksheet_locks = defaultdict(threading.Lock)
def worksheet_view(f):
"""
The `username` in the wrapper function is the username in the URL to the worksheet, which normally
- is the owner of the worksheet. Don't confuse this with `g.username`, the actual username of the
+ is the owner of the worksheet. Don't confuse this with `g.username`, the actual username of the
user looking at the worksheet.
"""
@login_required
@@ -26,7 +26,7 @@ def wrapper(username, id, **kwds):
worksheet = kwds['worksheet'] = g.notebook.get_worksheet_with_filename(worksheet_filename)
except KeyError:
return current_app.message(_("You do not have permission to access this worksheet"))
-
+
with worksheet_locks[worksheet]:
owner = worksheet.owner()
@@ -58,7 +58,7 @@ def url_for_worksheet(worksheet):
def get_cell_id():
"""
Returns the cell ID from the request.
-
+
We cast the incoming cell ID to an integer, if it's possible.
Otherwise, we treat it as a string.
"""
@@ -103,7 +103,7 @@ def worksheet(username, id, worksheet=None):
def worksheet_command(target, **route_kwds):
if 'methods' not in route_kwds:
route_kwds['methods'] = ['GET', 'POST']
-
+
def decorator(f):
@ws.route('/home/<username>/<id>/' + target, **route_kwds)
@worksheet_view
@@ -130,7 +130,7 @@ def wrapper(*args, **kwds):
worksheet = kwds.pop('worksheet', None)
if worksheet is not None:
args = (worksheet,) + args
-
+
return f(*args, **kwds)
#This function shares some functionality with url_for_worksheet.
@@ -141,10 +141,10 @@ def wc_url_for(worksheet, *args, **kwds):
return url_for(f.__name__, *args, **kwds)
wrapper.url_for = wc_url_for
-
+
return wrapper
return decorator
-
+
@worksheet_command('rename')
def worksheet_rename(worksheet):
@@ -194,7 +194,7 @@ def worksheet_save_snapshot(worksheet):
@worksheet_command('save_and_quit')
def worksheet_save_and_quit(worksheet):
- """Save a snapshot of a worksheet then quit it. """
+ """Save a snapshot of a worksheet then quit it. """
worksheet.save_snapshot(g.username)
worksheet.quit()
return 'saved'
@@ -266,7 +266,7 @@ def worksheet_new_cell_before(worksheet):
input = unicode_str(request.values.get('input', ''))
cell = worksheet.new_cell_before(id, input=input)
worksheet.increase_state_number()
-
+
r['new_id'] = cell.id()
r['new_html'] = cell.html(div_wrap=False)
@@ -280,7 +280,7 @@ def worksheet_new_text_cell_before(worksheet):
input = unicode_str(request.values.get('input', ''))
cell = worksheet.new_text_cell_before(id, input=input)
worksheet.increase_state_number()
-
+
r['new_id'] = cell.id()
r['new_html'] = cell.html(editing=True)
@@ -311,7 +311,7 @@ def worksheet_new_text_cell_after(worksheet):
input = unicode_str(request.values.get('input', ''))
cell = worksheet.new_text_cell_after(id, input=input)
worksheet.increase_state_number()
-
+
r['new_id'] = cell.id()
r['new_html'] = cell.html(editing=True)
@@ -369,9 +369,9 @@ def worksheet_eval(worksheet):
either introspection to the documentation of the function, or the
documentation of the function and the source code of the function
respectively.
- """
+ """
from base import notebook_updates
-
+
r = {}
r['id'] = id = get_cell_id()
@@ -429,7 +429,7 @@ def worksheet_eval(worksheet):
notebook_updates()
return encode_response(r)
-
+
@worksheet_command('cell_update')
def worksheet_cell_update(worksheet):
@@ -496,7 +496,7 @@ def worksheet_introspect(worksheet):
r['command'] = 'error'
r['message'] = 'Cannot evaluate public cell introspection.'
return encode_response(r)
-
+
before_cursor = request.values.get('before_cursor', '')
after_cursor = request.values.get('after_cursor', '')
cell = worksheet.get_cell_with_id(id)
@@ -513,7 +513,7 @@ def worksheet_edit(worksheet):
"""
Return a window that allows the user to edit the text of the
worksheet with the given filename.
- """
+ """
return g.notebook.html_edit_window(worksheet, g.username)
@@ -591,7 +591,7 @@ def worksheet_invite_collab(worksheet):
pass
return redirect(url_for_worksheet(worksheet))
-
+
########################################################
# Revisions
########################################################
@@ -599,7 +599,7 @@ def worksheet_invite_collab(worksheet):
def worksheet_revisions(worksheet):
"""
Show a list of revisions of this worksheet.
- """
+ """
if 'action' not in request.values:
if 'rev' in request.values:
return g.notebook.html_specific_revision(g.username, worksheet,
@@ -628,9 +628,9 @@ def worksheet_revisions(worksheet):
return current_app.message(_('Error'))
-
+
########################################################
-# Cell directories
+# Cell directories
########################################################
@worksheet_command('cells/<path:filename>')
def worksheet_cells(worksheet, filename):
@@ -649,7 +649,7 @@ def worksheet_data_legacy(worksheet, filename):
@worksheet_command('data/<path:filename>')
def worksheed_data_folder(worksheet,filename):
- # preferred way of accessing data
+ # preferred way of accessing data
return worksheet_data(worksheet, filename)
def worksheet_data(worksheet, filename):
@@ -684,7 +684,7 @@ def worksheet_savedatafile(worksheet):
os.unlink(dest)
open(dest, 'w').write(text_field)
return g.notebook.html_download_or_delete_datafile(worksheet, g.username, filename)
-
+
@worksheet_command('link_datafile')
def worksheet_link_datafile(worksheet):
@@ -702,10 +702,10 @@ def worksheet_link_datafile(worksheet):
os.link(src,target)
return redirect(worksheet_datafile.url_for(worksheet, name=data_filename))
#return redirect(url_for_worksheet(target_ws) + '/datafile?name=%s'%data_filename) #XXX: Can we not hardcode this?
-
+
@worksheet_command('upload_data')
def worksheet_upload_data(worksheet):
- return g.notebook.html_upload_data_window(worksheet, g.username)
+ return g.notebook.html_upload_data_window(worksheet, g.username)
@worksheet_command('do_upload_data')
def worksheet_do_upload_data(worksheet):
@@ -721,7 +721,7 @@ def worksheet_do_upload_data(worksheet):
return current_app.message(_('Error uploading file (missing field "file"). %(backlinks)s', backlinks=backlinks), worksheet_url)
else:
file = request.files['file']
-
+
text_fields = ['url', 'new', 'name']
for field in text_fields:
if field not in request.values:
@@ -775,8 +775,8 @@ def worksheet_do_upload_data(worksheet):
return response
else:
file.save(dest)
- return response
-
+ return response
+
################################
#Publishing
################################
@@ -828,7 +828,7 @@ def worksheet_publish(worksheet):
else:
return g.notebook.html_beforepublish_window(worksheet, g.username)
-############################################
+############################################
# Ratings
############################################
@worksheet_command('rating_info')
@@ -879,7 +879,7 @@ def unconditional_download(worksheet, title):
from flask.helpers import send_file
return send_file(filename, mimetype='application/sage')
-
+
@worksheet_command('restart_sage')
def worksheet_restart_sage(worksheet):
@@ -895,7 +895,7 @@ def worksheet_quit_sage(worksheet):
@worksheet_command('interrupt')
def worksheet_interrupt(worksheet):
- #XXX: TODO -- this must not block long (!)
+ #XXX: TODO -- this must not block long (!)
worksheet.sage().interrupt()
return 'failed' if worksheet.sage().is_computing() else 'success'
@@ -979,7 +979,7 @@ def worksheet_file(path):
# FIXME: For some reason, an extra cell gets added so we
# remove it here.
W.cell_list().pop()
-
+
return g.notebook.html(worksheet_filename=W.filename(),
username=g.username)
18 flask_version/worksheet_listing.py
View
@@ -7,7 +7,7 @@
from flask.ext.babel import Babel, gettext, ngettext, lazy_gettext
_ = gettext
-worksheet_listing = Module('flask_version.worksheet_listing')
+worksheet_listing = Module('sagenb.flask_version.worksheet_listing')
def render_worksheet_list(args, pub, username):
"""
@@ -28,10 +28,10 @@ def render_worksheet_list(args, pub, username):
a string
"""
-
+
from sagenb.notebook.notebook import sort_worksheet_list
from sagenb.misc.misc import unicode_str, SAGE_VERSION
-
+
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'
@@ -78,7 +78,7 @@ def bare_home():
def get_worksheets_from_request():
U = g.notebook.user_manager().user(g.username)
-
+
if 'filename' in request.form:
filenames = [request.form['filename']]
elif 'filenames' in request.form:
@@ -90,8 +90,8 @@ def get_worksheets_from_request():
for filename in filenames:
W = g.notebook.get_worksheet_with_filename(filename)
if W.owner() != g.username:
- # TODO BUG: if trying to stop a shared worksheet, this check means that
- # only the owner can stop from the worksheet listing (using /send_to_stop), but any
+ # TODO BUG: if trying to stop a shared worksheet, this check means that
+ # only the owner can stop from the worksheet listing (using /send_to_stop), but any
# shared person can stop the worksheet by quitting it.
continue
worksheets.append(W)
@@ -134,7 +134,7 @@ def empty_trash():
return redirect(request.headers['referer'])
else:
return redirect(url_for('home', typ='trash'))
-
+
#####################
# Public Worksheets #
@@ -155,7 +155,7 @@ def public_worksheet(id):
except KeyError:
return _("Requested public worksheet does not exist"), 404
worksheet = pub_worksheet(original_worksheet)
-
+
owner = worksheet.owner()
worksheet.set_owner('pub')
s = g.notebook.html(worksheet_filename=worksheet.filename(),
@@ -192,7 +192,7 @@ def public_worksheet_cells(id, filename):
@login_required
def download_worksheets():
from sagenb.misc.misc import walltime, tmp_filename
-
+
t = walltime()
print "Starting zipping a group of worksheets in a separate thread..."
zip_filename = tmp_filename() + ".zip"
1  sagenb/flask_version
View
5 sagenb/notebook/run_notebook.py
View
@@ -46,15 +46,12 @@ class NotebookRun(object):
# Flask #
#########
import os, sys, random
-flask_dir = os.path.join(os.environ['SAGE_ROOT'], 'devel', 'sagenb', 'flask_version')
-sys.path.append(flask_dir)
-import base as flask_base
+import sagenb.flask_version.base as flask_base
opts={}
startup_token = '{0:x}'.format(random.randint(0, 2**128))
if %(automatic_login)s:
opts['startup_token'] = startup_token
flask_app = flask_base.create_app(%(notebook_opts)s, **opts)
-sys.path.remove(flask_dir)
def save_notebook(notebook):
print "Quitting all running worksheets..."
1  setup.py
View
@@ -52,6 +52,7 @@ def all_files(dir, prefix):
install_requires = install_requires,
test_suite = 'sagenb.testing.run_tests.all_tests',
packages = [ 'sagenb'
+ , 'sagenb.flask_version'
, 'sagenb.interfaces'
, 'sagenb.misc'
, 'sagenb.notebook'
Please sign in to comment.
Something went wrong with that request. Please try again.