Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
934:98430e7143d2 | 935:7ecb946bfafd |
---|---|
3 import sys | 3 import sys |
4 import copy | 4 import copy |
5 import logging | 5 import logging |
6 import threading | 6 import threading |
7 import subprocess | 7 import subprocess |
8 from flask import request | |
8 from piecrust.app import PieCrustFactory | 9 from piecrust.app import PieCrustFactory |
9 | 10 |
10 | 11 |
11 logger = logging.getLogger(__name__) | 12 logger = logging.getLogger(__name__) |
12 | 13 |
18 class InvalidSiteError(Exception): | 19 class InvalidSiteError(Exception): |
19 pass | 20 pass |
20 | 21 |
21 | 22 |
22 class SiteInfo: | 23 class SiteInfo: |
23 def __init__(self, root_dir, url_prefix, *, debug=False): | 24 def __init__(self, root_dir, *, debug=False): |
24 self.root_dir = root_dir | 25 self.root_dir = root_dir |
25 self.url_prefix = url_prefix | |
26 self.debug = debug | 26 self.debug = debug |
27 self._piecrust_factory = None | 27 self._piecrust_factory = None |
28 self._piecrust_app = None | 28 self._piecrust_app = None |
29 self._scm = None | 29 self._scm = None |
30 | |
31 @property | |
32 def url_prefix(self): | |
33 return request.script_root | |
34 | |
35 def make_url(self, rel_url): | |
36 return self.url_prefix + rel_url | |
30 | 37 |
31 @property | 38 @property |
32 def piecrust_factory(self): | 39 def piecrust_factory(self): |
33 if self._piecrust_factory is None: | 40 if self._piecrust_factory is None: |
34 self._piecrust_factory = PieCrustFactory( | 41 self._piecrust_factory = PieCrustFactory( |
35 self.root_dir, | 42 self.root_dir, |
36 cache_key='admin', | 43 cache_key='admin', |
37 debug=self.debug, | 44 debug=self.debug, |
38 config_values=[ | 45 config_values=[ |
39 ('site/root', '%s/preview/' % self.url_prefix), | 46 ('site/root', self.make_url('/preview/')), |
40 ('site/asset_url_format', | 47 ('site/asset_url_format', self.make_url( |
41 self.url_prefix + '/preview/_asset/%path%') | 48 '/preview/_asset/%path%'))] |
42 ]) | 49 ) |
43 return self._piecrust_factory | 50 return self._piecrust_factory |
44 | 51 |
45 @property | 52 @property |
46 def piecrust_app(self): | 53 def piecrust_app(self): |
47 if self._piecrust_app is None: | 54 if self._piecrust_app is None: |