Mercurial > piecrust2
comparison piecrust/admin/views/micropub.py @ 1121:41b7ce0d5131
internal: PEP8.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 27 Feb 2018 21:44:45 -0800 |
parents | c8366fc15043 |
children | be74ba54a06f |
comparison
equal
deleted
inserted
replaced
1120:181a7a34d8f0 | 1121:41b7ce0d5131 |
---|---|
47 logger.warning("Args: %s" % request.args) | 47 logger.warning("Args: %s" % request.args) |
48 logger.warning("Form: %s" % request.form) | 48 logger.warning("Form: %s" % request.form) |
49 logger.warning("Data: %s" % request.get_data(True)) | 49 logger.warning("Data: %s" % request.get_data(True)) |
50 try: | 50 try: |
51 logger.warning("JSON: %s" % request.json) | 51 logger.warning("JSON: %s" % request.json) |
52 except: | 52 except: # NOQA |
53 pass | 53 pass |
54 | 54 |
55 | 55 |
56 @foodtruck_bp.route('/micropub', methods=['POST']) | 56 @foodtruck_bp.route('/micropub', methods=['POST']) |
57 @requires_indieauth | 57 @requires_indieauth |
61 if 'h' in request.form: | 61 if 'h' in request.form: |
62 data = _get_mf2_from_form(request.form) | 62 data = _get_mf2_from_form(request.form) |
63 else: | 63 else: |
64 try: | 64 try: |
65 data = json.loads(request.get_data(as_text=True)) | 65 data = json.loads(request.get_data(as_text=True)) |
66 except: | 66 except Exception: |
67 data = None | 67 data = None |
68 | 68 |
69 if data: | 69 if data: |
70 entry_type = _mf2get(data, 'type') | 70 entry_type = _mf2get(data, 'type') |
71 if entry_type == 'h-entry': | 71 if entry_type == 'h-entry': |
74 if do_publish: | 74 if do_publish: |
75 _run_publisher() | 75 _run_publisher() |
76 return _get_location_response(source_name, content_item) | 76 return _get_location_response(source_name, content_item) |
77 | 77 |
78 else: | 78 else: |
79 logger.error("Post type '%s' is not supported." % post_type) | 79 logger.error("Post type '%s' is not supported." % entry_type) |
80 else: | 80 else: |
81 logger.error("Missing form or JSON data.") | 81 logger.error("Missing form or JSON data.") |
82 | 82 |
83 abort(400) | 83 abort(400) |
84 | 84 |
123 data = {} | 123 data = {} |
124 if request.args.get('q') == 'config': | 124 if request.args.get('q') == 'config': |
125 endpoint_url = (request.host_url.rstrip('/') + | 125 endpoint_url = (request.host_url.rstrip('/') + |
126 url_for('.post_micropub_media')) | 126 url_for('.post_micropub_media')) |
127 data.update({ | 127 data.update({ |
128 "media-endpoint": endpoint_url | 128 "media-endpoint": endpoint_url |
129 }) | 129 }) |
130 | 130 |
131 pcapp = g.site.piecrust_app | 131 pcapp = g.site.piecrust_app |
132 syn_data = pcapp.config.get('micropub/syndicate_to') | 132 syn_data = pcapp.config.get('micropub/syndicate_to') |
133 if syn_data: | 133 if syn_data: |
378 (pthumb, pthumb)) | 378 (pthumb, pthumb)) |
379 | 379 |
380 if os.supports_fd: | 380 if os.supports_fd: |
381 import stat | 381 import stat |
382 try: | 382 try: |
383 os.chmod(fp.fileno(), | 383 os.chmod( |
384 stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IWGRP) | 384 fp.fileno(), |
385 stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP) | |
385 except OSError: | 386 except OSError: |
386 pass | 387 pass |
387 | 388 |
388 autocommit = pcapp.config.get('micropub/autocommit', False) | 389 autocommit = pcapp.config.get('micropub/autocommit', False) |
389 if autocommit: | 390 if autocommit: |