Mercurial > piecrust2
view piecrust/admin/views/__init__.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 | 5b4c02ed9bb2 |
children | b1a00c2c0c7f |
line wrap: on
line source
from flask import current_app, render_template, request from flask.views import View from .menu import get_menu_context class FoodTruckView(View): template_name = 'index.html' requires_menu = True def render_template(self, context): if self.requires_menu: context = with_menu_context() return render_template(self.template_name, **context) def get_context(self): return None def dispatch_request(self): ctx = self.get_context() return render_template(ctx) def with_menu_context(context=None): if context is None: context = {} context['menu'] = get_menu_context() with_base_data(context) return context def with_base_data(context=None): if context is None: context = {} script_root = request.script_root or '' root_url = current_app.config.get('FOODTRUCK_ROOT_URL') or '' context['base_url'] = script_root + root_url