Bläddra i källkod

add store_locations with remove feature

weichen 4 år sedan
förälder
incheckning
b29f2fa5cf
2 ändrade filer med 15 tillägg och 3 borttagningar
  1. 14 2
      backstage/store_locations/routes.py
  2. 1 1
      backstage/templates/store_location.html

+ 14 - 2
backstage/store_locations/routes.py

@@ -1,8 +1,10 @@
 from flask import render_template, Blueprint, request, redirect, url_for, flash
 import requests
-from backstage.config import PORTAL_SERVER
 from os import path
 from time import sleep
+from backstage.utils import translate
+from backstage.config import PORTAL_SERVER
+from backstage.utils.routes import remove_content
 
 store_locations_app = Blueprint('store_locations', __name__)
 
@@ -29,6 +31,9 @@ def create():
             imgs.append(img_src)
         return imgs
 
+    def get_district_name():
+        return translate(title.replace('門市', '')).lower().replace(' ', '_')
+
     result = []
     idx = 1
     for title, type_, store, hour, phone, location, parking in zip(
@@ -38,7 +43,8 @@ def create():
     ):
         result.append({
             'title': title, 'type': type_, 'imgs': list(get_imgs()), 'store': store,
-            'hour': hour, 'phone': phone, 'location': location, 'parking': parking
+            'hour': hour, 'phone': phone, 'location': location, 'parking': parking,
+            'url': '/{}/bhouse_store_in_{}_city'.format(type_, get_district_name())
         })
         idx += 1
     response = requests.post('{}store_locations'.format(PORTAL_SERVER), json=result)
@@ -59,3 +65,9 @@ def remove_img():
     else:
         flash('移除照片失敗', 'danger')
     return redirect(url_for('store_locations.main'))
+
+
+@store_locations_app.route('/backstage/store_locations/remove', methods=['POST'])
+def remove():
+    remove_content()
+    return redirect(url_for('store_locations.main'))

+ 1 - 1
backstage/templates/store_location.html

@@ -56,7 +56,7 @@
                 <button type="button" class="btn__edit  m-2">
                   <i class="fas fa-edit"></i>
                 </button>
-                <form action="#" method="POST">
+                <form action="{{ url_for('store_locations.remove', url=store.url) }}" method="POST">
                   <button class="btn__delete m-1" type="submit" value="delete"><i class="fas fa-trash-alt"></i></button>
                 </form>
                 <div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="updateModalLabel" aria-hidden="true">