邓淳远、崔鹏宇、翁思扬组云计算期末项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. from flask import Flask, render_template, request, jsonify, session, Blueprint
  2. from bson import json_util
  3. import uuid
  4. from APP.view.database import db_session
  5. from APP.view.model import Block, CollectionBlock
  6. bp_block = Blueprint("block", __name__, url_prefix="/block")
  7. @bp_block.route("/add", methods=["POST"])
  8. def add_block():
  9. type = request.form.get('type')
  10. content = request.form.get("content")
  11. collection_id = request.form.get("collection_id")
  12. id = str(uuid.uuid4())
  13. try:
  14. count = Block.query.count()
  15. print(count)
  16. if type == 'text' or type == 'url':
  17. b = Block(type=type, content_text=content, order=count, id=id)
  18. else:
  19. b = Block(type=type, content_pic=content, order=count, id=id)
  20. db_session.add(b)
  21. cb = CollectionBlock(id=collection_id, block_id=id)
  22. db_session.add(cb)
  23. db_session.commit()
  24. except BaseException as e:
  25. print(e)
  26. ret = {'msg': 'failed!', 'collection_id': collection_id}
  27. return json_util.dumps(ret)
  28. ret = {'msg': 'succuss', 'id': id}
  29. """
  30. ret['id'] =
  31. """
  32. return json_util.dumps(ret)
  33. @bp_block.route("/select", methods=["POST"])
  34. def get_block():
  35. # 查询这个id的collection的block
  36. id = request.form.get('id')
  37. blocks = []
  38. """
  39. blocks.append({'id': '1', 'content': 'xuanz','type':'text'})
  40. blocks.append({'id': '2', 'content': 'mingg','type':'url'})
  41. blocks.append({'id': '3', 'content': 'wnqian','type':'picture'})
  42. """
  43. ans = {'blocks': blocks, 'msg': 'succuss'}
  44. return json_util.dumps(ans)
  45. @bp_block.route("/delete", methods=["POST"])
  46. def delete():
  47. collection_id = request.form.get('collection_id')
  48. block_id = request.form.get('block_id')
  49. """
  50. id的collection的block
  51. """
  52. ret = {'msg': 'succuss'}
  53. return json_util.dumps(ret)
  54. @bp_block.route("/swap", methods=["POST"])
  55. def swap():
  56. id = request.form.get('id')
  57. collection_id = request.form.get('collection_id')
  58. order = request.form.get('new_order')
  59. """
  60. collection_id的collection的这个id的块和顺序是order的块交换
  61. """
  62. ret = {'msg': 'succuss'}
  63. return json_util.dumps(ret)
  64. @bp_block.route("/edit", methods=["POST"])
  65. def edit():
  66. collection_id = request.form.get('collection_id')
  67. block_id = request.form.get('block_id')
  68. content = request.form.get('content', None)
  69. """
  70. content = none的情况请直接返回
  71. """
  72. ret = {'msg': 'succuss'}
  73. return json_util.dumps(ret)
  74. @bp_block.route("/get_web_name", methods=["POST"])
  75. def get_web_name():
  76. url = request.form.get('url')
  77. ret = {'msg': 'succuss'}
  78. """
  79. ret['name'] = url对应的网站的titleurl
  80. """
  81. return json_util.dumps(ret)