コード例 #1
0
ファイル: passage.py プロジェクト: vishal9565/speed_reading
def create_passage(name):
    """

    :param name:
    :return:
    """
    exec_rec = Passage.query.filter(
        Passage.name == name.encode("utf-8")).one_or_none()
    if exec_rec:
        raise AppError(*ERROR_DUPLICATE_PASSAGE_TITLE)
    passage = Passage()
    passage.name = name
    with transactional_session() as sess:
        sess.add(passage)
コード例 #2
0
ファイル: passage.py プロジェクト: vishal9565/speed_reading
def create_answer(question_id, option_id):
    """

    :param question_id:
    :param option_id:
    :return:
    """
    answer_obj = Answer()
    answer_obj.question_id = question_id
    answer_obj.option_id = option_id
    try:
        with transactional_session() as sess:
            sess.add(answer_obj)
    except:
        raise AppError(*ERROR_MULTIPLE_OPTION_CREATE)
コード例 #3
0
ファイル: passage.py プロジェクト: vishal9565/speed_reading
def create_multiple_option(question_id, option_text):
    """

    :param question_id:
    :param option_id:
    :param option_text:
    :return:
    """
    multi_obj = MultipleOption()
    multi_obj.question_id = question_id
    multi_obj.option_text = option_text
    try:
        with transactional_session() as sess:
            sess.add(multi_obj)
    except:
        raise AppError(*ERROR_MULTIPLE_OPTION_CREATE)
コード例 #4
0
ファイル: passage.py プロジェクト: vishal9565/speed_reading
def create_question(passage_id, question):
    """

    :param passage_id:
    :param question:
    :return:
    """
    question_obj = Question()
    question_obj.passage_id = passage_id
    question_obj.question = question

    try:
        with transactional_session() as sess:
            sess.add(question_obj)
    except:
        raise AppError(*ERROR_QUESTION_CREATE)
コード例 #5
0
ファイル: passage.py プロジェクト: vishal9565/speed_reading
def create_paragraph(**kwargs):
    """
    create the Paragraph entity
    :param kwargs: dictionary containing the fields about the paragraph entity
    :type kwargs: dict

    :return: None if adding succeed else dictionary containing {"overwrite":true}
    :rtype Union[None,dict]
    """

    para = Paragraph()
    para.passage_id = kwargs["passage_id"]
    para.paragraph = kwargs["paragraph"].encode("utf-8")
    try:
        with transactional_session() as sess:
            sess.add(para)
    except:
        raise AppError(*ERROR_PARAGRAPH_CREATE)