Mercurial > piecrust2
annotate piecrust/admin/views/preview.py @ 1185:24413a2963b9
admin: Add hidden system information on publish page for troubleshooting.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 01 Oct 2020 10:58:33 -0700 |
parents | 0d699f04968c |
children |
rev | line source |
---|---|
963
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
1 from flask import g, request, make_response |
1151
0d699f04968c
cm: Update dependencies and fix imports of Flask plugins.
Ludovic Chabant <ludovic@chabant.com>
parents:
963
diff
changeset
|
2 from flask_login import login_required |
919
725744a4c42d
serve: Fix previewing articles from the administration panel.
Ludovic Chabant <ludovic@chabant.com>
parents:
886
diff
changeset
|
3 from piecrust.serving.server import PieCrustServer |
772
3885421c29a3
admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
704
diff
changeset
|
4 from ..blueprint import foodtruck_bp |
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
886
dcdec4b951a1
admin: Get the admin panel working again.
Ludovic Chabant <ludovic@chabant.com>
parents:
812
diff
changeset
|
7 @foodtruck_bp.route('/preview/') |
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 @login_required |
886
dcdec4b951a1
admin: Get the admin panel working again.
Ludovic Chabant <ludovic@chabant.com>
parents:
812
diff
changeset
|
9 def preview_root_page(): |
dcdec4b951a1
admin: Get the admin panel working again.
Ludovic Chabant <ludovic@chabant.com>
parents:
812
diff
changeset
|
10 return preview_page('/') |
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 |
886
dcdec4b951a1
admin: Get the admin panel working again.
Ludovic Chabant <ludovic@chabant.com>
parents:
812
diff
changeset
|
13 @foodtruck_bp.route('/preview/<path:url>') |
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 @login_required |
886
dcdec4b951a1
admin: Get the admin panel working again.
Ludovic Chabant <ludovic@chabant.com>
parents:
812
diff
changeset
|
15 def preview_page(url): |
952
94fd4f07da83
admin: Fix more URL prefix issues, improve publishing.
Ludovic Chabant <ludovic@chabant.com>
parents:
935
diff
changeset
|
16 site = g.site |
94fd4f07da83
admin: Fix more URL prefix issues, improve publishing.
Ludovic Chabant <ludovic@chabant.com>
parents:
935
diff
changeset
|
17 pcappfac = site.piecrust_factory |
963
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
18 root_url = request.script_root or '' |
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
19 root_url += site.make_url('/preview/') |
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
20 server = PieCrustServer(pcappfac, root_url=root_url) |
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
21 |
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
22 # Patch the WSGI environment for the underlying PieCrust server, |
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
23 # because it doesn't generally handle stuff being under a different |
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
24 # sub folder of the domain. |
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
25 script_name = request.environ['SCRIPT_NAME'] |
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
26 request.environ['SCRIPT_NAME'] = '' |
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
27 request.environ['PATH_INFO'] = script_name + request.environ['PATH_INFO'] |
a90541509a41
admin: Fix the site preview by editing the WSGI environment.
Ludovic Chabant <ludovic@chabant.com>
parents:
952
diff
changeset
|
28 |
919
725744a4c42d
serve: Fix previewing articles from the administration panel.
Ludovic Chabant <ludovic@chabant.com>
parents:
886
diff
changeset
|
29 return make_response(server) |
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 |