def edit_collection(collectionID): if request.method == 'GET': collection = Collection.get_collection(collectionID) return render_template('edit_collection.html', collection=collection) elif request.method == 'POST': collection = request.form['collection'] authorID = int(request.form['authorID']) introduction = request.form['introduction'] Collection.edit_collection(collection, authorID, introduction, collectionID) return redirect(url_for('single_collection', collectionID=collectionID))
def single_author(author_abbr): author = Author.get_author_by_abbr(author_abbr) if not author: abort(404) quote = Quote.get_quote_by_random(author['AuthorID']) quotes_num = Quote.get_quotes_num_by_author(author['AuthorID']) collections = Collection.get_collections_by_author(author['AuthorID']) works = Work.get_works_by_author(author['AuthorID']) for work in works: work['Content'] = content_clean(work['Content']) # count num of different type work. # return like this - works_num['shi'] = {'type_name': '诗', 'num': 0}. work_types = Work.get_types() works_num = {} for wt in work_types: works_num[wt['WorkType']] = {'type_name': wt['TypeName'], 'num': 0} for work in works: work_type = work['Type'] works_num[work_type]['num'] += 1 return render_template('single_author.html', author=author, quote=quote, quotes_num=quotes_num, collections=collections, works=works, works_num=works_num)
def single_collection(collectionID): collection = Collection.get_collection(collectionID) works = Work.get_works_by_collection(collectionID) for work in works: work['Content'] = re.sub(r'<([^<]+)>', '', work['Content']) work['Content'] = work['Content'].replace('%', '').replace('/', '') return render_template('single_collection.html', collection=collection, works=works)
def get_authors_by_name(): name = request.form['author'] authors = Author.get_authors_by_name(name) for author in authors: author['Collections'] = Collection.get_collections_by_author( author['AuthorID']) return json.dumps(authors)
def get_authors_by_name(): check_admin() name = request.form['author'] authors = Author.get_authors_by_name(name) for author in authors: author['Collections'] = Collection.get_collections_by_author(author['AuthorID']) return json.dumps(authors)
def single_collection(collectionID): collection = Collection.get_collection(collectionID) works = Work.get_works_by_collection(collectionID) for work in works: work['Content'] = content_clean(work['Content']) return render_template('single_collection.html', collection=collection, works=works)
def add_collection(): if request.method == 'GET': return render_template('add_collection.html') elif request.method == 'POST': collection = request.form['collection'] authorID = int(request.form['authorID']) introduction = request.form['introduction'] newCollectionID = Collection.add_collection(collection, authorID, introduction) return redirect(url_for('single_collection', collectionID = newCollectionID))
def single_author(authorID): author = Author.get_author(authorID) collections = Collection.get_collections_by_author(authorID) works = Work.get_works_by_author(authorID) for work in works: work['Content'] = re.sub(r'<([^<]+)>', '', work['Content']) work['Content'] = work['Content'].replace('%', '').replace('/', '') worksNum = Work.get_works_num(works) return render_template('single_author.html', author=author, collections=collections, works=works, worksNum=worksNum)
def get_collections_by_author(): authorID = int(request.form['authorID']) collections = Collection.get_collections_by_author(authorID) return json.dumps(collections)