コード例 #1
0
def get_articles(userid):
    user = User.objects(id=userid).first()
    page = int(request.args.get('page'))
    per_page = int(request.args.get('per_page'))
    kws = {'user': user}
    if request.args.get("status") != None:
        kws['status'] = int(request.args.get("status"))
    if request.args.get("channel_id") != None:
        channel = Channel.objects(id=request.args.get("channel_id")).first()
        kws['channel'] = channel
    if request.args.get("begin_pubdate") != None:
        kws['created__gte'] = request.args.get("begin_pubdate")
    if request.args.get("end_pubdate") != None:
        kws['created__lte'] = request.args.get("end_pubdate")
    articles = Article.objects(**kws)
    paginated_articles = articles.skip((page - 1) * per_page).limit(per_page)
    return jsonify({
        "message": 'OK',
        "data": {
            "total_count": articles.count(),
            "page": page,
            "per_page": per_page,
            "results": articles.to_public_json()
        }
    })
コード例 #2
0
def get_channels():
    channels = Channel.objects()
    return jsonify({
        'massage': 'ok',
        'data': {
            'channels': channels.to_public_json()
        }
    })
コード例 #3
0
def client_get_channels(userid):

    channels = Channel.objects()

    return jsonify({
        "message": 'OK',
        "data": {
            "channels": channels.to_public_json()
        }
    })
コード例 #4
0
def delete_user_channel(userid,channelid):
    user = User.objects(id=userid).first()
    channel_del = Channel.objects(id=channelid).first()
    user.channels.remove(channel_del)
    user.save()

    return jsonify({
        "message": 'OK',
        "data": {}
    })
コード例 #5
0
def user_add_channel(userid):
    user = User.objects(id=userid).first()
    body = request.json
    channels = body.get('channels')
    channel_id = channels[0]['id']
    channel_add = Channel.objects(id=channel_id).first()
    user.channels.append(channel_add)
    user.save()
    return jsonify({
        "message": 'OK',
        "data": {}
    })
コード例 #6
0
def upload_article(userid, articleId):
    data = request.json
    print(data)
    channel = Channel.objects(id=data.get('channel_id')).first()
    article = Article.objects(id=articleId).first()
    d_cover = article.covers
    cover = Cover(type=data.get('cover')['type'],
                  images=data.get('cover')['images']).save()
    article.title = data.get('title')
    article.channel = channel
    article.content = data.get('content')
    article.covers = cover
    d_cover.delete()
    article.save()

    return jsonify({'message': 'ok'})