Beispiel #1
0
def create_content():
    return_value = success('The content was created.')
    payload = get_payload(request)

    editing = False
    if payload.get('id'):
        content = Content.get(payload.get('id'))
        editing = True
        return_value = success('The content was updated.')
    else:
        content = Content()

    content.type = payload.get('type').lower()
    content.template = '{}.html'.format(content.type)
    content.title = payload.get('title')
    content.body = payload.get('body') or ''
    content.theme = payload.get('theme')
    content.preview = payload.get('preview') or ''
    content.user_id = payload.get('user_id')
    tags = [t.strip() for t in payload.get('tags', '').split(',') if t.strip()]
    for tag in tags:
        count = Tag.filter(Tag.name == tag).count()
        if not count:
            new_tag = Tag(name=tag)
            new_tag.insert()

    content.tags = ",".join(tags)
    content.parser = payload.get('parser', 'markdown')

    published = json.loads(payload.get('published', 'false'))
    content.published = published

    menu_item = json.loads(payload.get('menu_item', 'false'))
    content.menu_item = menu_item

    if not editing:
        content.slug = make_slug(content.title)
    else:
        published_on = payload.get('published_on')
        if published_on:
            content.published_on = parser.parse(published_on)

    valid = content.validate()
    if valid['success'] or editing:
        print(content.to_dict())
        content.insert()
        safe_commit()
        return_value['id'] = content.id
        # with app.context():
        #    cache.clear()
    else:
        return_value = valid

    return jsonify(return_value)
Beispiel #2
0
def create_content():
    return_value = success('The content was created.')
    payload = get_payload(request)

    editing = False
    if payload.get('id'):
        content = Content.get(payload.get('id'))
        editing = True
        return_value = success('The content was updated.')
    else:
        content = Content()

    content.type = payload.get('type').lower()
    content.title = payload.get('title')
    content.body = payload.get('body')
    content.user_id = payload.get('user_id')
    tags = [t.strip() for t in payload.get('tags', '').split(',') if t.strip()]
    for tag in tags:
        count = Tag.filter(Tag.name == tag).count()
        if not count:
            new_tag = Tag(name=tag)
            new_tag.insert()

    content.tags = ",".join(tags)
    content.parser = payload.get('parser', 'markdown')
    content.published = bool(payload.get('published', False))

    if not editing:
        content.slug = make_slug(content.title)
    else:
        created_on = payload.get('created_on')
        if created_on:
            content.created_on = parser.parse(created_on)

    valid = content.validate()
    if valid['success'] or editing:
        content.insert()
        safe_commit()
        return_value['id'] = content.id
    else:
        return_value = valid

    return jsonify(return_value)
Beispiel #3
0
def get_tags():
    tags = [t.name for t in Tag.all()]
    return json.dumps(tags)
Beispiel #4
0
def get_tags():
    tags = [t.name for t in Tag.all()]
    return json.dumps(tags)