Exemplo n.º 1
0
def new_concept(context_id=None):
    if request.method == 'POST':
        text = request.form['concept_name']
        if text.strip() == "":
            return render_template('add_concept.html', \
                                   context_id=context_id, \
                                   error="Concept cannot be blank.")
        # TODO(a33kuo): Should be replaced by get_or_create() method.
        concept = Concept.get_concept(text, session['user_language'])
        if concept is None:
            concept = Concept(text, session['user_language'])
            concept.add()
        context = Context.get_context(context_id)
        concept.add_context(context)
        if context_id is not None:
            return redirect('/context/' + context_id)
        else:
            return redirect('/context/')
    else:
        return render_template('add_concept.html', context_id=context_id)