def code_submit(): form = SnipUpload(request.form) if request.method == 'POST': name = request.form['name'] if form.validate(): # Save the comment here. flash('Your snippet is submitted successfully') transform_xml(name) flash('Your input snippet:') flash(name) tree, root = prepare_tree('database/Chopin.xml') inputXML = etree.parse('upload.xml') input_root = inputXML.getroot() # print a list of matches to testinput.XML from Chopin.XML flash(search(input_root, tree)) # get a list of artic element that has a staccato articulation element_artic_list = find_artic(tree, 'stacc') # print("-" * 10, "artic elements that has a staccato articulation", "-" * 10) for element in element_artic_list: flash('Element address:') flash(element) flash("is in measure:") flash(get_measure(element)) flash('-------------------------------------') else: flash('All the form fields are required. ') return render_template('frontend_search_test.html', form=form)
def search_terms(tag, para, tree): """ search terms in the database Arguments: tags of term that want to search for para(meters) of tags that want to search for tree of xml base that needed to be searched in Return: rendered result page 'ReChord_result.html' """ if tag == 'Expressive Terms': # todo: do search on expressive terms result = find_artic(tree, para) elif tag == 'Articulation': result = find_expressive_term(tree.root, para) # todo: Integrate more term search # elif tag == 'Tempo Marking': # elif tag == 'Dynamic Marking': # elif tag == 'Piano Fingerings': # elif tag == 'Pedal Marking': # elif tag == 'Hairpin': # elif tag == 'Slur/Ligatures': # elif tag == 'Ornaments': # elif tag == 'Notes': # elif tag == 'Accidental': return render_template('ReChord_result.html', result=result)
def positive_test_find_artic(): """Positive test for find_artic""" _, root = prepare_tree('database/Chopin.xml') element_artic_list = find_artic(root, 'stacc') assert len(element_artic_list) != 0, "find_artic: stacc not found"