prince_corpus route
parent
0aadc12ee7
commit
8e5d857d09
@ -1,26 +1,56 @@
|
|||||||
"helper functions"
|
"""helper functions (is it really usefull?)
|
||||||
|
|
||||||
from flask import abort
|
TODO: maybe all these calculations are to be put in the db storage
|
||||||
|
"""
|
||||||
|
|
||||||
def find_one_or_404(collection, **kwargs):
|
def inverted_prince_bigram(bigram):
|
||||||
"""Find a single document or raise a 404.
|
"Translates ch -> Charles"
|
||||||
|
inverted_prince_bigram = {value: key for key, value in prince_bigram.items()}
|
||||||
|
return inverted_prince_bigram[bigram]
|
||||||
|
|
||||||
This is like :meth:`~pymongo.collection.Collection.find_one`, but
|
|
||||||
rather than returning ``None``, cause a 404 Not Found HTTP status
|
|
||||||
on the request.
|
|
||||||
|
|
||||||
.. code-block:: python
|
def bigram_prince(prince):
|
||||||
|
"Translates Charles_i -> ch_i"
|
||||||
|
name, number = prince.split("_")
|
||||||
|
return prince_bigram[name] + "_" + number
|
||||||
|
|
||||||
usercollection = mydb['usercollection']
|
|
||||||
|
|
||||||
@app.route("/user/<username>")
|
def trigram_house(house):
|
||||||
def user_profile(username):
|
return house_trigram[house]
|
||||||
userfound = find_one_or_404(usercollection, {"_id": username})
|
|
||||||
return render_template("user.html",
|
|
||||||
user=userfound)
|
def make_acteid_from_route(house=None, prince=None, date_and_item=None):
|
||||||
"""
|
"/acte/Anjou/Isabelle_i/1441_08_05a -> anj_isa_i_1441_08_05a"
|
||||||
found = collection.find_one(**kwargs)
|
return "_".join([trigram_house(house), bigram_prince(prince), date_and_item])
|
||||||
if found is None:
|
|
||||||
abort(404)
|
def make_timeitem_from_filename(filename):
|
||||||
return found
|
"""
|
||||||
|
"anj_isa_i_1441_08_05a" -> "1441_08_05a"
|
||||||
|
"""
|
||||||
|
trs_fname = filename.split('_')
|
||||||
|
return "_".join(trs_fname[3:])
|
||||||
|
|
||||||
|
#from flask import abort
|
||||||
|
#
|
||||||
|
#def find_one_or_404(collection, **kwargs):
|
||||||
|
# """Find a single document or raise a 404.
|
||||||
|
#
|
||||||
|
# This is like :meth:`~pymongo.collection.Collection.find_one`, but
|
||||||
|
# rather than returning ``None``, cause a 404 Not Found HTTP status
|
||||||
|
# on the request.
|
||||||
|
#
|
||||||
|
# .. code-block:: python
|
||||||
|
#
|
||||||
|
# usercollection = mydb['usercollection']
|
||||||
|
#
|
||||||
|
# @app.route("/user/<username>")
|
||||||
|
# def user_profile(username):
|
||||||
|
# userfound = find_one_or_404(usercollection, {"_id": username})
|
||||||
|
# return render_template("user.html",
|
||||||
|
# user=userfound)
|
||||||
|
# """
|
||||||
|
# found = collection.find_one(**kwargs)
|
||||||
|
# if found is None:
|
||||||
|
# abort(404)
|
||||||
|
# return found
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue