diff --git a/Vagrantfile b/Vagrantfile index 56acd78..363069f 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -9,7 +9,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| vb.cpus = 2 end - config.vm.provision "shell", path: "install.sh", privileged: "false" + config.vm.provision "shell", path: "install.sh", privileged: false end Vagrant::Config.run do |config| diff --git a/install.sh b/install.sh index 5197390..9660b79 100755 --- a/install.sh +++ b/install.sh @@ -45,7 +45,6 @@ sudo npm install -g bower cd /home/vagrant - virtualenv .venv source .venv/bin/activate diff --git a/realms/__init__.py b/realms/__init__.py index 08de16f..f550e3a 100644 --- a/realms/__init__.py +++ b/realms/__init__.py @@ -13,13 +13,14 @@ 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, declarative_base, Model, _QueryProperty +from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.assets import Environment, Bundle from werkzeug.routing import BaseConverter from werkzeug.exceptions import HTTPException +from sqlalchemy.ext.declarative import declarative_base from .lib.util import to_canonical, remove_ext, mkdir_safe, gravatar_url, to_dict -from .lib.hook import HookModelMeta +from .lib.hook import HookModelMeta, HookMixin from .lib.util import is_su, in_virtualenv from .version import __version__ @@ -161,6 +162,8 @@ def create_app(config=None): cache.init_app(app) assets.init_app(app) + 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) @@ -186,11 +189,10 @@ def create_app(config=None): # This will be removed at some point with app.app_context(): - db.create_all() + db.metadata.create_all(db.get_engine(app)) return app - # Init plugins here if possible login_manager = LoginManager() diff --git a/realms/commands.py b/realms/commands.py index 24781b4..542df69 100644 --- a/realms/commands.py +++ b/realms/commands.py @@ -1,5 +1,5 @@ from realms import config, create_app, db, __version__, cli -from realms.lib.util import is_su, random_string, in_virtualenv, green, yellow, red +from realms.lib.util import random_string, in_virtualenv, green, yellow, red from subprocess import call, Popen from multiprocessing import cpu_count import click @@ -108,7 +108,7 @@ def setup(ctx, **kw): green('Config saved to %s' % conf_path) if not conf_path.startswith('/etc/realms-wiki'): - yellow('Note: You can move file to /etc/realms-wiki/realms-wiki.conf') + yellow('Note: You can move file to /etc/realms-wiki/realms-wiki.json') click.echo() yellow('Type "realms-wiki start" to start server') @@ -339,7 +339,8 @@ def create_db(): """ green("Creating all tables") with app.app_context(): - db.create_all() + green('DB_URI: %s' % app.config.get('DB_URI')) + db.metadata.create_all(db.get_engine(app)) @cli.command() @@ -349,7 +350,7 @@ def drop_db(): """ yellow("Dropping all tables") with app.app_context(): - db.create_all() + db.metadata.drop_all(db.get_engine(app)) @cli.command() diff --git a/realms/lib/model.py b/realms/lib/model.py index a811d18..84da7c9 100644 --- a/realms/lib/model.py +++ b/realms/lib/model.py @@ -1,14 +1,10 @@ import json from sqlalchemy import not_, and_ -from sqlalchemy.ext.declarative import declarative_base from datetime import datetime from realms import db -from .hook import HookModelMeta, HookMixin -Base = declarative_base(metaclass=HookModelMeta, cls=HookMixin) - -class Model(Base): +class Model(db.Model): """Base SQLAlchemy Model for automatic serialization and deserialization of columns and nested relationships. diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index fe00b87..ef51cac 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -32,7 +32,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'): @@ -107,7 +107,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':