diff --git a/docker/Dockerfile b/docker/Dockerfile index 3a5ef95..d57ac7a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,7 +6,7 @@ RUN apt-get install -y software-properties-common python-software-properties rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN ln -s /usr/bin/nodejs /usr/bin/node && \ - npm install -g bower + npm install -g bower clean-css RUN useradd -ms /bin/bash wiki @@ -44,4 +44,3 @@ CMD . .venv/bin/activate && \ --bind 0.0.0.0:5000 \ --chdir /home/wiki/realms-wiki \ 'realms:create_app()' - diff --git a/realms/__init__.py b/realms/__init__.py index 8c4c571..27c63dc 100644 --- a/realms/__init__.py +++ b/realms/__init__.py @@ -13,10 +13,10 @@ import httplib import traceback import click from flask import Flask, request, render_template, url_for, redirect, g -from flask.ext.cache import Cache -from flask.ext.login import LoginManager, current_user -from flask.ext.sqlalchemy import SQLAlchemy -from flask.ext.assets import Environment, Bundle +from flask_cache import Cache +from flask_login import LoginManager, current_user +from flask_sqlalchemy import SQLAlchemy +from flask_assets import Environment, Bundle from flask_ldap_login import LDAPLoginManager from functools import update_wrapper from werkzeug.routing import BaseConverter @@ -180,9 +180,7 @@ def create_app(config=None): db.Model = declarative_base(metaclass=HookModelMeta, cls=HookMixin) - for status_code in httplib.responses: - if status_code >= 400: - app.register_error_handler(status_code, error_handler) + app.register_error_handler(HTTPException, error_handler) @app.before_request def init_g(): diff --git a/realms/commands.py b/realms/commands.py index ac228c9..c7ca43c 100644 --- a/realms/commands.py +++ b/realms/commands.py @@ -425,7 +425,7 @@ def clear_cache(): def test(): """ Run tests """ - for mod in [('flask.ext.testing', 'Flask-Testing'), ('nose', 'nose'), ('blinker', 'blinker')]: + for mod in [('flask_testing', 'Flask-Testing'), ('nose', 'nose'), ('blinker', 'blinker')]: if not module_exists(mod[0]): pip.main(['install', mod[1]]) diff --git a/realms/config/__init__.py b/realms/config/__init__.py index 4150a3d..32172f3 100644 --- a/realms/config/__init__.py +++ b/realms/config/__init__.py @@ -139,6 +139,7 @@ class Config(object): DEBUG = False ASSETS_DEBUG = False SQLALCHEMY_ECHO = False + SQLALCHEMY_TRACK_MODIFICATIONS = False MODULES = ['wiki', 'search', 'auth'] diff --git a/realms/lib/hook.py b/realms/lib/hook.py index 0327263..a607b54 100644 --- a/realms/lib/hook.py +++ b/realms/lib/hook.py @@ -1,4 +1,4 @@ -from flask.ext.sqlalchemy import DeclarativeMeta +from flask_sqlalchemy import DeclarativeMeta from functools import wraps diff --git a/realms/lib/test.py b/realms/lib/test.py index dd5b683..465b6f4 100644 --- a/realms/lib/test.py +++ b/realms/lib/test.py @@ -1,7 +1,7 @@ import os import shutil import tempfile -from flask.ext.testing import TestCase +from flask_testing import TestCase from realms.lib.util import random_string from realms import create_app diff --git a/realms/modules/auth/__init__.py b/realms/modules/auth/__init__.py index a33ffda..b8421e7 100644 --- a/realms/modules/auth/__init__.py +++ b/realms/modules/auth/__init__.py @@ -1,6 +1,6 @@ from realms import login_manager from flask import request, flash, redirect -from flask.ext.login import login_url +from flask_login import login_url modules = set() diff --git a/realms/modules/auth/ldap/models.py b/realms/modules/auth/ldap/models.py index c1c7176..1574eb8 100644 --- a/realms/modules/auth/ldap/models.py +++ b/realms/modules/auth/ldap/models.py @@ -1,5 +1,5 @@ from flask import render_template -from flask.ext.login import login_user +from flask_login import login_user from realms import ldap from flask_ldap_login import LDAPLoginForm from ..models import BaseUser diff --git a/realms/modules/auth/local/models.py b/realms/modules/auth/local/models.py index 695ce63..9e14ec8 100644 --- a/realms/modules/auth/local/models.py +++ b/realms/modules/auth/local/models.py @@ -1,5 +1,5 @@ from flask import current_app, render_template -from flask.ext.login import logout_user, login_user +from flask_login import logout_user, login_user from realms import login_manager, db from realms.lib.model import Model from ..models import BaseUser diff --git a/realms/modules/auth/models.py b/realms/modules/auth/models.py index f62b736..f5a0ec7 100644 --- a/realms/modules/auth/models.py +++ b/realms/modules/auth/models.py @@ -1,5 +1,5 @@ from flask import current_app -from flask.ext.login import UserMixin, logout_user, AnonymousUserMixin +from flask_login import UserMixin, logout_user, AnonymousUserMixin from realms import login_manager from realms.lib.util import gravatar_url from itsdangerous import URLSafeSerializer, BadSignature diff --git a/realms/templates/auth/ldap/login.html b/realms/modules/auth/templates/auth/ldap/login.html similarity index 100% rename from realms/templates/auth/ldap/login.html rename to realms/modules/auth/templates/auth/ldap/login.html diff --git a/realms/templates/auth/local/login.html b/realms/modules/auth/templates/auth/local/login.html similarity index 100% rename from realms/templates/auth/local/login.html rename to realms/modules/auth/templates/auth/local/login.html diff --git a/realms/templates/auth/login.html b/realms/modules/auth/templates/auth/login.html similarity index 100% rename from realms/templates/auth/login.html rename to realms/modules/auth/templates/auth/login.html diff --git a/realms/templates/auth/register.html b/realms/modules/auth/templates/auth/register.html similarity index 100% rename from realms/templates/auth/register.html rename to realms/modules/auth/templates/auth/register.html diff --git a/realms/templates/auth/settings.html b/realms/modules/auth/templates/auth/settings.html similarity index 100% rename from realms/templates/auth/settings.html rename to realms/modules/auth/templates/auth/settings.html diff --git a/realms/modules/auth/views.py b/realms/modules/auth/views.py index 8ca607f..40f5e47 100644 --- a/realms/modules/auth/views.py +++ b/realms/modules/auth/views.py @@ -1,8 +1,8 @@ from flask import current_app, render_template, request, redirect, Blueprint, flash, url_for -from flask.ext.login import logout_user +from flask_login import logout_user from realms.modules.auth.models import Auth -blueprint = Blueprint('auth', __name__) +blueprint = Blueprint('auth', __name__, template_folder='templates') @blueprint.route("/login", methods=['GET', 'POST']) diff --git a/realms/modules/search/models.py b/realms/modules/search/models.py index 5a1a559..2935db7 100644 --- a/realms/modules/search/models.py +++ b/realms/modules/search/models.py @@ -14,7 +14,7 @@ def whoosh(app): def elasticsearch(app): - from flask.ext.elastic import Elastic + from flask_elastic import Elastic fields = app.config.get('ELASTICSEARCH_FIELDS') return ElasticSearch(Elastic(app), fields) diff --git a/realms/templates/search/search.html b/realms/modules/search/templates/search/search.html similarity index 100% rename from realms/templates/search/search.html rename to realms/modules/search/templates/search/search.html diff --git a/realms/modules/search/views.py b/realms/modules/search/views.py index f94d27e..4172039 100644 --- a/realms/modules/search/views.py +++ b/realms/modules/search/views.py @@ -1,10 +1,14 @@ -from flask import render_template, request, Blueprint +from flask import render_template, request, Blueprint, current_app +from flask.ext.login import current_user from realms import search as search_engine -blueprint = Blueprint('search', __name__) +blueprint = Blueprint('search', __name__, template_folder='templates') @blueprint.route('/_search') def search(): + if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous(): + return current_app.login_manager.unauthorized() + results = search_engine.wiki(request.args.get('q')) return render_template('search/search.html', results=results) diff --git a/realms/modules/wiki/assets.py b/realms/modules/wiki/assets.py index 8b2162d..8f20b42 100644 --- a/realms/modules/wiki/assets.py +++ b/realms/modules/wiki/assets.py @@ -7,4 +7,4 @@ assets.register('editor.js', 'vendor/ace-builds/src/mode-markdown.js', 'vendor/ace-builds/src/ext-keybinding_menu.js', 'vendor/keymaster/keymaster.js', - 'js/aced.js') + 'wiki/js/aced.js') diff --git a/realms/static/js/aced.js b/realms/modules/wiki/static/js/aced.js similarity index 100% rename from realms/static/js/aced.js rename to realms/modules/wiki/static/js/aced.js diff --git a/realms/static/js/collaboration/firepad.js b/realms/modules/wiki/static/js/collaboration/firepad.js similarity index 100% rename from realms/static/js/collaboration/firepad.js rename to realms/modules/wiki/static/js/collaboration/firepad.js diff --git a/realms/static/js/collaboration/main.js b/realms/modules/wiki/static/js/collaboration/main.js similarity index 100% rename from realms/static/js/collaboration/main.js rename to realms/modules/wiki/static/js/collaboration/main.js diff --git a/realms/static/js/collaboration/togetherjs.js b/realms/modules/wiki/static/js/collaboration/togetherjs.js similarity index 100% rename from realms/static/js/collaboration/togetherjs.js rename to realms/modules/wiki/static/js/collaboration/togetherjs.js diff --git a/realms/static/js/editor.js b/realms/modules/wiki/static/js/editor.js similarity index 100% rename from realms/static/js/editor.js rename to realms/modules/wiki/static/js/editor.js diff --git a/realms/templates/wiki/compare.html b/realms/modules/wiki/templates/wiki/compare.html similarity index 100% rename from realms/templates/wiki/compare.html rename to realms/modules/wiki/templates/wiki/compare.html diff --git a/realms/templates/wiki/edit.html b/realms/modules/wiki/templates/wiki/edit.html similarity index 94% rename from realms/templates/wiki/edit.html rename to realms/modules/wiki/templates/wiki/edit.html index dd1dc86..3ee82c6 100644 --- a/realms/templates/wiki/edit.html +++ b/realms/modules/wiki/templates/wiki/edit.html @@ -6,10 +6,10 @@ var PAGE_NAME = '{{ name }}'; - + {% if config.get('COLLABORATION') %} - + {% endif %} {% if config.get('COLLABORATION') == 'firepad' %} @@ -18,11 +18,11 @@ - + {% endif %} {% if config.get('COLLABORATION') == 'togetherjs' %} - + {% endif %} diff --git a/realms/templates/wiki/history.html b/realms/modules/wiki/templates/wiki/history.html similarity index 100% rename from realms/templates/wiki/history.html rename to realms/modules/wiki/templates/wiki/history.html diff --git a/realms/templates/wiki/index.html b/realms/modules/wiki/templates/wiki/index.html similarity index 100% rename from realms/templates/wiki/index.html rename to realms/modules/wiki/templates/wiki/index.html diff --git a/realms/templates/wiki/page.html b/realms/modules/wiki/templates/wiki/page.html similarity index 100% rename from realms/templates/wiki/page.html rename to realms/modules/wiki/templates/wiki/page.html diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index ab7d99f..73eee22 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -3,16 +3,17 @@ import itertools import sys from datetime import datetime from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app -from flask.ext.login import login_required, current_user +from flask_login import login_required, current_user from realms.lib.util import to_canonical, remove_ext, gravatar_url from .models import PageNotFound -blueprint = Blueprint('wiki', __name__) +blueprint = Blueprint('wiki', __name__, template_folder='templates', + static_folder='static', static_url_path='/static/wiki') @blueprint.route("/_commit//") def commit(name, sha): - if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous(): + if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous: return current_app.login_manager.unauthorized() cname = to_canonical(name) @@ -27,7 +28,7 @@ def commit(name, sha): @blueprint.route(r"/_compare//") def compare(name, fsha, dots, lsha): - if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous(): + if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous: return current_app.login_manager.unauthorized() diff = g.current_wiki.get_page(name, sha=lsha).compare(fsha) @@ -42,7 +43,7 @@ def revert(): commit = request.form.get('commit') message = request.form.get('message', "Reverting %s" % cname) - if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous(): + if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous: return dict(error=True, message="Anonymous posting not allowed"), 403 if cname in current_app.config.get('WIKI_LOCKED_PAGES'): @@ -64,7 +65,7 @@ def revert(): @blueprint.route("/_history/") def history(name): - if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous(): + if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous: return current_app.login_manager.unauthorized() return render_template('wiki/history.html', name=name) @@ -189,7 +190,7 @@ def _tree_index(items, path=""): @blueprint.route("/_index", defaults={"path": ""}) @blueprint.route("/_index/") def index(path): - if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous(): + if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous: return current_app.login_manager.unauthorized() items = g.current_wiki.get_index() @@ -210,7 +211,7 @@ def page_write(name): if not cname: return dict(error=True, message="Invalid name") - if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous(): + if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous: return dict(error=True, message="Anonymous posting not allowed"), 403 if request.method == 'POST': @@ -253,7 +254,7 @@ def page_write(name): @blueprint.route("/", defaults={'name': 'home'}) @blueprint.route("/") def page(name): - if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous(): + if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous: return current_app.login_manager.unauthorized() cname = to_canonical(name) diff --git a/realms/templates/layout.html b/realms/templates/layout.html index 4eb1717..a8ee14c 100644 --- a/realms/templates/layout.html +++ b/realms/templates/layout.html @@ -58,7 +58,7 @@ - {% if current_user.is_authenticated() %} + {% if current_user.is_authenticated %}