Mercurial > piecrust2
diff piecrust/admin/siteinfo.py @ 935:7ecb946bfafd
admin: Lots of fixes for running the admin panel in a WSGI server.
- Use new source APIs in the dashboard to open WIP files.
- Fixed broken/outdated code in some views.
- Fixed cases when Flask is not running at the root URL by using the
`SCRIPT_NAME` variable somewhat more properly.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 04 Oct 2017 09:15:16 -0700 |
parents | dcdec4b951a1 |
children | 94fd4f07da83 |
line wrap: on
line diff
--- a/piecrust/admin/siteinfo.py Wed Oct 04 09:11:58 2017 -0700 +++ b/piecrust/admin/siteinfo.py Wed Oct 04 09:15:16 2017 -0700 @@ -5,6 +5,7 @@ import logging import threading import subprocess +from flask import request from piecrust.app import PieCrustFactory @@ -20,15 +21,21 @@ class SiteInfo: - def __init__(self, root_dir, url_prefix, *, debug=False): + def __init__(self, root_dir, *, debug=False): self.root_dir = root_dir - self.url_prefix = url_prefix self.debug = debug self._piecrust_factory = None self._piecrust_app = None self._scm = None @property + def url_prefix(self): + return request.script_root + + def make_url(self, rel_url): + return self.url_prefix + rel_url + + @property def piecrust_factory(self): if self._piecrust_factory is None: self._piecrust_factory = PieCrustFactory( @@ -36,10 +43,10 @@ cache_key='admin', debug=self.debug, config_values=[ - ('site/root', '%s/preview/' % self.url_prefix), - ('site/asset_url_format', - self.url_prefix + '/preview/_asset/%path%') - ]) + ('site/root', self.make_url('/preview/')), + ('site/asset_url_format', self.make_url( + '/preview/_asset/%path%'))] + ) return self._piecrust_factory @property