Browse Source

feat: 新增删除留言

SongZihuan 3 years ago
parent
commit
37a468ecbe

+ 1 - 1
core/msg.py

@@ -13,7 +13,7 @@ def load_message_list(limit: Optional[int] = None, offset: Optional[int] = None,
 
 
 class Message:
-    def __init__(self, msg_id, auth: "core.user.User", context, secret, update_time):
+    def __init__(self, msg_id, auth: "Optional[core.user.User]", context, secret=False, update_time=None):
         self.msg_id = msg_id
         self.auth = auth
         self.context = context

+ 5 - 0
static/styles/archive/archive.css

@@ -12,4 +12,9 @@
     border-radius: 10px;
     border: 2px solid #1685a9;
     padding: 15px;
+}
+
+.modal div {
+    background-color: white;
+    border-radius: 10px;
 }

+ 1 - 1
static/styles/auth/yours.css

@@ -1,4 +1,4 @@
-#LogoutModal div {
+.modal div {
     background-color: white;
     border-radius: 10px;
 }

+ 1 - 1
static/styles/docx/article.css

@@ -11,7 +11,7 @@
     text-decoration: none;
 }
 
-#CommentModal div {
+.modal div {
     background-color: white;
     border-radius: 10px;
 }

+ 1 - 1
static/styles/docx/docx.css

@@ -37,7 +37,7 @@
     border-radius: 10px;
 }
 
-#CreateModal div {
+.modal div {
     background-color: white;
     border-radius: 10px;
 }

+ 1 - 1
static/styles/msg/msg.css

@@ -11,7 +11,7 @@
     text-decoration: none;
 }
 
-#MsgModal div {
+.modal div {
     background-color: white;
     border-radius: 10px;
 }

+ 27 - 1
templates/msg/msg.html

@@ -12,7 +12,7 @@
     <section id="base" class="container mt-3">
         <div class="row">
             <section class="col-12 text-right">
-                <form class="writer clearfix" action="{{ url_for('msg.write_page') }}" method="post">
+                <form class="writer clearfix" action="{{ url_for('msg.write_msg_page') }}" method="post">
                     {{ form.hidden_tag() }}
                     {{ form.context(class="form-control mb-2", rows="5") }}
                     {{ form.secret() }} {{ form.secret.label }}
@@ -44,12 +44,38 @@
                 <section class="col-12">
                     {% for msg in msg_list %}
                         <div class="msg mr-0">
+                            {% if show_delete %}
+                                <div id="DeleteModal{{msg.msg_id}}" class="modal fade" role="dialog" aria-hidden="true">
+                                    <div class="modal-dialog">
+                                        <div class="modal-content text-left">
+                                            <div class="modal-header">
+                                                <h4 class="modal-title"> 确认删除留言? </h4>
+                                            </div>
+                                            <div class="modal-body">
+                                                <p> 是否确认删除留言? </p>
+                                            </div>
+                                            <div class="modal-footer">
+                                                <a class="btn btn-danger"
+                                                   href="{{ url_for("msg.delete_msg_page", msg_id=msg.msg_id) }}"> 删除 </a>
+                                                <button type="button" class="btn btn-secondary" data-dismiss="modal"> 取消 </button>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </div>
+                            {% endif %}
+
                             <p class="msg-title h5">
                                 {% if current_user.check_role("ReadUserInfo") %}  {# 判断是否可读取用户信息 #}
                                     {{ msg.auth.email }}
                                 {% else %}
                                     {{ msg.auth.s_email }}
                                 {% endif %}
+
+                                {% if show_delete %}
+                                    <a class="mb-2"
+                                        data-toggle="modal" data-target="#DeleteModal{{msg.msg_id}}"> &times; </a>
+                                {% endif %}
+
                                 <br>
                                 <small> {{ msg.update_time }}
                                     {% if msg.secret == is_secret %}

+ 2 - 2
view/docx.py

@@ -140,9 +140,9 @@ def delete_blog_page(blog_id: int):
         abort(403)
         return
     if BlogArticle(blog_id, None, None, None, None).delete():
-        flash("归档博文成功")
+        flash("博文删除成功")
     else:
-        flash("归档博文失败")
+        flash("博文删除失败")
     return redirect(url_for("docx.docx_page", page=1))
 
 

+ 20 - 3
view/msg.py

@@ -33,13 +33,17 @@ def msg_page(page: int = 1):
                                  show_secret=current_user.check_role("ReadSecretMsg"))  # 判断是否可读取私密内容
     max_page = App.get_max_page(Message.get_msg_count(), 20)
     page_list = App.get_page("docx.docx_page", page, max_page)
-    return render_template("msg/msg.html", msg_list=msg_list, page_list=page_list, form=WriteForm(),
-                           is_secret=DBBit.BIT_1)
+    return render_template("msg/msg.html",
+                           msg_list=msg_list,
+                           page_list=page_list,
+                           form=WriteForm(),
+                           is_secret=DBBit.BIT_1,
+                           show_delete=current_user.check_role("DeleteMsg"))
 
 
 @msg.route('/write', methods=["POST"])
 @login_required
-def write_page():
+def write_msg_page():
     form = WriteForm()
     if form.validate_on_submit():
         auth: User = current_user
@@ -58,6 +62,19 @@ def write_page():
     abort(404)
 
 
+@msg.route('/delete/<int:msg_id>')
+@login_required
+def delete_msg_page(msg_id: int):
+    if not current_user.check_role("DeleteMsg"):
+        abort(403)
+        return
+    if Message(msg_id, None, None).delete():
+        flash("留言删除成功")
+    else:
+        flash("留言删除失败")
+    return redirect(url_for("msg.msg_page", page=1))
+
+
 @msg.context_processor
 def inject_base():
     return {"top_nav": ["", "", "", "active", "", ""]}