summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-02-01 20:16:34 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2016-02-02 04:23:27 +0100
commite300358e7c2d7619a57cafe2232b298ea796b395 (patch)
treeebbc64c2d60a78829910b6997caaa970002d02c2
parent86f8914def48346d807347c2d43edd543ff4f3e9 (diff)
downloadweb-e300358e7c2d7619a57cafe2232b298ea796b395.tar.gz
web-e300358e7c2d7619a57cafe2232b298ea796b395.tar.bz2
web-e300358e7c2d7619a57cafe2232b298ea796b395.zip
manage.py: Fix url_for for console commands
-rw-r--r--accounts/utils/console.py18
-rwxr-xr-xmanage.py4
2 files changed, 20 insertions, 2 deletions
diff --git a/accounts/utils/console.py b/accounts/utils/console.py
index f81bd36..9996faa 100644
--- a/accounts/utils/console.py
+++ b/accounts/utils/console.py
@@ -1,4 +1,22 @@
# -*- coding: utf-8 -*-
+from flask.ext import script
+
+
+class Command(script.Command):
+ """
+ This changes the Command class from Flask-Script in such way,
+ that url_for will generate correct urls.
+ """
+
+ def __call__(self, app=None, *args, **kwargs):
+ base_url = '%s://%s%s' % (
+ app.config.get('PREFERRED_URL_SCHEME') or 'http',
+ app.config.get('SERVER_NAME') or 'localhost',
+ app.config.get('APPLICATION_ROOT') or '/')
+
+ with app.test_request_context(base_url=base_url):
+ return self.run(*args, **kwargs)
+
class TablePrinter(object):
diff --git a/manage.py b/manage.py
index cb65d10..cd763ed 100755
--- a/manage.py
+++ b/manage.py
@@ -1,9 +1,9 @@
#!/usr/bin/env python
from flask import current_app
-from flask.ext.script import Command, Manager, Server, Shell, Option
+from flask.ext.script import Manager, Server, Shell, Option
from accounts import create_app
-from accounts.utils.console import TablePrinter
+from accounts.utils.console import Command, TablePrinter
class ListServices(Command):