|
@@ -4,17 +4,18 @@ from time import sleep
|
|
|
from backstage.utils import translate
|
|
|
from collections import defaultdict
|
|
|
from os import path
|
|
|
+from backstage.config import PORTAL_SERVER
|
|
|
|
|
|
TYPE_URL_FOR = {'collection': 'collections.collection_list',
|
|
|
'blog': 'blogs.blog_list'}
|
|
|
|
|
|
|
|
|
def create_content(data, image_data):
|
|
|
- new_response = requests.post('http://127.0.0.1:5000/api/new_content', json=data)
|
|
|
+ new_response = requests.post('{}new_content'.format(PORTAL_SERVER), json=data)
|
|
|
if new_response.status_code == 200:
|
|
|
requests.post(
|
|
|
- 'http://127.0.0.1:5000/api/upload/static/img?type={}&filename={}'.format(
|
|
|
- data.get('type'), image_data.filename), files={'image': image_data})
|
|
|
+ '{}upload/static/img?type={}&filename={}'.format(
|
|
|
+ PORTAL_SERVER, data.get('type'), image_data.filename), files={'image': image_data})
|
|
|
sleep(1) # sleep for waiting for new_content API generating content successfully.
|
|
|
return redirect(url_for('editor.editor', url='/{}/{}'.format(
|
|
|
data.get('type'), get_trans_title_url_name(data.get('name')))))
|
|
@@ -25,7 +26,7 @@ def create_content(data, image_data):
|
|
|
|
|
|
def remove_content():
|
|
|
url = request.args.get('url', type=str)
|
|
|
- response = requests.delete('http://127.0.0.1:5000/api/contents?url={}'.format(url))
|
|
|
+ response = requests.delete('{}contents?url={}'.format(PORTAL_SERVER, url))
|
|
|
if response.status_code == 200:
|
|
|
flash('刪除文章成功', 'success')
|
|
|
else:
|
|
@@ -58,14 +59,14 @@ def update_manage_table(forms, req_args, files, img_type):
|
|
|
flash('上傳圖片失敗,副檔名必須為:{}'.format(ALLOWED_EXTENSIONS), 'danger')
|
|
|
continue
|
|
|
requests.post(
|
|
|
- 'http://127.0.0.1:5000/api/upload/static/img?type={}&filename={}'.format(
|
|
|
- img_type, f_value.filename), files={'image': f_value})
|
|
|
+ '{}upload/static/img?type={}&filename={}'.format(
|
|
|
+ PORTAL_SERVER, img_type, f_value.filename), files={'image': f_value})
|
|
|
img_index = int(f_key.split('-')[-1])-1
|
|
|
update_data['img'][img_index]['src'] = path.join(
|
|
|
path.split(update_data['img'][img_index]['src'])[0], f_value.filename)
|
|
|
response = requests.post(
|
|
|
- 'http://127.0.0.1:5000/api/manages/data?page={}§ion={}'.format(
|
|
|
- req_args.get('page'), req_args.get('section_class')), json=update_data)
|
|
|
+ '{}manages/data?page={}§ion={}'.format(
|
|
|
+ PORTAL_SERVER, req_args.get('page'), req_args.get('section_class')), json=update_data)
|
|
|
if response.status_code == 200:
|
|
|
sleep(1) # waiting for API upload image successfully.
|
|
|
flash('修改成功', 'success')
|