annotate piecrust/admin/views/preview.py @ 809:22c6f6a3d0a0

admin: Add ability to upload page assets.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 17 Dec 2016 19:55:10 -0800
parents 5e91bc0e3b4d
children 82509bce94ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
587
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os.path
772
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents: 704
diff changeset
2 from flask import current_app, g, make_response
587
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 from flask.ext.login import login_required
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 from piecrust import CACHE_DIR
704
89ca8cdab020 admin: Fix crash when previewing a website.
Ludovic Chabant <ludovic@chabant.com>
parents: 587
diff changeset
5 from piecrust.app import PieCrustFactory
587
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 from piecrust.serving.server import Server
772
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents: 704
diff changeset
7 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
8
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9
772
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents: 704
diff changeset
10 @foodtruck_bp.route('/site/<sitename>/')
587
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 @login_required
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 def preview_site_root(sitename):
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 return preview_site(sitename, '/')
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15
772
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents: 704
diff changeset
16 @foodtruck_bp.route('/site/<sitename>/<path:url>')
587
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 @login_required
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 def preview_site(sitename, url):
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 root_dir = g.sites.get_root_dir(sitename)
704
89ca8cdab020 admin: Fix crash when previewing a website.
Ludovic Chabant <ludovic@chabant.com>
parents: 587
diff changeset
20 appfactory = PieCrustFactory(
89ca8cdab020 admin: Fix crash when previewing a website.
Ludovic Chabant <ludovic@chabant.com>
parents: 587
diff changeset
21 root_dir,
89ca8cdab020 admin: Fix crash when previewing a website.
Ludovic Chabant <ludovic@chabant.com>
parents: 587
diff changeset
22 cache_key='foodtruck',
772
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents: 704
diff changeset
23 debug=current_app.debug)
704
89ca8cdab020 admin: Fix crash when previewing a website.
Ludovic Chabant <ludovic@chabant.com>
parents: 587
diff changeset
24 server = Server(appfactory,
89ca8cdab020 admin: Fix crash when previewing a website.
Ludovic Chabant <ludovic@chabant.com>
parents: 587
diff changeset
25 root_url='/site/%s/' % sitename)
587
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 return make_response(server._run_request)
d4a01a023998 admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27