コード例 #1
0
 def delete(self, id):
     q = Questions.get(id=id)
     if q:
         if q.teacher:
             q.teacher = q.teacher.__dict__
         r = q.__dict__
         q.delete()
         return r, 200
コード例 #2
0
 def get(self, id):
     q = Questions.get(id=id)
     if q:
         if q.teacher:
             q.teacher = q.teacher.__dict__
             q.teacher['full_name'] = '{} {}'.format(
                 q.teacher['name'], q.teacher['surname'])
         return q.__dict__
     return {}, 404
コード例 #3
0
ファイル: referer.py プロジェクト: XinMa1/work
    def answnerAdd(self):
        inputParams = self.getInput()
        qID = inputParams['question']
        question = Questions.get(Questions.id == qID)
        
        current_user = Users.get(Users.name == self.isLogin())
        if not self.isAdmin() or question.group.owner != current_user:
            return self.error(msg = '权限不足!', url=self.makeUrl('/admin/questions/list'))
        
        self.privData['QUESTION'] = question

        return self.display('answnerAdd')
コード例 #4
0
 def put(self, id):
     args = self.parser.parse_args()
     q = Questions.get(id=id)
     if q and args:
         if args.get('teacher'):
             t = Users.get(email=args.get('teacher', {}).get('email'))
             args['teacher'] = t.id
             if not t:
                 args['teacher'] = None
         q.update(**args)
         return q.__dict__
     return {}, 404
コード例 #5
0
ファイル: referer.py プロジェクト: XinMa1/work
 def questions(self):
     try:
         #import pdb;pdb.set_trace()
         questionList = Questions.select().order_by(Questions.id.desc())
         Listtemp=[]
         for item in questionList:
             length = Answers.select().where(item.id ==Answers.question).count()
             Listtemp.append([item,length])
         self.privData['QUESTIONS_LIST'] = Listtemp
         return self.display('questions-list')
     except Exception,e:
         print e
         return self.error(msg='获取问题列表信息失败!')
コード例 #6
0
ファイル: referer.py プロジェクト: XinMa1/work
 def question_details(self):
     inputs = self.getInput()
     try:
         #import pdb;pdb.set_trace()
         question = Questions.get(Questions.id == inputs['id'])
         self.privData['QUESTION_DETAIL'] =question
         albumList = Albums.select().where(Albums.question ==inputs['id'])
         self.privData['ALUBUM'] =albumList
         answersList=Answers.select().where(Answers.question ==inputs['id'])
         self.privData['ANSWERS_LIST'] =answersList
         return self.display('question-details')
     except Exception, e:
         return self.error(msg='获取问题详情失败!')
コード例 #7
0
ファイル: referer.py プロジェクト: XinMa1/work
 def answners(self):
     inputParams = self.getInput()
     qID = inputParams['id']
     page = int(inputParams['page']) if inputParams.has_key('page') else 1
     count = config.COUNT_PER_PAGE
     question = Questions.get(Questions.id == qID)
     answnersList = Answners.select().where(Answners.question == qID)
     answnersList = answnersList.order_by(Answners.id.desc())
     pageString = self.getPageStr(self.makeUrl('/admin/answners/list', {'id': qID}), page, count, answnersList.count()) 
     self.privData['ANSWNERS_LIST'] = answnersList.paginate(page, count)
     self.privData['PAGE_STRING'] = pageString
     self.privData['QUESTION'] = question
     return self.display('answnersList')
コード例 #8
0
 def post(self):
     args = self.parser.parse_args()
     if args:
         if args.get('teacher'):
             t = Users.get(email=args.get('teacher', {}).get('email'))
             args['teacher'] = t
             if not t:
                 args['teacher'] = None
         q = Questions.create(**args)
         if q.teacher:
             q.teacher = q.teacher.__dict__
         return q.__dict__
     return {}, 404
コード例 #9
0
ファイル: referer.py プロジェクト: XinMa1/work
 def answnersSearch(self):
     inputParams = self.getInput()
     keywords = inputParams['keywords'].strip().lower() if inputParams.has_key('keywords') else ''
     page = int(inputParams['page']) if inputParams.has_key('page') else 1
     qID = int(inputParams['qid'])
     count = config.COUNT_PER_PAGE
     question = Questions.get(Questions.id == qID)
     answnersList = Answners.select().where(Answners.question == qID and Answners.content.contains(keywords))
     answnersList = answnersList.order_by(Answners.id.desc())
     pageString = self.getPageStr(self.makeUrl('/admin/questions/answners', {'id': qID}), page, count, answnersList.count())
     self.privData['ANSWNERS_LIST'] = answnersList.paginate(page, count)
     self.privData['PAGE_STRING'] = pageString
     self.privData['QUESTION'] = question
     return self.display('answnersList')
コード例 #10
0
    def get_all_questions_for_quiz(quiz_id):
        sql = "Select * from questions where quiz_id=%s"
        cursor = connection.cursor()
        cursor.execute(sql, [quiz_id])
        records = cursor.fetchall()
        questions = []

        for record in records:
            question: Questions = Questions(id=record[0],
                                            description=record[2])
            question.answers = AnswersDaoImpl.get_all_answers_for_question(
                question.id)
            questions.append(question)
        return questions
コード例 #11
0
 def get(self):
     qs = Questions.filter()
     if qs:
         r = []
         for q in qs:
             feedbacks = q.get_feedbacks()
             if q.teacher:
                 q.teacher = q.teacher.__dict__
                 q.teacher['full_name'] = '{} {}'.format(
                     q.teacher['name'], q.teacher['surname'])
             q = q.__dict__
             q['feedbacks'] = feedbacks
             r.append(q)
         return r, 200
     return {}, 404
コード例 #12
0
ファイル: referer.py プロジェクト: XinMa1/work
    def list(self):
        inputParams = self.getInput()
        page = int(inputParams['page']) if inputParams.has_key('page') else 1
        count = config.COUNT_PER_PAGE

        questionsList = Questions.select()
        current_user = Users.get(Users.name == self.isLogin())
        if not self.isAdmin():
            questionsList = current_user.questions_owner
        questionsList = questionsList.order_by(Questions.id.desc())
        pageString = self.getPageStr(self.makeUrl('/admin/agents/list'), page, count, questionsList.count())

        self.privData['QUESTIONS_LIST'] = questionsList.paginate(page, count)
        self.privData['PAGE_STRING'] = pageString

        return self.display('questionsList')
コード例 #13
0
ファイル: referer.py プロジェクト: XinMa1/work
    def answnerSave(self):
        userInput = self.getInput()
        try:
            qID = int(userInput['question'])
            question = Questions.get(Questions.id == qID)
            current_user = Users.get(Users.name == self.isLogin())
            if not self.isAdmin() or question.group.owner != current_user:
                return self.error(msg = '权限不足!', url=self.makeUrl('/admin/questions/answners', {'id': qID}))

            Answners.create(
                question = question,
                owner = current_user,
                content = userInput['content']
            )

        except Exception, e:
            return self.error(msg = '新增回答失败: %s' % e, url=self.makeUrl('/admin/questions/list'))
コード例 #14
0
ファイル: referer.py プロジェクト: XinMa1/work
    def search(self):
        inputParams = self.getInput()
        keywords = inputParams['keywords'].strip().lower() if inputParams.has_key('keywords') else ''
        page = int(inputParams['page']) if inputParams.has_key('page') else 1
        count = config.COUNT_PER_PAGE

        current_user = Users.get(Users.name == self.isLogin())
        questionsList = Questions.select().where(Questions.title.contains(keywords))
        if not self.isAdmin():
            questionsList = current_user.questions_owner
        questionsList = questionsList.order_by(Questions.id.desc())
        pageString = self.getPageStr(self.makeUrl('/admin/questions/list'), page, count, questionsList.count())

        self.privData['QUESTIONS_LIST'] = questionsList.paginate(page, count)
        self.privData['PAGE_STRING'] = pageString

        return self.display('questionsList')
コード例 #15
0
ファイル: referer.py プロジェクト: XinMa1/work
 def raise_question(self):
     inputs = web.input()
     user =Users.get(Users.name == self.isLogin())
     self.desc = '提问上传图片'
     self.ref = ''
     try:
         title = inputs['title']
         content =inputs['content']
         imgfilelst=[]
         imageslst=[]
         imgfilelst.append(inputs['imgfile1'])
         imgfilelst.append(inputs['imgfile2'])
         imgfilelst.append(inputs['imgfile3'])
         for item in imgfilelst:
             try:
                 if len(item)>10:
                     htmlimg = httpUploadedFile(item)
                     imageslst.append([htmlimg.uuid(),self.wap_imgsave(htmlimg)])
                 else:
                     imageslst.append(["default",Images().get(Images.id == 1).thumbnail])
             except Exception, e:
                 imageslst.append(["default",Images().get(Images.id == 1).thumbnail])
         
         self.privData['USER'] = user
         question = Questions.create(
             title = title,
             content = content,
             owner = user,
             uuid1=imageslst[0][0],
             uuid2=imageslst[1][0],
             uuid3=imageslst[2][0],
             img1=imageslst[0][1],
             img2=imageslst[1][1],
             img3=imageslst[2][1]
             
         )
         question.save()
         return self.questions()
コード例 #16
0
import unittest
from unittest.mock import MagicMock

from models.questions import Questions
from daos.questions_dao import QuestionsDAO
from daos.daos_impl.questions_dao_impl import QuestionDaoImpl
from service.questions_services import QuestionsServices

from models.quizzes import Quizzes
from daos.quizzes_dao import QuizesDAO
from daos.daos_impl.quizzes_dao_impl import QuizzesDaoImpl
from service.quiz_service import QuizService

question = Questions(1, 1, 'What is the speed of light?')
question2 = Questions(0, 'What is a test')
questions = [question, question2]
quiz = Quizzes(1, 'Light Quiz', 1)

mock_question_dao = QuestionDaoImpl()
mock_question_dao.get_all_questions_for_quiz = MagicMock(
    return_value=questions)
mock_quizzes_dao = QuizzesDaoImpl()
mock_quizzes_dao.get_quiz = MagicMock(return_value=quiz)

questions_service = QuestionsServices()


class QuestionsTest(unittest.TestCase):
    def test_service_get_all_questions_for_quiz(self):
        retrieved_question = questions_service.get_all_questions(quiz.id)
        assert all(retrieved_question)
コード例 #17
0
ファイル: answer_dao_test.py プロジェクト: VanVelZ/quiz-maker
import unittest
from models.answers import Answers
from daos.answers_dao import AnswersDAO
from daos.daos_impl.answers_dao_impl import AnswersDaoImpl

from models.questions import Questions
from daos.questions_dao import QuestionsDAO
from daos.daos_impl.questions_dao_impl import QuestionDaoImpl

answer_dao = AnswersDaoImpl()
question_dao = QuestionDaoImpl()

test_answer = Answers(0, 'Test answer', False)
test_question = Questions(1, 1, 'What is the speed of light?')


class AnswerTest(unittest.TestCase):
    def test_get_all_answers_for_question(self):
        retrieved_answer = answer_dao.get_all_answers_for_question(
            test_question.id)
        assert all(retrieved_answer)

    def test_create_answer(self):
        new_answer = answer_dao.create_answer(test_answer, test_question.id,
                                              False)
        assert new_answer == True
コード例 #18
0
ファイル: referer.py プロジェクト: XinMa1/work
 def detail(self):
     inputParams = self.getInput()
     qID = inputParams['id']
     question = Questions.get(Questions.id == qID)
     self.privData['QUESTION'] = question
     return self.display('questionDetail')