Browse Source

增加了block的add功能

master
邓淳远 4 years ago
parent
commit
a2ad4edcea
1 changed files with 36 additions and 13 deletions
  1. +36
    -13
      APP/view/block.py

+ 36
- 13
APP/view/block.py View File

@ -1,19 +1,41 @@
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
import uuid
bp_block = Blueprint("block", __name__,url_prefix="/block")
from APP.view.database import db_session
from APP.view.model import Block, CollectionBlock
bp_block = Blueprint("block", __name__, url_prefix="/block")
@bp_block.route("/add", methods=["POST"]) @bp_block.route("/add", methods=["POST"])
def add_block(): def add_block():
type = request.form.get('type') type = request.form.get('type')
content = request.form.get("content") content = request.form.get("content")
ret = {'msg': 'succuss'}
collection_id = request.form.get("collection_id")
id = str(uuid.uuid4())
try:
count = Block.query.count()
print(count)
if type == 'text' or type == 'url':
b = Block(type=type, content_text=content, order=count, id=id)
else:
b = Block(type=type, content_pic=content, order=count, id=id)
db_session.add(b)
cb = CollectionBlock(id=collection_id, block_id=id)
db_session.add(cb)
db_session.commit()
except BaseException as e:
print(e)
ret = {'msg': 'failed!', 'collection_id': collection_id}
return json_util.dumps(ret)
ret = {'msg': 'succuss', 'id': id}
""" """
ret['id'] = ret['id'] =
""" """
return json_util.dumps()
return json_util.dumps(ret)
@bp_block.route("/select", methods=["POST"]) @bp_block.route("/select", methods=["POST"])
@ -26,11 +48,10 @@ def get_block():
blocks.append({'id': '2', 'content': 'mingg','type':'url'}) blocks.append({'id': '2', 'content': 'mingg','type':'url'})
blocks.append({'id': '3', 'content': 'wnqian','type':'picture'}) blocks.append({'id': '3', 'content': 'wnqian','type':'picture'})
""" """
ans = {'blocks':blocks,'msg':'succuss'}
ans = {'blocks': blocks, 'msg': 'succuss'}
return json_util.dumps(ans) return json_util.dumps(ans)
@bp_block.route("/delete", methods=["POST"]) @bp_block.route("/delete", methods=["POST"])
def delete(): def delete():
collection_id = request.form.get('collection_id') collection_id = request.form.get('collection_id')
@ -38,9 +59,10 @@ def delete():
""" """
id的collection的block id的collection的block
""" """
ret = {'msg':'succuss'}
ret = {'msg': 'succuss'}
return json_util.dumps(ret) return json_util.dumps(ret)
@bp_block.route("/swap", methods=["POST"]) @bp_block.route("/swap", methods=["POST"])
def swap(): def swap():
id = request.form.get('id') id = request.form.get('id')
@ -50,28 +72,29 @@ def swap():
collection_id的collection的这个id的块和顺序是order的块交换 collection_id的collection的这个id的块和顺序是order的块交换
""" """
ret = {'msg':'succuss'}
ret = {'msg': 'succuss'}
return json_util.dumps(ret) return json_util.dumps(ret)
@bp_block.route("/edit", methods=["POST"]) @bp_block.route("/edit", methods=["POST"])
def edit(): def edit():
collection_id = request.form.get('collection_id') collection_id = request.form.get('collection_id')
block_id = request.form.get('block_id') block_id = request.form.get('block_id')
content = request.form.get('content',None)
content = request.form.get('content', None)
""" """
content = none的情况请直接返回 content = none的情况请直接返回
""" """
ret = {'msg':'succuss'}
ret = {'msg': 'succuss'}
return json_util.dumps(ret) return json_util.dumps(ret)
@bp_block.route("/get_web_name", methods=["POST"]) @bp_block.route("/get_web_name", methods=["POST"])
def get_web_name(): def get_web_name():
url = request.form.get('url') url = request.form.get('url')
ret = {'msg':'succuss'}
ret = {'msg': 'succuss'}
""" """
ret['name'] = url对应的网站的titleurl ret['name'] = url对应的网站的titleurl
""" """
return json_util.dumps(ret)
return json_util.dumps(ret)

Loading…
Cancel
Save