Mercurial > piecrust2
comparison piecrust/admin/views/publish.py @ 778:5e91bc0e3b4d
internal: Move admin panel code into the piecrust package.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 16 Jul 2016 15:02:24 +0200 |
parents | foodtruck/views/publish.py@3885421c29a3 |
children | 82509bce94ca |
comparison
equal
deleted
inserted
replaced
777:8d633ca59bc5 | 778:5e91bc0e3b4d |
---|---|
1 import copy | |
2 import logging | |
3 from flask import request, g, url_for, render_template, Response | |
4 from flask.ext.login import login_required | |
5 from ..blueprint import foodtruck_bp | |
6 from ..pubutil import PublishLogReader | |
7 from ..views import with_menu_context | |
8 | |
9 | |
10 logger = logging.getLogger(__name__) | |
11 | |
12 | |
13 @foodtruck_bp.route('/publish', methods=['GET', 'POST']) | |
14 @login_required | |
15 def publish(): | |
16 if request.method == 'POST': | |
17 target = request.form.get('target') | |
18 if not target: | |
19 raise Exception("No target specified.") | |
20 | |
21 g.site.publish(target) | |
22 | |
23 site = g.site | |
24 pub_cfg = copy.deepcopy(site.piecrust_app.config.get('publish', {})) | |
25 if not pub_cfg: | |
26 data = {'error': "There are not publish targets defined in your " | |
27 "configuration file."} | |
28 return render_template('error.html', **data) | |
29 | |
30 data = {} | |
31 data['url_run'] = url_for('.publish') | |
32 data['site_title'] = site.piecrust_app.config.get('site/title', site.name) | |
33 data['targets'] = [] | |
34 for tn in sorted(pub_cfg.keys()): | |
35 tc = pub_cfg[tn] | |
36 desc = None | |
37 if isinstance(tc, dict): | |
38 desc = tc.get('description') | |
39 data['targets'].append({ | |
40 'name': tn, | |
41 'description': desc | |
42 }) | |
43 | |
44 with_menu_context(data) | |
45 | |
46 return render_template('publish.html', **data) | |
47 | |
48 | |
49 @foodtruck_bp.route('/publish-log') | |
50 @login_required | |
51 def stream_publish_log(): | |
52 pid_path = g.site.publish_pid_file | |
53 log_path = g.site.publish_log_file | |
54 rdr = PublishLogReader(pid_path, log_path) | |
55 | |
56 response = Response(rdr.run(), mimetype='text/event-stream') | |
57 response.headers['Cache-Control'] = 'no-cache' | |
58 return response | |
59 |