Beispiel #1
0
def edit_vocab_word(word_id):

    word = VocabWord.get_by_id(word_id)
    form = VocabWordForm(obj=word)
    form.source_code.choices = Language.get_all_options()
    if form.validate_on_submit():

        source_code = form.source_code.data
        root = form.root.data
        translation = form.translation.data
        definition = form.definition.data
        synonyms = form.synonyms.data
        examples = form.examples.data
        notes = form.notes.data

        update_vocab_word = word.update(source_code,
                                        root, translation, definition, synonyms, examples, notes)

        g.user.update_last_language(source_code)

        flash(f"{update_vocab_word.root} edited!", 'success')
        return redirect(f"/words/{update_vocab_word.id}")

    else:
        flash(f"Error updating vocabulary word!", 'warning')
        return render_template('edit_vocab_word.html', vocab_word_form=form, word=word)
Beispiel #2
0
def add_new_variation_by_api():

    current_user = get_jwt_identity()
    user = User.get_by_id(current_user)

    form = VocabWordAndComponentForm()
    form.source_code.choices = Language.get_all_options()
    if form.validate():

        root_id = request.json['root_id']
        user_id = user.id
        part_of_speech = request.json['part_of_speech']
        word = request.json['word']
        translation = request.json['translation']
        examples = request.json['examples']

        new_component = VocabWordComponent.add_variation(
            root_id, user_id, part_of_speech, word, translation, examples)

        response = {
            'component': new_component.serialize(),
            'status': 'success'
        }
        return jsonify(response)

    else:
        response = {
            'errors': form.errors,
            'status': 'errors'
        }
        return jsonify(response)
Beispiel #3
0
def view_user_words(source_code):

    languages = Language.get_all_options()
    sorted_words = db.session.query(VocabWord).filter(
        VocabWord.owner_id == g.user.id, VocabWord.source_code == source_code).order_by(VocabWord.root).all()

    return render_template('words.html', languages=languages, words=sorted_words, source_code=source_code)
Beispiel #4
0
def show_vocab_word(word_id):

    word = VocabWord.get_by_id(word_id)
    components = word.components
    parts_of_speech = word.components_pos()
    print(f"POS: {parts_of_speech}", file=sys.stderr)

    vocab_word_form = VocabWordForm(obj=word)
    vocab_word_form.source_code.choices = Language.get_all_options()

    vocab_component_form = VocabComponentForm()

    return render_template('view_vocab_word.html', vocab_word_form=vocab_word_form, vocab_component_form=vocab_component_form, word=word, components=components, parts_of_speech=parts_of_speech)
Beispiel #5
0
def add_new_word_by_api():

    current_user = get_jwt_identity()
    user = User.get_by_id(current_user)

    form = VocabWordAndComponentForm()
    form.source_code.choices = Language.get_all_options()
    if form.validate():

        user_id = user.id
        source_code = request.json['source_code']
        part_of_speech = request.json['part_of_speech']
        word = request.json['word']
        translation = request.json['translation']
        definition = request.json['definition']
        synonyms = request.json['synonyms']
        examples = request.json['examples']

        if definition == '0':
            definition = ''

        new_word = VocabWord.add_vocab_word(
            user_id, source_code, word, translation, definition, synonyms, examples, '')

        print(f"ROOT_ID: {new_word.id}", file=sys.stderr)

        new_component = VocabWordComponent.add_variation(
            new_word.id, user_id, part_of_speech, word, translation, examples)

        response = {
            'word': new_word.serialize(),
            'status': 'success'
        }
        return jsonify(response)

    else:
        response = {
            'errors': form.errors,
            'status': 'errors'
        }
        return jsonify(response)
Beispiel #6
0
def add_vocab_word():

    form = VocabWordForm()
    form.source_code.choices = Language.get_all_options()
    if form.validate_on_submit():

        source_code = form.source_code.data
        root = form.root.data
        translation = form.translation.data
        definition = form.definition.data
        synonyms = form.synonyms.data
        examples = form.examples.data
        notes = form.notes.data

        new_vocab_word = VocabWord.add_vocab_word(
            session[CURR_USER_ID], source_code, root, translation, definition, synonyms, examples, notes)

        g.user.update_last_language(source_code)

        flash(f"{new_vocab_word.root} created!", 'success')
        return redirect(f"/words/{new_vocab_word.id}")

    else:
        return render_template('new_vocab_word.html', vocab_word_form=form)
Beispiel #7
0
def show_study_material():
    languages = Language.get_all_options()
    return render_template('study_material.html', languages=languages, parts_of_speech=PARTS_OF_SPEECH)