def get_dynasty_by_json(): check_admin() dynasty_id = int(request.form['dynasty_id']) dynasty = Dynasty.get_dynasty(dynasty_id) authors = Author.get_authors_by_dynasty(dynasty_id) return render_template('single_dynasty.widget', dynasty=dynasty, authors=authors)
def add_quote(author_id): check_admin() quote = request.form['quote'] work_id = int(request.form['work-id']) work_title = Work.get_work(work_id)['Title'] Quote.add(author_id, quote, work_id, work_title) return redirect(url_for('admin_quotes', author_id=author_id))
def admin_widgets(target_type, target_id): check_admin() widgets = Widget.get_widgets(target_type, target_id) return render_template('admin_widgets.html', target_type=target_type, target_id=target_id, widgets=widgets)
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 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 add_collection(): check_admin() 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 edit_quote(quote_id): check_admin() if request.method == 'GET': quote = Quote.get_quote_by_id(quote_id) return render_template('edit_quote.html', quote=quote) elif request.method == 'POST': quote = request.form['quote'] work_id = int(request.form['work-id']) work = Work.get_work(work_id) Quote.edit(quote_id, work['AuthorID'], quote, work['WorkID'], work['Title']) return redirect(url_for('admin_quotes', author_id=work['AuthorID']))
def add_widget(): check_admin() target_type = request.form['target_type'] target_id = int(request.form['target_id']) title = request.form['title'] content = request.form['content'] index = int(request.form['index']) Widget.add_widget(target_type, target_id, title, content, index) return redirect( url_for('admin_widgets', target_type=target_type, target_id=target_id))
def edit_collection(collectionID): check_admin() 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 add_collection(): check_admin() 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 add_dynasty(): check_admin() if request.method == 'GET': return render_template('add_dynasty.html') elif request.method == 'POST': dynasty = request.form['dynasty'] abbr = request.form['abbr'] introduction = request.form['introduction'] startYear = int(request.form['startYear']) endYear = int(request.form['endYear']) Dynasty.add_dynasty(dynasty, abbr, introduction, startYear, endYear) return redirect(url_for('single_dynasty', dynasty_abbr=abbr))
def add_product(): check_admin() if request.method == 'GET': return render_template('add_product.html') elif request.method == 'POST': product = request.form['product'] url = request.form['url'] image_url = request.form['image-url'] introduction = request.form['introduction'] new_product_id = Product.add_product(product, url, image_url, introduction) return redirect(url_for('single_product', product_id=new_product_id))
def edit_product(product_id): check_admin() if request.method == 'GET': product = Product.get_product(product_id) return render_template('edit_product.html', product=product) elif request.method == 'POST': product = request.form['product'] url = request.form['url'] image_url = request.form['image-url'] introduction = request.form['introduction'] Product.edit_product(product_id, product, url, image_url, introduction) return redirect(url_for('single_product', product_id=product_id))
def add_author(): check_admin() if request.method == 'GET': dynasties = Dynasty.get_dynasties() return render_template('add_author.html', dynasties=dynasties) elif request.method == 'POST': author = request.form['author'] abbr = request.form['abbr'] introduction = request.form['introduction'] birthYear = request.form['birthYear'] deathYear = request.form['deathYear'] dynastyID = int(request.form['dynastyID']) Author.add_author(author, abbr, introduction, birthYear, deathYear, dynastyID) return redirect(url_for('single_author', author_abbr=abbr))
def edit_dynasty(dynasty_id): check_admin() if request.method == 'GET': dynasty = Dynasty.get_dynasty(dynasty_id) return render_template('edit_dynasty.html', dynasty=dynasty) elif request.method == 'POST': dynasty = request.form['dynasty'] abbr = request.form['abbr'] introduction = request.form['introduction'] history = request.form['history'] startYear = int(request.form['startYear']) endYear = int(request.form['endYear']) Dynasty.edit_dynasty(dynasty, abbr, introduction, history, startYear, endYear, dynasty_id) return redirect(url_for('single_dynasty', dynasty_abbr=abbr))
def edit_widget(widget_id): check_admin() if request.method == 'GET': widget = Widget.get_widget(widget_id) return render_template('edit_widget.html', widget=widget) elif request.method == 'POST': target_type = request.form['target_type'] target_id = int(request.form['target_id']) title = request.form['title'] content = request.form['content'] index = int(request.form['index']) Widget.edit_widget(widget_id, title, content, index) return redirect( url_for('admin_widgets', target_type=target_type, target_id=target_id))
def add_work(): check_admin() if request.method == 'GET': work_types = Work.get_types() return render_template('add_work.html', work_types=work_types) elif request.method == 'POST': title = request.form['title'] content = request.form['content'] foreword = request.form['foreword'] intro = request.form['introduction'] authorID = int(request.form['authorID']) dynastyID = int(Dynasty.get_dynastyID_by_author(authorID)) collectionID = int(request.form['collectionID']) work_type = request.form['type'] type_name = Work.get_type_name(work_type) new_work_id = Work.add_work(title, content, foreword, intro, authorID, dynastyID, collectionID, work_type, type_name) return redirect(url_for('single_work', work_id=new_work_id))
def search_author_in_collection(): check_admin() name = request.form['author'] authors = Author.get_authors_by_name(name) return json.dumps(authors)
def get_collections_by_author(): check_admin() authorID = int(request.form['authorID']) collections = Collection.get_collections_by_author(authorID) return json.dumps(collections)
def admin_quotes(author_id): check_admin() author = Author.get_author_by_id(author_id) quotes = Quote.get_quotes_by_author(author_id) return render_template('admin_quotes.html', quotes=quotes, author=author)
def delete_quote(quote_id): check_admin() author_id = int(request.args['author_id']) Quote.delete(quote_id) return redirect(url_for('admin_quotes', author_id=author_id))