| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | 
							- from flask import render_template, Blueprint, request, redirect, url_for, jsonify
 
- import requests
 
- from wtforms.compat import iteritems
 
- from backstage.collections.forms import CollectionCreateForm
 
- from backstage.utils import get_now_time
 
- from backstage.utils.routes import create_content, remove_content, get_trans_title_url_name
 
- from backstage.config import PORTAL_SERVER
 
- import json
 
- collections_app = Blueprint('collections', __name__)
 
- @collections_app.route('/backstage/collections')
 
- def collection_list():
 
-     response = requests.get('{}contents?url=/collection'.format(PORTAL_SERVER))
 
-     if response.status_code == 200:
 
-         #sortedData = sorted(response.json(), key='date', reverse=True)        
 
-         #print(len(response))
 
-         #aa = json.loads(response.text)
 
-         sortedData = sorted(response.json(), key=lambda x:x['date'], reverse=True)
 
-         """ i=1
 
-         for d in sortedData:
 
-             if i == 1:
 
-                 print(d)
 
-                 for key, value in d.items():
 
-                     print(key+' '+value)
 
-             i+=1 """
 
-         #print(response.text)
 
-         return render_template('collections.html',
 
-                                title='家具規劃作品',
 
-                                legend='家具規劃作品列表',
 
-                                collections=sortedData,
 
-                                length=len(response.json()),
 
-                                form=CollectionCreateForm())
 
- @collections_app.route('/backstage/collection/create', methods=['POST'])
 
- def create():
 
-     form = CollectionCreateForm()
 
-     eng_name = get_trans_title_url_name(form.title.data)
 
-     front_matter = '''---
 
- title: "{}"\n\
 
- date: {}\n\
 
- draft: {}\n\
 
- type: "{}"\n\
 
- url: "{}"\n\
 
- image: "/img/collection/{}"\n\
 
- description: "{}"\n\
 
- ---'''.format(form.title.data,
 
-               get_now_time(),
 
-               'false',
 
-               'collection',
 
-               '/collection/{}'.format(eng_name),
 
-               form.image.data.filename,
 
-               form.description.data.replace('\r\n','<br>'))
 
-     data = {'frontMatter': front_matter,
 
-             'name': eng_name,
 
-             'type': 'collection'}
 
-     return create_content(data, form.image.data)
 
- @collections_app.route('/backstage/collection/remove', methods=['POST'])
 
- def remove():
 
-     remove_content()
 
-     return redirect(url_for('collections.collection_list'))
 
 
  |