view piecrust/admin/views/preview.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 725744a4c42d
children 94fd4f07da83
line wrap: on
line source

from flask import g, make_response
from flask.ext.login import login_required
from piecrust.serving.server import PieCrustServer
from ..blueprint import foodtruck_bp


@foodtruck_bp.route('/preview/')
@login_required
def preview_root_page():
    return preview_page('/')


@foodtruck_bp.route('/preview/<path:url>')
@login_required
def preview_page(url):
    pcappfac = g.site.piecrust_factory
    server = PieCrustServer(pcappfac, root_url=g.site.make_url('/preview/'))
    return make_response(server)