Bladeren bron

add store_locations main route and create route

weichen 4 jaren geleden
bovenliggende
commit
3b36596bb4
2 gewijzigde bestanden met toevoegingen van 81 en 0 verwijderingen
  1. 23 0
      backstage/store_locations/manage_table copy 2.html
  2. 58 0
      backstage/store_locations/routes.py

+ 23 - 0
backstage/store_locations/manage_table copy 2.html

@@ -0,0 +1,23 @@
+{% extends "layout.html" %}
+{% block main %}
+<h1>{{ title }}</h1>
+{% for content in contents %}
+<div>
+<form action="{{ url_for(form_url, page=page, section_class=content.sectionClass) }}" method="POST" enctype="multipart/form-data">
+  <table id="example" class="table table-striped table-bordered" cellspacing="0" width="60%">
+    <thead>
+      <tr>
+        <th>數量</th>
+        <th>類型</th>
+        <th>內容</th>
+        <th style="text-align:center;width:100px;">
+            <input class="btn btn-primary" type="submit" value="提交">
+        </th>
+      </tr>
+    </thead>
+    {{ table_bodys|safe }}
+  </table>
+</form>
+</div>
+{% endfor %}
+{% endblock main %}

+ 58 - 0
backstage/store_locations/routes.py

@@ -0,0 +1,58 @@
+from flask import render_template, Blueprint, request, redirect, url_for, flash
+import requests
+from backstage.config import PORTAL_SERVER
+from os import path
+
+store_locations_app = Blueprint('store_locations', __name__)
+
+
+@store_locations_app.route('/backstage/store_location')
+def main():
+    response = requests.get('{}store_locations'.format(PORTAL_SERVER))
+    return render_template('store_location.html',
+                           title='門市據點',
+                           page='store_location',
+                           stores_data=response.json())
+
+
+@store_locations_app.route('/backstage/store_locations/create', methods=['POST'])
+def create():
+    def get_imgs():
+        i_idx = 1
+        imgs = []
+        while(request.form.get('img-%s' % i_idx)):
+            imgs.append(request.form.get('img-%s' % i_idx))
+            i_idx += 1
+        return imgs
+
+    result = []
+    idx = 1
+    while(request.form.get('title-%s' % idx)):
+        result.append({
+            'title': request.form.get('title-%s' % idx),
+            'type': request.form.get('type-%s' % idx),
+            'imgs': get_imgs(),
+            'store': request.form.get('store-%s' % idx),
+            'hour': request.form.get('hour-%s' % idx),
+            'phone': request.form.get('phone-%s' % idx),
+            'location': request.form.get('location-%s' % idx),
+            'parking': request.form.get('parking-%s' % idx),
+        })
+        idx += 1
+    response = requests.post('{}store_locations'.format(PORTAL_SERVER), json=result)
+    if response.status_code == 200:
+        flash('提交成功', 'success')
+    else:
+        flash('提交失敗', 'danger')
+    return redirect(url_for('store_locations.main'))
+
+
+@store_locations_app.route('/backstage/store_locations/remove_img', methods=['GET'])
+def remove_img():
+    response = requests.delete('{}statics/img?type={}&filename={}'.format(
+        PORTAL_SERVER, request.args.get('type'), path.basename(request.args.get('src'))))
+    if response.status_code == 200:
+        flash('移除照片成功', 'success')
+    else:
+        flash('移除照片失敗', 'danger')
+    return redirect(url_for('store_locations.main'))