示例#1
0
def get_author_details():
    if request.method == 'GET':
        author_id = request.args.get('author_id')
        doc_num = request.args.get('doc_num')

        if author_id is None and doc_num is None:
            return render_template('data_visualize/select_author.html',
                                   title='Select an author',
                                   content=u'Select an author in the following list and the system will display the '
                                           u'details of that author you selected',
                                   authors_list=data_warehouse.get_all_author_id_and_name()
                                   )

    if request.method == 'POST':
        try:
            author_id = int(request.form['author_id'])
            doc_num = data_warehouse.get_num_of_doc_written_by_an_author(author_id)
        except ValueError:
            abort(403)

    try:
        author_id = int(author_id)
        doc_num = int(doc_num)
    except ValueError:
        abort(403)

    author_name = data_warehouse.get_author_name_by_id(author_id)
    return render_template('data_visualize/author_details.html',
                           title=author_name,
                           content=Markup(u'You are now looking at <strong>{}</strong>. There are <strong>{}</strong> '
                                          u'of documents written by {} stored in our database.'
                                          .format(author_name, doc_num, author_name)),
                           doc_list=data_warehouse.get_all_docs_by_author_id(author_id)
                           )
def get_author_details():
    if request.method == 'GET':
        author_id = request.args.get('author_id')
        doc_num = request.args.get('doc_num')

        if author_id is None and doc_num is None:
            return render_template('data_visualize/select_author.html',
                                   title='Select an author',
                                   content=u'Select an author in the following list and the system will display the '
                                           u'details of that author you selected',
                                   authors_list=data_warehouse.get_all_author_id_and_name()
                                   )

    if request.method == 'POST':
        try:
            author_id = int(request.form['author_id'])
            doc_num = data_warehouse.get_num_of_doc_written_by_an_author(author_id)
        except ValueError:
            abort(403)

    try:
        author_id = int(author_id)
        doc_num = int(doc_num)
    except ValueError:
        abort(403)

    author_name = data_warehouse.get_author_name_by_id(author_id)
    return render_template('data_visualize/author_details.html',
                           title=author_name,
                           content=Markup(u'You are now looking at <strong>{}</strong>. There are <strong>{}</strong> '
                                          u'of documents written by {} stored in our database.'
                                          .format(author_name, doc_num, author_name)),
                           doc_list=data_warehouse.get_all_docs_by_author_id(author_id)
                           )
示例#3
0
def return_doc_list():
    if request.method != 'POST':
        abort(403)

    try:
        author_id = int(request.form['author_id'])
    except ValueError:
        abort(403)

    # x, y, z refers to doc_id, doc_title and year_of_pub respectively
    doc_list = [(x, y) for x, y, z in data_warehouse.get_all_docs_by_author_id(author_id)]
    return jsonify(doc_list)
def return_doc_list():
    if request.method != 'POST':
        abort(403)

    try:
        author_id = int(request.form['author_id'])
    except ValueError:
        abort(403)

    # x, y, z refers to doc_id, doc_title and year_of_pub respectively
    doc_list = [(x, y) for x, y, z in data_warehouse.get_all_docs_by_author_id(author_id)]
    return jsonify(doc_list)