comparison piecrust/admin/views/dashboard.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 175d80cf75d7
children 8101692fdc11
comparison
equal deleted inserted replaced
934:98430e7143d2 935:7ecb946bfafd
8 from piecrust.sources.fs import FSContentSourceBase 8 from piecrust.sources.fs import FSContentSourceBase
9 from piecrust.sources.interfaces import IInteractiveSource 9 from piecrust.sources.interfaces import IInteractiveSource
10 from piecrust.uriutil import split_uri 10 from piecrust.uriutil import split_uri
11 from ..textutil import text_preview 11 from ..textutil import text_preview
12 from ..blueprint import foodtruck_bp, load_user 12 from ..blueprint import foodtruck_bp, load_user
13 from ..views import with_menu_context 13 from ..views import with_menu_context, with_base_data
14 14
15 15
16 logger = logging.getLogger(__name__) 16 logger = logging.getLogger(__name__)
17 17
18 18
85 source = s 85 source = s
86 break 86 break
87 if source is None: 87 if source is None:
88 return None 88 return None
89 89
90 content_item = source.findContentFromPath(path) 90 full_path = os.path.join(pcapp.root_dir, path)
91 content_item = source.findContentFromPath(full_path)
91 if content_item is None: 92 if content_item is None:
92 return None 93 return None
93 94
94 page = pcapp.getPage(source, content_item) 95 page = pcapp.getPage(source, content_item)
95 uri = page.getUri() 96 uri = page.getUri()
101 102
102 extract = text_preview(seg.content) 103 extract = text_preview(seg.content)
103 return { 104 return {
104 'title': page.config.get('title'), 105 'title': page.config.get('title'),
105 'slug': slug, 106 'slug': slug,
106 'url': url_for('.edit_page', uri=slug), 107 'url': url_for('.edit_page', url=slug),
107 'text': extract 108 'text': extract
108 } 109 }
109 110
110 111
111 @foodtruck_bp.route('/login', methods=['GET', 'POST']) 112 @foodtruck_bp.route('/login', methods=['GET', 'POST'])
124 return redirect(url_for('.index')) 125 return redirect(url_for('.index'))
125 data['message'] = ( 126 data['message'] = (
126 "User '%s' doesn't exist or password is incorrect." % 127 "User '%s' doesn't exist or password is incorrect." %
127 username) 128 username)
128 129
130 with_base_data(data)
129 return render_template('login.html', **data) 131 return render_template('login.html', **data)
130 132
131 133
132 @foodtruck_bp.route('/logout') 134 @foodtruck_bp.route('/logout')
133 @login_required 135 @login_required