Mercurial > piecrust2
annotate piecrust/admin/views/preview.py @ 961:b1a00c2c0c7f
admin: Use URL routes for static assets.
This removes the need for `base_url` and other workarounds for when the
admin panel is under a sub-folder.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 07 Oct 2017 12:16:04 -0700 |
parents | 94fd4f07da83 |
children | a90541509a41 |
rev | line source |
---|---|
935
7ecb946bfafd
admin: Lots of fixes for running the admin panel in a WSGI server.
Ludovic Chabant <ludovic@chabant.com>
parents:
919
diff
changeset
|
1 from flask import g, make_response |
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 from flask.ext.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 |
94fd4f07da83
admin: Fix more URL prefix issues, improve publishing.
Ludovic Chabant <ludovic@chabant.com>
parents:
935
diff
changeset
|
18 server = PieCrustServer(pcappfac, root_url=site.make_url('/preview/')) |
919
725744a4c42d
serve: Fix previewing articles from the administration panel.
Ludovic Chabant <ludovic@chabant.com>
parents:
886
diff
changeset
|
19 return make_response(server) |
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 |