|
@ -1,38 +1,54 @@ |
|
|
from flask import Flask, render_template, request, jsonify, session, Blueprint |
|
|
from flask import Flask, render_template, request, jsonify, session, Blueprint |
|
|
from bson import json_util |
|
|
from bson import json_util |
|
|
|
|
|
|
|
|
bp = Blueprint("collection", __name__,url_prefix="/collection") |
|
|
|
|
|
|
|
|
from APP.view.database import db_session |
|
|
|
|
|
from APP.view.model import Collection |
|
|
|
|
|
|
|
|
|
|
|
bp_collection = Blueprint("collection", __name__, url_prefix="/collection") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/add", methods=["POST"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp_collection.route("/add", methods=["POST"]) |
|
|
def add_collection(): |
|
|
def add_collection(): |
|
|
name = request.form.get('name') |
|
|
name = request.form.get('name') |
|
|
tag = request.form.get('tag', None) |
|
|
tag = request.form.get('tag', None) |
|
|
ret = {'msg':'succuss','name':name} |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
phonenum = request.form.get('phonenum') |
|
|
|
|
|
try: |
|
|
|
|
|
count = Collection.query.count() |
|
|
|
|
|
print(count) |
|
|
|
|
|
c = Collection(id=count + 1, name=name, tag=tag, phonenum=phonenum) |
|
|
|
|
|
db_session.add(c) |
|
|
|
|
|
db_session.commit() |
|
|
|
|
|
except BaseException as e: |
|
|
|
|
|
print(e) |
|
|
|
|
|
ret = {'msg': 'failed!', 'name': name} |
|
|
|
|
|
return json_util.dumps(ret) |
|
|
|
|
|
|
|
|
|
|
|
ret = {'msg': 'succuss', 'name': name, 'id': str(count + 1)} |
|
|
|
|
|
"""; |
|
|
插入最末尾 |
|
|
插入最末尾 |
|
|
ret['id'] = |
|
|
ret['id'] = |
|
|
""" |
|
|
""" |
|
|
return json_util.dumps(ret) |
|
|
return json_util.dumps(ret) |
|
|
|
|
|
|
|
|
@bp.route("/select", methods=["POST"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp_collection.route("/select", methods=["POST"]) |
|
|
def get_collection(): |
|
|
def get_collection(): |
|
|
# 搜索的关键词 |
|
|
# 搜索的关键词 |
|
|
name = request.form.get('name', None) |
|
|
name = request.form.get('name', None) |
|
|
# 搜索对象 |
|
|
# 搜索对象 |
|
|
phonenum = request.form.get('phonenum',None) |
|
|
|
|
|
|
|
|
phonenum = request.form.get('phonenum', None) |
|
|
collections = [] |
|
|
collections = [] |
|
|
""" |
|
|
""" |
|
|
collections.append({'id': '1', 'name': 'xuanz','like':1}) |
|
|
collections.append({'id': '1', 'name': 'xuanz','like':1}) |
|
|
collections.append({'id': '2', 'name': 'mingg','like':2}) |
|
|
collections.append({'id': '2', 'name': 'mingg','like':2}) |
|
|
collections.append({'id': '3', 'name': 'wnqian','like':3}) |
|
|
collections.append({'id': '3', 'name': 'wnqian','like':3}) |
|
|
""" |
|
|
""" |
|
|
ret = {'collections':collections,'msg':'succuss'} |
|
|
|
|
|
|
|
|
ret = {'collections': collections, 'msg': 'succuss'} |
|
|
return json_util.dumps(ret) |
|
|
return json_util.dumps(ret) |
|
|
|
|
|
|
|
|
@bp.route("/recommand", methods=["POST"]) |
|
|
|
|
|
def get_collection(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp_collection.route("/recommand", methods=["POST"]) |
|
|
|
|
|
def recommand_collection(): |
|
|
collections = [] |
|
|
collections = [] |
|
|
""" |
|
|
""" |
|
|
返回推荐的内容 |
|
|
返回推荐的内容 |
|
@ -40,11 +56,12 @@ def get_collection(): |
|
|
collections.append({'id': '2', 'name': 'mingg','like':2}) |
|
|
collections.append({'id': '2', 'name': 'mingg','like':2}) |
|
|
collections.append({'id': '3', 'name': 'wnqian','like':3}) |
|
|
collections.append({'id': '3', 'name': 'wnqian','like':3}) |
|
|
""" |
|
|
""" |
|
|
ret = {'collections':collections,'msg':'succuss'} |
|
|
|
|
|
|
|
|
ret = {'collections': collections, 'msg': 'succuss'} |
|
|
return json_util.dumps(ret) |
|
|
return json_util.dumps(ret) |
|
|
|
|
|
|
|
|
@bp.route("/isLike", methods=["POST"]) |
|
|
|
|
|
def islike(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp_collection.route("/isLike", methods=["POST"]) |
|
|
|
|
|
def islike(): |
|
|
ret = {'msg': 'succuss'} |
|
|
ret = {'msg': 'succuss'} |
|
|
id = request.form.get('collection_id') |
|
|
id = request.form.get('collection_id') |
|
|
""" |
|
|
""" |
|
@ -54,27 +71,29 @@ def islike(): |
|
|
return json_util.dumps(ret) |
|
|
return json_util.dumps(ret) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/like", methods=["POST"]) |
|
|
|
|
|
|
|
|
@bp_collection.route("/like", methods=["POST"]) |
|
|
def get_like(): |
|
|
def get_like(): |
|
|
id = request.form.get('colllection_id') |
|
|
id = request.form.get('colllection_id') |
|
|
""" |
|
|
""" |
|
|
增加点赞数 |
|
|
增加点赞数 |
|
|
更新用户的点赞状态 |
|
|
更新用户的点赞状态 |
|
|
""" |
|
|
""" |
|
|
ret = {'msg':'succuss'} |
|
|
|
|
|
|
|
|
ret = {'msg': 'succuss'} |
|
|
return json_util.dumps(ret) |
|
|
return json_util.dumps(ret) |
|
|
|
|
|
|
|
|
@bp.route("/unlike", methods=["POST"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp_collection.route("/unlike", methods=["POST"]) |
|
|
def get_unlike(): |
|
|
def get_unlike(): |
|
|
id = request.form.get('colllection_id') |
|
|
id = request.form.get('colllection_id') |
|
|
""" |
|
|
""" |
|
|
减少点赞数 |
|
|
减少点赞数 |
|
|
更新用户的点赞状态 |
|
|
更新用户的点赞状态 |
|
|
""" |
|
|
""" |
|
|
ret = {'msg':'succuss'} |
|
|
|
|
|
|
|
|
ret = {'msg': 'succuss'} |
|
|
return json_util.dumps(ret) |
|
|
return json_util.dumps(ret) |
|
|
|
|
|
|
|
|
@bp.route("/swap", methods=["POST"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp_collection.route("/swap", methods=["POST"]) |
|
|
def swap(): |
|
|
def swap(): |
|
|
id = request.form.get('id') |
|
|
id = request.form.get('id') |
|
|
order = request.form.get('new_order') |
|
|
order = request.form.get('new_order') |
|
@ -82,26 +101,28 @@ def swap(): |
|
|
把这个id的collection和顺序是order的collection交换 |
|
|
把这个id的collection和顺序是order的collection交换 |
|
|
编号从零开始,有可能是自己 |
|
|
编号从零开始,有可能是自己 |
|
|
""" |
|
|
""" |
|
|
ret = {'msg':'succuss'} |
|
|
|
|
|
|
|
|
ret = {'msg': 'succuss'} |
|
|
return json_util.dumps(ret) |
|
|
return json_util.dumps(ret) |
|
|
|
|
|
|
|
|
@bp.route("/delete", methods=["POST"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp_collection.route("/delete", methods=["POST"]) |
|
|
def delete(): |
|
|
def delete(): |
|
|
id = request.form.get('collection_id') |
|
|
id = request.form.get('collection_id') |
|
|
""" |
|
|
""" |
|
|
删除这个id的collection,记得刷新顺序 |
|
|
删除这个id的collection,记得刷新顺序 |
|
|
""" |
|
|
""" |
|
|
ret = {'msg':'succuss'} |
|
|
|
|
|
|
|
|
ret = {'msg': 'succuss'} |
|
|
return json_util.dumps(ret) |
|
|
return json_util.dumps(ret) |
|
|
|
|
|
|
|
|
@bp.route("/edit", methods=["POST"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp_collection.route("/edit", methods=["POST"]) |
|
|
def edit(): |
|
|
def edit(): |
|
|
id = request.form.get('collection_id') |
|
|
id = request.form.get('collection_id') |
|
|
name = request.form.get('name', None) |
|
|
name = request.form.get('name', None) |
|
|
tag = request.form.get('tag', None) |
|
|
tag = request.form.get('tag', None) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
全部是none的情况请直接返回 |
|
|
全部是none的情况请直接返回 |
|
|
""" |
|
|
""" |
|
|
ret = {'msg':'succuss'} |
|
|
|
|
|
return json_util.dumps(ret) |
|
|
|
|
|
|
|
|
ret = {'msg': 'succuss'} |
|
|
|
|
|
return json_util.dumps(ret) |