Parcourir la source

add collectionCreateForm and send into collection_list

weichen il y a 4 ans
Parent
commit
3e82ac7d56
2 fichiers modifiés avec 18 ajouts et 2 suppressions
  1. 11 0
      backstage/collections/forms.py
  2. 7 2
      backstage/collections/routes.py

+ 11 - 0
backstage/collections/forms.py

@@ -0,0 +1,11 @@
+from flask_wtf import FlaskForm
+from flask_wtf.file import FileField, FileRequired, FileAllowed
+from wtforms import StringField, TextAreaField
+from wtforms.validators import DataRequired
+
+
+class CollectionCreateForm(FlaskForm):
+    title = StringField('Tilte', validators=[DataRequired()])
+    image = FileField('Image', validators=[
+        FileRequired(), FileAllowed(['jpg', 'png', 'gif', 'webp'], 'Images only!')])
+    description = TextAreaField('Description', validators=[DataRequired()])

+ 7 - 2
backstage/collections/routes.py

@@ -1,5 +1,6 @@
 from flask import render_template, Blueprint
 import requests
+from backstage.collections.forms import CollectionCreateForm
 
 
 collections_app = Blueprint('collections', __name__)
@@ -9,5 +10,9 @@ collections_app = Blueprint('collections', __name__)
 def collection_list():
     response = requests.get('http://127.0.0.1:5000/api/contents?url=/collection')
     if response.status_code == 200:
-        return render_template(
-            'collections.html', title='家具規劃作品', legend='家具規劃作品列表', collections=response.json(), length=len(response.json()))
+        return render_template('collections.html',
+                               title='家具規劃作品',
+                               legend='家具規劃作品列表',
+                               collections=response.json(),
+                               length=len(response.json()),
+                               form=CollectionCreateForm())