comparison piecrust/admin/views/create.py @ 950:18d6ac20a132

admin: Fix old API calls and bugs when creating new pages.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 05 Oct 2017 00:27:57 -0700
parents 7ecb946bfafd
children 0d699f04968c
comparison
equal deleted inserted replaced
949:2d9b4c12579c 950:18d6ac20a132
52 metadata[f.name] = f.default_value 52 metadata[f.name] = f.default_value
53 for fk, fv in request.form.items(): 53 for fk, fv in request.form.items():
54 if fk.startswith('meta-'): 54 if fk.startswith('meta-'):
55 metadata[fk[5:]] = fv 55 metadata[fk[5:]] = fv
56 56
57 logger.debug("Searching for item with metadata: %s" % metadata) 57 logger.debug("Creating item with metadata: %s" % metadata)
58 content_item = source.findContent(metadata) 58 content_item = source.createContent(metadata)
59 if content_item is None: 59 if content_item is None:
60 logger.error("Can't find item for: %s" % metadata) 60 logger.error("Can't create item for: %s" % metadata)
61 abort(500) 61 abort(500)
62 62
63 logger.debug("Creating item: %s" % content_item.spec) 63 logger.debug("Creating content: %s" % content_item.spec)
64 with source.openItem(content_item, mode='w') as fp: 64 with source.openItem(content_item, 'w') as fp:
65 fp.write('') 65 fp.write('---\n')
66 fp.write('draft: true\n')
67 fp.write('---\n')
68 fp.write('\n')
69 fp.write("Start writing!\n")
66 flash("'%s' was created." % content_item.spec) 70 flash("'%s' was created." % content_item.spec)
67
68 route = pcapp.getSourceRoute(source.name)
69 if route is None:
70 logger.error("Can't find route for source: %s" % source.name)
71 abort(500)
72 71
73 page = Page(source, content_item) 72 page = Page(source, content_item)
74 uri = page.getUri() 73 uri = page.getUri()
75 logger.debug("Redirecting to: %s" % uri) 74 logger.debug("Redirecting to: %s" % uri)
76 _, rel_url = split_uri(page.app, uri) 75 _, rel_url = split_uri(page.app, uri)