Mercurial > piecrust2
comparison foodtruck/views/edit.py @ 658:a920b2ab1f31
admin: Fix OS-specific new line problems when editing pages.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 25 Feb 2016 23:26:36 -0800 |
parents | efc1dc916e7c |
children | 4d8e82641597 |
comparison
equal
deleted
inserted
replaced
657:c1a94e1beb9d | 658:a920b2ab1f31 |
---|---|
31 page_text = page_text.replace('\r\n', '\n') | 31 page_text = page_text.replace('\r\n', '\n') |
32 | 32 |
33 if 'do_preview' in request.form or 'do_save' in request.form or \ | 33 if 'do_preview' in request.form or 'do_save' in request.form or \ |
34 'do_save_and_commit' in request.form: | 34 'do_save_and_commit' in request.form: |
35 logger.debug("Writing page: %s" % page.path) | 35 logger.debug("Writing page: %s" % page.path) |
36 with open(page.path, 'w', encoding='utf8') as fp: | 36 with open(page.path, 'w', encoding='utf8', newline='') as fp: |
37 fp.write(page_text) | 37 fp.write(page_text) |
38 flash("%s was saved." % os.path.relpath( | 38 flash("%s was saved." % os.path.relpath( |
39 page.path, site_app.root_dir)) | 39 page.path, site_app.root_dir)) |
40 | 40 |
41 if 'do_save_and_commit' in request.form: | 41 if 'do_save_and_commit' in request.form: |
64 | 64 |
65 def _edit_page_form(page): | 65 def _edit_page_form(page): |
66 data = {} | 66 data = {} |
67 data['is_new_page'] = False | 67 data['is_new_page'] = False |
68 data['url_cancel'] = url_for('list_source', source_name=page.source.name) | 68 data['url_cancel'] = url_for('list_source', source_name=page.source.name) |
69 with open(page.path, 'r', encoding='utf8') as fp: | 69 with open(page.path, 'r', encoding='utf8', newline='') as fp: |
70 data['page_text'] = fp.read() | 70 data['page_text'] = fp.read() |
71 data['is_dos_nl'] = "1" if '\r\n' in data['page_text'] else "0" | 71 data['is_dos_nl'] = "1" if '\r\n' in data['page_text'] else "0" |
72 | 72 |
73 with_menu_context(data) | 73 with_menu_context(data) |
74 return render_template('edit_page.html', **data) | 74 return render_template('edit_page.html', **data) |