Fix bug in vagrantfile Fix bug in db create/drop Fix typo in climaster
@@ -9,7 +9,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |||||
vb.cpus = 2 | vb.cpus = 2 | ||||
end | end | ||||
config.vm.provision "shell", path: "install.sh", privileged: "false" | |||||
config.vm.provision "shell", path: "install.sh", privileged: false | |||||
end | end | ||||
Vagrant::Config.run do |config| | Vagrant::Config.run do |config| | ||||
@@ -45,7 +45,6 @@ sudo npm install -g bower | |||||
cd /home/vagrant | cd /home/vagrant | ||||
virtualenv .venv | virtualenv .venv | ||||
source .venv/bin/activate | source .venv/bin/activate | ||||
@@ -13,13 +13,14 @@ import click | |||||
from flask import Flask, request, render_template, url_for, redirect, g | from flask import Flask, request, render_template, url_for, redirect, g | ||||
from flask.ext.cache import Cache | from flask.ext.cache import Cache | ||||
from flask.ext.login import LoginManager, current_user | 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 flask.ext.assets import Environment, Bundle | ||||
from werkzeug.routing import BaseConverter | from werkzeug.routing import BaseConverter | ||||
from werkzeug.exceptions import HTTPException | 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.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 .lib.util import is_su, in_virtualenv | ||||
from .version import __version__ | from .version import __version__ | ||||
@@ -161,6 +162,8 @@ def create_app(config=None): | |||||
cache.init_app(app) | cache.init_app(app) | ||||
assets.init_app(app) | assets.init_app(app) | ||||
db.Model = declarative_base(metaclass=HookModelMeta, cls=HookMixin) | |||||
for status_code in httplib.responses: | for status_code in httplib.responses: | ||||
if status_code >= 400: | if status_code >= 400: | ||||
app.register_error_handler(status_code, error_handler) | app.register_error_handler(status_code, error_handler) | ||||
@@ -186,11 +189,10 @@ def create_app(config=None): | |||||
# This will be removed at some point | # This will be removed at some point | ||||
with app.app_context(): | with app.app_context(): | ||||
db.create_all() | |||||
db.metadata.create_all(db.get_engine(app)) | |||||
return app | return app | ||||
# Init plugins here if possible | # Init plugins here if possible | ||||
login_manager = LoginManager() | login_manager = LoginManager() | ||||
@@ -1,5 +1,5 @@ | |||||
from realms import config, create_app, db, __version__, cli | 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 subprocess import call, Popen | ||||
from multiprocessing import cpu_count | from multiprocessing import cpu_count | ||||
import click | import click | ||||
@@ -108,7 +108,7 @@ def setup(ctx, **kw): | |||||
green('Config saved to %s' % conf_path) | green('Config saved to %s' % conf_path) | ||||
if not conf_path.startswith('/etc/realms-wiki'): | 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() | click.echo() | ||||
yellow('Type "realms-wiki start" to start server') | yellow('Type "realms-wiki start" to start server') | ||||
@@ -339,7 +339,8 @@ def create_db(): | |||||
""" | """ | ||||
green("Creating all tables") | green("Creating all tables") | ||||
with app.app_context(): | 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() | @cli.command() | ||||
@@ -349,7 +350,7 @@ def drop_db(): | |||||
""" | """ | ||||
yellow("Dropping all tables") | yellow("Dropping all tables") | ||||
with app.app_context(): | with app.app_context(): | ||||
db.create_all() | |||||
db.metadata.drop_all(db.get_engine(app)) | |||||
@cli.command() | @cli.command() | ||||
@@ -1,14 +1,10 @@ | |||||
import json | import json | ||||
from sqlalchemy import not_, and_ | from sqlalchemy import not_, and_ | ||||
from sqlalchemy.ext.declarative import declarative_base | |||||
from datetime import datetime | from datetime import datetime | ||||
from realms import db | 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 | """Base SQLAlchemy Model for automatic serialization and | ||||
deserialization of columns and nested relationships. | deserialization of columns and nested relationships. | ||||
@@ -32,7 +32,7 @@ def revert(): | |||||
commit = request.form.get('commit') | commit = request.form.get('commit') | ||||
message = request.form.get('message', "Reverting %s" % cname) | 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 | return dict(error=True, message="Anonymous posting not allowed"), 403 | ||||
if cname in current_app.config.get('WIKI_LOCKED_PAGES'): | if cname in current_app.config.get('WIKI_LOCKED_PAGES'): | ||||
@@ -107,7 +107,7 @@ def page_write(name): | |||||
if not cname: | if not cname: | ||||
return dict(error=True, message="Invalid name") | 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 | return dict(error=True, message="Anonymous posting not allowed"), 403 | ||||
if request.method == 'POST': | if request.method == 'POST': | ||||