Beispiel #1
0
def get_songs():
    if "author" in request.args:
        data = get_song.get_songs_by_author(request.args["author"])
    elif "name" in request.args:
        data = get_song.get_songs_by_name(request.args["name"])
    elif "start_date" in request.args and "end_date" in request.args:
        start, end = (request.args["start_date"], request.args["end_date"])
        start, end = (datetime.datetime.strptime(start,"%d/%m/%Y"), 
            datetime.datetime.strptime(end,"%d/%m/%Y"))
        data = get_song.get_songs_by_date_range(start , end)
    else:
        print ("getting all")
        data = get_song.get_all_songs()
    return render_template("ajax/songs.html", songs=data)
Beispiel #2
0
def export():
    if "entity_type" not in request.values or request.values[
            "entity_type"] is None or request.values["entity_type"] == "":
        return "entity_type is required", status.HTTP_400_BAD_REQUEST

    entity_type = request.values["entity_type"]
    ALL = "all"
    SONG = "song"
    PHRASE = "phrase"
    GROUP = "group"
    if entity_type not in [ALL, SONG, PHRASE, GROUP]:
        return "unknown entity_type", status.HTTP_400_BAD_REQUEST
    tree = xml_handler.get_base_xml()
    if entity_type == ALL or entity_type == SONG:
        songs = get_song.get_all_songs()
        for song in songs:
            tree.append(xml_handler.dump_song(song))

    if entity_type == ALL or entity_type == PHRASE:
        all_phrases = phrases.get_all_phrases()
        for p in all_phrases:
            tree.append(xml_handler.dump_phrase(p))
    if entity_type == ALL or entity_type == GROUP:
        all_groups = word_groups.get_groups()
        for group in all_groups:
            tree.append(xml_handler.dump_word_group(group))

    buffer = io.StringIO(xml_handler.to_string(tree))
    mem = io.BytesIO()
    mem.write(buffer.getvalue().encode())
    mem.seek(0)
    buffer.close()

    return send_file(mem,
                     as_attachment=True,
                     attachment_filename='export.xml',
                     mimetype='text/xml',
                     cache_timeout=0)
Beispiel #3
0
def word_by_index():
    return render_template("ajax/word_by_index.html", songs=get_song.get_all_songs())
Beispiel #4
0
def get_word_index_form():
    return render_template("ajax/word_index_form.html",songs=get_song.get_all_songs())
Beispiel #5
0
def get_words_in_song_form():
    return render_template("ajax/words_search.html",songs=get_song.get_all_songs())
Beispiel #6
0
def get_phrases():
    all_phrases = phrases.get_all_phrases()
    return render_template("ajax/phrases.html", phrases=all_phrases, songs=get_song.get_all_songs())
Beispiel #7
0
def get_all_songs():
    return jsonify(get_song.get_all_songs())