|
@@ -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'))
|