Example #1
0
def get_categories():
    page = request.args.get('page', 1, type=int)
    per_page = min(request.args.get('per_page', 10, type=int), 100)
    data = Category.to_collection_dict(Category.query, page, per_page)
    if not data:
        return jsonify({'status': 'ok', 'code': 200, 'msg': 'No data found'})
    return jsonify(data), 200
Example #2
0
def insert_category():
    content = request.get_json()
    try:
        print('ok')
        cate = Category(name=content['name'])
        data, errors = CategorySchema().load(cate.to_json())
        print(errors)
        if errors:
            return jsonify({'status': 'ko', 'code': 422, 'msg': errors}), 422
    except:
        return jsonify({'status': 'ko', 'code': 415, 'msg': 'Fail'}), 415
    try:
        db.session.add(cate)
        db.session.commit()
        return jsonify({
            'status': 'ok',
            'code': 201,
            'msg': 'Create new category successfully!'
        }), 201
    except:
        return jsonify({'status': 'ko', 'code': 403, 'msg': 'Fail'})
Example #3
0
def set_post(post,form):
    post.title=form.title.data
    if(post.url==None or post.url==''):
        post.url=post.slugify(post.title)
    else:
        post.url=post.slugify(post.url)
    post.description=form.description.data
    post.content=form.content.data
    post.post_type=form.post_type.data
    post.post_status=form.post_status.data
    post.author=User.get_by_id(session['user_id'])
    post.category=Category(name=form.category.data)
    my_tags = []
    for tag in form.tags.data.lower().split(','):
        my_tags.append(Tag(name=tag))
    post.tags=my_tags

    return post
Example #4
0
def category_sermon():
    cat = Category(name='Sermon')
    cat.put()
    return cat
Example #5
0
def category_worship():
    cat = Category(name='Worship')
    cat.put()
    return cat
Example #6
0
def category_sermon():
  cat = Category(name='Sermon')
  cat.put()
  return cat
Example #7
0
def category_worship():
  cat = Category(name='Worship')
  cat.put()
  return cat