Browse Source

add blogs page show the blog list

weichen 4 năm trước cách đây
mục cha
commit
11a181e490
3 tập tin đã thay đổi với 51 bổ sung3 xóa
  1. 13 0
      backstage/blogs/routes.py
  2. 3 3
      backstage/collections/routes.py
  3. 35 0
      backstage/templates/blogs.html

+ 13 - 0
backstage/blogs/routes.py

@@ -0,0 +1,13 @@
+from flask import render_template, Blueprint
+import requests
+
+
+blogs_app = Blueprint('blogs', __name__)
+
+
+@blogs_app.route('/backstage/blogs')
+def blog_list():
+    response = requests.get('http://127.0.0.1:5000/api/contents?url=/blog')
+    if response.status_code == 200:
+        return render_template(
+            'blogs.html', title='設計專欄', legend='設計專欄列表', blogs=response.json(), length=len(response.json()))

+ 3 - 3
backstage/collections/routes.py

@@ -7,7 +7,7 @@ collections_app = Blueprint('collections', __name__)
 
 @collections_app.route('/backstage/collections')
 def collection_list():
-    collections = requests.get('http://127.0.0.1:5000/api/contents?url=/collection')
-    if collections.status_code == 200:
+    response = requests.get('http://127.0.0.1:5000/api/contents?url=/collection')
+    if response.status_code == 200:
         return render_template(
-            'collections.html', title='家具規劃作品', legend='家具規劃作品列表', collections=collections.json())
+            'collections.html', title='家具規劃作品', legend='家具規劃作品列表', collections=response.json(), length=len(response.json()))

+ 35 - 0
backstage/templates/blogs.html

@@ -0,0 +1,35 @@
+{% extends "layout.html" %}
+{% block main %}
+<h1>{{ title }}</h1>
+<table id="example" class="table table-striped table-bordered" cellspacing="0" width="60%">
+  <thead>
+    <tr>
+      <th>數量</th>
+      <th>標題</th>
+      <th>順序</th>
+      <th>顯示</th>
+      <th style="text-align:center;width:100px;">新增 <button type="button" data-func="dt-add" class="btn btn-success btn-xs dt-add">
+          <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
+        </button></th>
+    </tr>
+  </thead>
+  {% for idx in range(0, length) %}
+    <tbody>
+      <tr>
+        <td>{{ idx }}</td>
+        <td>{{ blogs[idx].title }}</td>
+        <td>1</td>
+        <td>on</td>
+        <td>
+          <div>
+            <a class="btn btn-secondary btn-sm m-1" href="{{ url_for('editor.editor', url=blogs[idx].url) }}">編輯</a>
+            <form action="{{ url_for('editor.remove', url=blogs[idx].url) }}" method="POST">
+              <input class="btn btn-danger" type="submit" value="Delete">
+            </form>
+          </div>
+        </td>
+      </tr>
+    </tbody>
+  {% endfor %}
+</table>
+{% endblock main %}