Beispiel #1
0
def rollback(migrator, database, fake=False, **kwargs):
    log.info('Drop all database tables...')
    migrator.remove_model(UserAnswer)
    migrator.remove_model(UserQuiz)
    migrator.remove_model(QuestionChoice)
    migrator.remove_model(Question)
    migrator.remove_model(Quiz)
    migrator.remove_model(QuizCategory)
    migrator.remove_model(User)
    log.info('All database tables dropped. OK')
Beispiel #2
0
def migrate(migrator, database, fake=False, **kwargs):
    log.info('Creating database tables...')
    migrator.create_model(User)
    migrator.create_model(QuizCategory)
    migrator.create_model(Quiz)
    migrator.create_model(Question)
    migrator.create_model(QuestionChoice)
    migrator.create_model(UserQuiz)
    migrator.create_model(UserAnswer)
    log.info('Database tables created. OK')
Beispiel #3
0
 def create(data):
     login = data.get('login', '')
     users = User.select(User.id).where(User.login == login)
     if users.count():
         return Errors.user_is_already_exists(login)
     else:
         User.insert(login=login, password=data.get('password', ''), image=data.get('image', None),
                     is_admin=data.get('is_admin', False)).execute()
         log.info('User create OK. login:{}'.format(login))
     return Errors.no_error()
Beispiel #4
0
 def create(data):
     question = data['question']
     quiz_id = data['quiz_id']
     questions = Question.select(Question.id).where(
         Question.question == question, Question.quiz == quiz_id)
     if questions.count():
         return Errors.question_is_already_exists(question)
     else:
         Question.insert(question=question, quiz_id=quiz_id).execute()
         log.info('Question create OK. question:{}'.format(question))
     return Errors.no_error()
Beispiel #5
0
 def create(data):
     user_id = data['user_id']
     quiz_id = data['quiz_id']
     user_quizzes = UserQuiz.select(UserQuiz.id).where(
         UserQuiz.name == user_id, UserQuiz.quiz == quiz_id)
     if user_quizzes.count():
         return Errors.user_quiz_is_already_exists(user_id, quiz_id)
     else:
         UserQuiz.insert(user_id=user_id, quiz_id=quiz_id).execute()
         log.info('UserQuiz create OK. user_id:{}, quiz_id:{}'.format(
             user_id, quiz_id))
     return Errors.no_error()
Beispiel #6
0
 def create(data):
     name = data['name']
     quizzes = QuizCategory.select(
         QuizCategory.id).where(QuizCategory.name == name)
     if quizzes.count():
         return Errors.quiz_is_already_exists(name)
     else:
         QuizCategory.insert(name=name,
                             image=data.get('image', None),
                             comments=data.get('comments', None)).execute()
         log.info('QuizCategory create OK. name:{}'.format(name))
     return Errors.no_error()
Beispiel #7
0
    def create(data):
        choice = data['choice']
        question_id = data['question_id']
        is_right = data.get('is_right', False)

        question_choices = QuestionChoice.select(QuestionChoice.id).where(
            QuestionChoice.choice == choice,
            QuestionChoice.question == question_id)
        if question_choices.count():
            return Errors.question_choice_is_already_exists(choice)
        else:
            QuestionChoice.insert(choice=choice,
                                  question_id=question_id,
                                  is_right=is_right).execute()
            log.info('Question choice create OK. choice:{}'.format(choice))
        return Errors.no_error()
Beispiel #8
0
 def create(data):
     user_quiz_id = data['user_quiz_id']
     question_choice_id = data['question_choice_id']
     user_answers = UserAnswer.select(UserAnswer.id).where(
         UserAnswer.user_quiz == user_quiz_id,
         Question.question_choice == question_choice_id)
     if user_answers.count():
         return Errors.user_answer_is_already_exists(
             user_quiz_id, question_choice_id)
     else:
         UserAnswer.insert(user_quiz=user_quiz_id,
                           question_choice=question_choice_id).execute()
         log.info(
             'UserAnswer create OK. user_quiz_id:{}, question_choice_id:{}'.
             format(user_quiz_id, question_choice_id))
     return Errors.no_error()
Beispiel #9
0
def main():
    log.info('')
    log.info('Starting...')
    log.info('')

    try:
        log.info('Initializing database...')
        init_db()
        log.info('Database initialized.')

        app = Application(handlers=ApiService.get_handlers(), settings=dict())

        port = SETTINGS_LISTEN.get('port', 8888)
        address = SETTINGS_LISTEN.get('address', '0.0.0.0')
        log.info('Listen on http://{}:{}'.format(address, port))
        app.listen(port, address)
    except Exception as e:
        log.error('Failed to start. {}'.format(e))
        raise

    log.info('')
    log.info('Started.')
    log.info('')
    tornado.ioloop.IOLoop.current().start()