diff 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
line wrap: on
line diff
--- a/piecrust/admin/views/create.py	Thu Oct 05 00:27:08 2017 -0700
+++ b/piecrust/admin/views/create.py	Thu Oct 05 00:27:57 2017 -0700
@@ -54,22 +54,21 @@
         if fk.startswith('meta-'):
             metadata[fk[5:]] = fv
 
-    logger.debug("Searching for item with metadata: %s" % metadata)
-    content_item = source.findContent(metadata)
+    logger.debug("Creating item with metadata: %s" % metadata)
+    content_item = source.createContent(metadata)
     if content_item is None:
-        logger.error("Can't find item for: %s" % metadata)
+        logger.error("Can't create item for: %s" % metadata)
         abort(500)
 
-    logger.debug("Creating item: %s" % content_item.spec)
-    with source.openItem(content_item, mode='w') as fp:
-        fp.write('')
+    logger.debug("Creating content: %s" % content_item.spec)
+    with source.openItem(content_item, 'w') as fp:
+        fp.write('---\n')
+        fp.write('draft: true\n')
+        fp.write('---\n')
+        fp.write('\n')
+        fp.write("Start writing!\n")
     flash("'%s' was created." % content_item.spec)
 
-    route = pcapp.getSourceRoute(source.name)
-    if route is None:
-        logger.error("Can't find route for source: %s" % source.name)
-        abort(500)
-
     page = Page(source, content_item)
     uri = page.getUri()
     logger.debug("Redirecting to: %s" % uri)