|
@@ -1,10 +1,8 @@
|
|
-from flask import render_template, Blueprint, flash, request, redirect, url_for
|
|
|
|
|
|
+from flask import render_template, Blueprint, request, redirect, url_for
|
|
import requests
|
|
import requests
|
|
from backstage.collections.forms import CollectionCreateForm
|
|
from backstage.collections.forms import CollectionCreateForm
|
|
-from backstage.utils import translate, get_now_time
|
|
|
|
-from backstage.utils.routes import remove_content
|
|
|
|
-from time import sleep
|
|
|
|
-
|
|
|
|
|
|
+from backstage.utils import get_now_time
|
|
|
|
+from backstage.utils.routes import create_content, remove_content, get_trans_title_url_name
|
|
|
|
|
|
collections_app = Blueprint('collections', __name__)
|
|
collections_app = Blueprint('collections', __name__)
|
|
|
|
|
|
@@ -24,7 +22,6 @@ def collection_list():
|
|
@collections_app.route('/backstage/collection/create', methods=['POST'])
|
|
@collections_app.route('/backstage/collection/create', methods=['POST'])
|
|
def create():
|
|
def create():
|
|
form = CollectionCreateForm()
|
|
form = CollectionCreateForm()
|
|
- url_name = translate(form.title.data).replace(' ', '_')
|
|
|
|
front_matter = '''---
|
|
front_matter = '''---
|
|
title: "{}"\n\
|
|
title: "{}"\n\
|
|
date: {}\n\
|
|
date: {}\n\
|
|
@@ -37,22 +34,13 @@ description: "{}"\n\
|
|
get_now_time(),
|
|
get_now_time(),
|
|
'false',
|
|
'false',
|
|
'collection',
|
|
'collection',
|
|
- '/collection/{}'.format(url_name),
|
|
|
|
|
|
+ '/collection/{}'.format(get_trans_title_url_name(form.title.data)),
|
|
form.image.data.filename,
|
|
form.image.data.filename,
|
|
form.description.data)
|
|
form.description.data)
|
|
data = {'frontMatter': front_matter,
|
|
data = {'frontMatter': front_matter,
|
|
'name': request.form['title'],
|
|
'name': request.form['title'],
|
|
'type': 'collection'}
|
|
'type': 'collection'}
|
|
- new_response = requests.post('http://127.0.0.1:5000/api/new_content', json=data)
|
|
|
|
- if new_response.status_code == 200:
|
|
|
|
- requests.post(
|
|
|
|
- 'http://127.0.0.1:5000/api/upload/static/img?type=collection&filename={}'.format(
|
|
|
|
- form.image.data.filename), files={'image': form.image.data})
|
|
|
|
- sleep(0.5)
|
|
|
|
- return redirect(url_for('editor.editor', url='/collection/{}'.format(url_name)))
|
|
|
|
- else:
|
|
|
|
- flash('新增文章失敗', 'danger')
|
|
|
|
- return redirect(url_for('collections.collection_list'))
|
|
|
|
|
|
+ return create_content(data, form.image.data, 'collection')
|
|
|
|
|
|
|
|
|
|
@collections_app.route('/backstage/collection/remove', methods=['POST'])
|
|
@collections_app.route('/backstage/collection/remove', methods=['POST'])
|