diff --git a/realms/__init__.py b/realms/__init__.py index c4f9688..b0480c7 100644 --- a/realms/__init__.py +++ b/realms/__init__.py @@ -148,7 +148,7 @@ manager = Manager(app) # Flask extension objects login_manager = LoginManager() login_manager.init_app(app) -login_manager.login_view = 'login' +login_manager.login_view = 'auth.login' @login_manager.user_loader diff --git a/realms/models.py b/realms/models.py index aeb6a9e..7219ed4 100644 --- a/realms/models.py +++ b/realms/models.py @@ -98,7 +98,7 @@ class User(Base): @classmethod def login(cls, id): - login_user(CurrentUser(id), True) + login_user(CurrentUser(id), remember=True) @classmethod def logout(cls): diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index fe31a4e..a5f2d18 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -8,9 +8,9 @@ from realms.models import Site blueprint = Blueprint('wiki', __name__) -@blueprint.route("/wiki/_new/", methods=['GET', 'POST']) +@blueprint.route("/wiki/new/", methods=['GET', 'POST']) @login_required -def new_wiki(): +def new(): if request.method == 'POST': wiki_name = to_canonical(request.form['name']) @@ -26,7 +26,7 @@ def new_wiki(): @blueprint.route("/wiki/_commit//") -def commit_sha(name, sha): +def commit(name, sha): cname = to_canonical(name) data = g.current_wiki.get_page(cname, sha=sha) @@ -55,7 +55,7 @@ def revert(): @blueprint.route("/wiki/_history/") def history(name): history = g.current_wiki.get_history(name) - return render_template('wiki/history.html', name=name, history=history) + return render_template('wiki/history.html', name=name, history=history, wiki_home=url_for('wiki.page')) @blueprint.route("/wiki/_edit/", methods=['GET', 'POST']) diff --git a/realms/static/js/dillinger.js b/realms/static/js/dillinger.js index 1528f1e..990cbd2 100644 --- a/realms/static/js/dillinger.js +++ b/realms/static/js/dillinger.js @@ -1,6 +1,7 @@ $(function(){ - // Cache some shit + var url_prefix = "/wiki"; + var $theme = $('#theme-list') , $preview = $('#preview') , $autosave = $('#autosave') @@ -261,22 +262,11 @@ $(function(){ } - /** - * Initialize theme and other options of Ace editor. - * - * @return {Void} - */ function initAce(){ - editor = ace.edit("editor"); - + editor.focus(); } - /** - * Initialize various UI elements based on userprofile data. - * - * @return {Void} - */ function initUi(){ // Set proper theme value in theme dropdown fetchTheme(profile.theme, function(){ @@ -288,8 +278,6 @@ $(function(){ editor.getSession().setMode('ace/mode/markdown'); editor.getSession().setValue( profile.currentMd || editor.getSession().getValue()); - - // Immediately populate the preview
previewMd(); }); @@ -309,26 +297,11 @@ $(function(){ } - /// HANDLERS ================= - - - /** - * Clear the markdown and text and the subsequent HTML preview. - * - * @return {Void} - */ function clearSelection(){ editor.getSession().setValue(""); previewMd(); } - // TODO: WEBSOCKET MESSAGE? - /** - * Save the markdown via localStorage - isManual is from a click or key event. - * - * @param {Boolean} - * @return {Void} - */ function saveFile(isManual){ updateUserProfile({currentMd: editor.getSession().getValue()}); @@ -341,17 +314,12 @@ $(function(){ content: editor.getSession().getValue() }; $.post(window.location, data, function(){ - location.href = "/" + data['name']; + location.href = url_prefix + '/' + data['name']; }); } } - /** - * Enable autosave for a specific interval. - * - * @return {Void} - */ function autoSave(){ if(profile.autosave.enabled) { @@ -371,11 +339,6 @@ $(function(){ }); - /** - * Clear out user profile data in localStorage. - * - * @return {Void} - */ function resetProfile(){ // For some reason, clear() is not working in Chrome. localStorage.clear(); @@ -387,11 +350,6 @@ $(function(){ window.location.reload(); } - /** - * Dropbown nav handler to update the current theme. - * - * @return {Void} - */ function changeTheme(e){ // check for same theme var $target = $(e.target); @@ -409,14 +367,6 @@ $(function(){ } } - // TODO: Maybe we just load them all once and stash in appcache? - /** - * Dynamically appends a script tag with the proper theme and then applies that theme. - * - * @param {String} The theme name - * @param {Function} Optional callback - * @return {Void} - */ function fetchTheme(th, cb){ var name = th.split('/').pop(); asyncLoad("/static/js/ace/theme-"+ name +".js", function() { @@ -428,21 +378,10 @@ $(function(){ } - /** - * Change the body background color based on theme. - * - * @param {String} The theme name - * @return {Void} - */ function updateBg(name){ // document.body.style.backgroundColor = bgColors[name] } - /** - * Clientside update showing rendered HTML of Markdown. - * - * @return {Void} - */ function previewMd(){ var unmd = editor.getSession().getValue() @@ -455,12 +394,6 @@ $(function(){ //refreshWordCount(); } - /** - * Stash current file name in the user's profile. - * - * @param {String} Optional string to force the value - * @return {Void} - */ function updateFilename(str){ // Check for string because it may be keyup event object var f; @@ -503,43 +436,23 @@ $(function(){ } - /** - * Show a sad panda because they are using a shitty browser. - * - * @return {Void} - */ function sadPanda(){ // TODO: ACTUALLY SHOW A SAD PANDA. alert('Sad Panda - No localStorage for you!') } - /** - * Toggles the autosave feature. - * - * @return {Void} - */ function toggleAutoSave(){ $autosave.html( profile.autosave.enabled ? ' Disable Autosave' : ' Enable Autosave' ); updateUserProfile({autosave: {enabled: !profile.autosave.enabled }}); autoSave(); } - /** - * Bind keyup handler to the editor. - * - * @return {Void} - */ function bindPreview(){ editor.getSession().on('change', function(e) { previewMd(); }); } - /** - * Bind navigation elements. - * - * @return {Void} - */ function bindNav(){ $theme @@ -575,16 +488,12 @@ $(function(){ } // end bindNav() - /** - * Bind special keyboard handlers. - * - * @return {Void} - */ + function bindKeyboard(){ // CMD+s TO SAVE DOC key('command+s, ctrl+s', function(e){ saveFile(true); - e.preventDefault(); // so we don't save the webpage - native browser functionality + e.preventDefault(); // so we don't save the web page - native browser functionality }); var saveCommand = { @@ -605,14 +514,6 @@ $(function(){ }); - -/** - * Get scrollHeight of preview div - * (code adapted from https://github.com/anru/rsted/blob/master/static/scripts/editor.js) - * - * @param {Object} The jQuery object for the preview div - * @return {Int} The scrollHeight of the preview area (in pixels) - */ function getScrollHeight($prevFrame) { // Different browsers attach the scrollHeight of a document to different // elements, so handle that here. @@ -626,12 +527,6 @@ function getScrollHeight($prevFrame) { } } -/** - * Scroll preview to match cursor position in editor session - * (code adapted from https://github.com/anru/rsted/blob/master/static/scripts/editor.js) - * - * @return {Void} - */ function syncPreview() { var $ed = window.ace.edit('editor'); diff --git a/realms/templates/layout.html b/realms/templates/layout.html index 089a7f2..37b2a2f 100644 --- a/realms/templates/layout.html +++ b/realms/templates/layout.html @@ -8,10 +8,10 @@ Realms - - - - + + + + {% block css %}{% endblock %} @@ -43,14 +43,14 @@ @@ -63,13 +63,13 @@ {% else %} -
  • Login
  • -
  • Register
  • +
  • Login
  • +
  • Register
  • {% endif %}
    diff --git a/realms/templates/macros.html b/realms/templates/macros.html index 76da3fd..dc3b4bf 100644 --- a/realms/templates/macros.html +++ b/realms/templates/macros.html @@ -1,7 +1,7 @@ {% macro recaptcha(config) -%} diff --git a/realms/templates/wiki/page.html b/realms/templates/wiki/page.html index 47de0dd..a47d1b7 100644 --- a/realms/templates/wiki/page.html +++ b/realms/templates/wiki/page.html @@ -1,15 +1,15 @@ {% extends 'layout.html' %} {% block page_menu %} {% endblock %} {% block body %} {% if commit %}
    -
    +