profile.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:hellogithub.com 作者: 521xueweihan 项目源码 文件源码
def user_collection():
    uuid = session.get('uuid')
    collection_name = request.values.get('name')
    collection_id = request.values.get('collection_id')

    if request.method == 'GET':
        collections = Collection.select()\
                                .where(Collection.uuid == uuid,
                                       Collection.status == 1)\
                                .order_by(Collection.create_time)
        for fi_collection in collections:
            fi_collection.projects = CollectionProject.select() \
                                                      .join(Collection) \
                                                      .where(Collection.id ==
                                                             fi_collection.id,
                                                             CollectionProject.status == 1)
        return render_template('profile/collection.html',
                               collections=collections,
                               page_title=u'????')
    # ?????
    elif request.method == 'POST':
        if not collection_name:
            raise InvalidParams()
        try:
            Collection.create(name=collection_name, uuid=uuid)
            return jsonify(message=u'????? {} ??'
                           .format(collection_name))
        except IntegrityError:
            raise ParamsConflict()

    # ?????
    elif request.method == 'PATCH':
        if not collection_name:
            raise InvalidParams()

        update_time = datetime.now()
        Collection.update(name=collection_name, update_time=update_time)\
            .where(Collection.id == collection_id).execute()
        return jsonify(message=u'????? {} ??'.format(collection_name))

    # ?????
    elif request.method == 'DELETE':
        if not collection_id:
            raise InvalidParams()

        collection_projects = CollectionProject.select()\
                                               .join(Collection)\
                                               .where(Collection.id == collection_id,
                                                      Collection.status == 1)
        with database.transaction():
            for fi_collection_project in collection_projects:
                CollectionProject.del_collection_project(fi_collection_project.id)

            Collection.del_collection(collection_id)
        return jsonify(message=u'???????')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号