示例#1
0
def _submit_page_form(pcapp, source):
    metadata = {}
    for f in source.getInteractiveFields():
        metadata[f.name] = f.default_value
    for fk, fv in request.form.items():
        if fk.startswith('meta-'):
            metadata[fk[5:]] = fv

    logger.debug("Creating item with metadata: %s" % metadata)
    content_item = source.createContent(metadata)
    if content_item is None:
        logger.error("Can't create item for: %s" % metadata)
        abort(500)

    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)

    page = Page(source, content_item)
    uri = page.getUri()
    logger.debug("Redirecting to: %s" % uri)
    _, rel_url = split_uri(page.app, uri)
    return redirect(url_for('.edit_page', url=rel_url))
示例#2
0
def _submit_page_form(pcapp, source):
    metadata = {}
    for f in source.getInteractiveFields():
        metadata[f.name] = f.default_value
    for fk, fv in request.form.items():
        if fk.startswith('meta-'):
            metadata[fk[5:]] = fv

    logger.debug("Creating item with metadata: %s" % metadata)
    content_item = source.createContent(metadata)
    if content_item is None:
        logger.error("Can't create item for: %s" % metadata)
        abort(500)

    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)

    page = Page(source, content_item)
    uri = page.getUri()
    logger.debug("Redirecting to: %s" % uri)
    _, rel_url = split_uri(page.app, uri)
    return redirect(url_for('.edit_page', url=rel_url))
示例#3
0
def _get_location_response(source_name, content_item):
    from piecrust.app import PieCrust
    pcapp = PieCrust(g.site.root_dir)
    source = pcapp.getSource(source_name)

    page = Page(source, content_item)
    uri = page.getUri()

    logger.debug("Redirecting to: %s" % uri)
    r = Response()
    r.status_code = 201
    r.headers.add('Location', uri)
    return r