Преглед на файлове

remove create_content type_input and blog, collection create routes call create_content with input data containing type and category

weichen преди 4 години
родител
ревизия
9fcfec9fa3
променени са 3 файла, в които са добавени 8 реда и са изтрити 7 реда
  1. 3 2
      backstage/blogs/routes.py
  2. 1 1
      backstage/collections/routes.py
  3. 4 4
      backstage/utils/routes.py

+ 3 - 2
backstage/blogs/routes.py

@@ -39,8 +39,9 @@ categories: ["{}"]\n\
               form.categories.data)
     data = {'frontMatter': front_matter,
             'name': request.form['title'],
-            'type': form.categories.data}
-    return create_content(data, form.image.data, 'blog')
+            'type': 'blog',
+            'categories': form.categories.data}
+    return create_content(data, form.image.data)
 
 
 @blogs_app.route('/backstage/blog/remove', methods=['POST'])

+ 1 - 1
backstage/collections/routes.py

@@ -40,7 +40,7 @@ description: "{}"\n\
     data = {'frontMatter': front_matter,
             'name': request.form['title'],
             'type': 'collection'}
-    return create_content(data, form.image.data, 'collection')
+    return create_content(data, form.image.data)
 
 
 @collections_app.route('/backstage/collection/remove', methods=['POST'])

+ 4 - 4
backstage/utils/routes.py

@@ -7,18 +7,18 @@ TYPE_URL_FOR = {'collection': 'collections.collection_list',
                 'blog': 'blogs.blog_list'}
 
 
-def create_content(data, image_data, type_):
+def create_content(data, image_data):
     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={}&filename={}'.format(
-                type_, image_data.filename), files={'image': image_data})
+                data.get('type'), image_data.filename), files={'image': image_data})
         sleep(0.5)  # sleep for waiting for new_content API generating content successfully.
         return redirect(url_for('editor.editor', url='/{}/{}'.format(
-            type_, get_trans_title_url_name(data.get('name')))))
+            data.get('type'), get_trans_title_url_name(data.get('name')))))
     else:
         flash('新增文章失敗', 'danger')
-        return redirect(url_for(TYPE_URL_FOR.get(type_)))
+        return redirect(url_for(TYPE_URL_FOR.get(data.get('type'))))
 
 
 def remove_content():