|
@@ -2,6 +2,7 @@ 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
|
|
|
|
|
|
store_locations_app = Blueprint('store_locations', __name__)
|
|
|
|
|
@@ -18,29 +19,31 @@ def main():
|
|
|
@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
|
|
|
+ for img_src in request.form.getlist('img-{}'.format(idx)):
|
|
|
+ imgs.append(img_src)
|
|
|
+ for f_img in request.files.getlist('image-{}'.format(idx)):
|
|
|
+ img_src = '/img/{}/{}'.format(type_, f_img.filename)
|
|
|
+ requests.post('{}statics/img?type={}&filename={}'.format(
|
|
|
+ PORTAL_SERVER, type_, f_img.filename), files={'image': f_img})
|
|
|
+ imgs.append(img_src)
|
|
|
return imgs
|
|
|
|
|
|
result = []
|
|
|
idx = 1
|
|
|
- while(request.form.get('title-%s' % idx)):
|
|
|
+ for title, type_, store, hour, phone, location, parking in zip(
|
|
|
+ request.form.getlist('title'), request.form.getlist('type'), request.form.getlist('store'),
|
|
|
+ request.form.getlist('hour'), request.form.getlist('phone'),
|
|
|
+ request.form.getlist('location'), request.form.getlist('parking')
|
|
|
+ ):
|
|
|
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),
|
|
|
+ 'title': title, 'type': type_, 'imgs': list(get_imgs()), 'store': store,
|
|
|
+ 'hour': hour, 'phone': phone, 'location': location, 'parking': parking
|
|
|
})
|
|
|
idx += 1
|
|
|
response = requests.post('{}store_locations'.format(PORTAL_SERVER), json=result)
|
|
|
if response.status_code == 200:
|
|
|
+ sleep(1) # waiting for API upload image successfully.
|
|
|
flash('提交成功', 'success')
|
|
|
else:
|
|
|
flash('提交失敗', 'danger')
|