From 3c13d7c93d4f632025a9919114757679d9a3d537 Mon Sep 17 00:00:00 2001 From: zsyuan <13096633+zsyuan8973@user.noreply.gitee.com> Date: Mon, 17 Jul 2023 01:21:29 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=E5=B1=95=E7=A4=BA=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zsyuan <13096633+zsyuan8973@user.noreply.gitee.com> --- display | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 display diff --git a/display b/display new file mode 100644 index 0000000..ac02fc1 --- /dev/null +++ b/display @@ -0,0 +1,30 @@ +from abc import ABC, abstractmethod +from flasgger import swag_from +from flask import request, current_app +from flask.views import MethodView +from flask import Response, jsonify, make_response +from app.extensions import json_response +from app.text.models import get_all_displays + + + +class TextDisplay(ABC): + @abstractmethod + def display_text(self, text): + pass + +class ConsoleDisplay(TextDisplay): + def display_text(self, text): + print(text) + + query = request.values + limit = int(query.get("limit", 10)) + offset = int(query.get("offset", 0)) + total, text_data = TextTable.get_all_displays(limit, offset) + return json_response(data={"total": total, "result": text_data}) + + + +# 创建ConsoleDisplay对象并调用display_text方法展示文本内容 +console_display = ConsoleDisplay() +console_display.display_text(json_response) \ No newline at end of file -- Gitee From 07f732d5d87b9179c517c9ca70cdec732946196d Mon Sep 17 00:00:00 2001 From: zsyuan <13096633+zsyuan8973@user.noreply.gitee.com> Date: Mon, 17 Jul 2023 01:23:21 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20disp?= =?UTF-8?q?lay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- display | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 display diff --git a/display b/display deleted file mode 100644 index ac02fc1..0000000 --- a/display +++ /dev/null @@ -1,30 +0,0 @@ -from abc import ABC, abstractmethod -from flasgger import swag_from -from flask import request, current_app -from flask.views import MethodView -from flask import Response, jsonify, make_response -from app.extensions import json_response -from app.text.models import get_all_displays - - - -class TextDisplay(ABC): - @abstractmethod - def display_text(self, text): - pass - -class ConsoleDisplay(TextDisplay): - def display_text(self, text): - print(text) - - query = request.values - limit = int(query.get("limit", 10)) - offset = int(query.get("offset", 0)) - total, text_data = TextTable.get_all_displays(limit, offset) - return json_response(data={"total": total, "result": text_data}) - - - -# 创建ConsoleDisplay对象并调用display_text方法展示文本内容 -console_display = ConsoleDisplay() -console_display.display_text(json_response) \ No newline at end of file -- Gitee From 08d1e77c7a383f92d42feed5ca9ad0885944167c Mon Sep 17 00:00:00 2001 From: zsyuan <13096633+zsyuan8973@user.noreply.gitee.com> Date: Mon, 17 Jul 2023 01:28:32 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E5=B1=95=E7=A4=BA=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zsyuan <13096633+zsyuan8973@user.noreply.gitee.com> --- app/text/display.py | 30 ++++++++++++++++++++++++++++++ app/text/models.py | 11 +++++++++++ app/text/urls.py | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 app/text/display.py diff --git a/app/text/display.py b/app/text/display.py new file mode 100644 index 0000000..ac02fc1 --- /dev/null +++ b/app/text/display.py @@ -0,0 +1,30 @@ +from abc import ABC, abstractmethod +from flasgger import swag_from +from flask import request, current_app +from flask.views import MethodView +from flask import Response, jsonify, make_response +from app.extensions import json_response +from app.text.models import get_all_displays + + + +class TextDisplay(ABC): + @abstractmethod + def display_text(self, text): + pass + +class ConsoleDisplay(TextDisplay): + def display_text(self, text): + print(text) + + query = request.values + limit = int(query.get("limit", 10)) + offset = int(query.get("offset", 0)) + total, text_data = TextTable.get_all_displays(limit, offset) + return json_response(data={"total": total, "result": text_data}) + + + +# 创建ConsoleDisplay对象并调用display_text方法展示文本内容 +console_display = ConsoleDisplay() +console_display.display_text(json_response) \ No newline at end of file diff --git a/app/text/models.py b/app/text/models.py index 2f3ebc2..8cdcbee 100644 --- a/app/text/models.py +++ b/app/text/models.py @@ -23,6 +23,17 @@ class TextTable(BaseModel): class Meta: table_name = "t_text" + + # 获取文本内容信息 + @classmethod + def get_all_displays(cls, page_size, page_number): + limit = page_size + offset = (page_number - 1) * page_size + displays = cls.select() + total = displays.count() + res = displays.order_by(cls.id).offset(offset).limit(limit) + displays_data = [cls.display_to_dict(displays) for displays in res] + return total, displays_data # @classmethod # def get_with_page(cls, limit, offset): diff --git a/app/text/urls.py b/app/text/urls.py index 5160bfd..78c8df8 100644 --- a/app/text/urls.py +++ b/app/text/urls.py @@ -2,6 +2,7 @@ from flask import Blueprint from peewee import DoesNotExist from app.text import views +from app.text import display bp = Blueprint("text", __name__) @@ -18,6 +19,7 @@ def handle_not_exist(error): # ) bp.add_url_rule("/content", view_func=views.Content.as_view("content"), methods=["POST"]) +bp.add_url_rule("/display", view_func=display.ConsoleDisplay.as_view("ConsoleDisplay"), methods=["GET"]) # bp.add_url_rule("/demos", view_func=views.Demos.as_view("demos"), methods=["GET"]) -- Gitee