Esempio n. 1
0
    def __init__(self):
        self.ques = [Question("What is the second largest island in Greece?", ["Evia", "Crete", "Rodes", "Samos"]),
                     Question("What is the largest greek football club?", ["Olympiacos", "Vazelos",
                                                                           "Chanoumi", "Mpougatses"]),
                     Question("What is Einstain first name?", ["Albert", "John", "Mike", "Steven"])]

        self.skip = Question("What is larger?", ["1", "-1", "0", "0.999"])
 def show(self, Request):
     categories = Category.all()
     try:
         question = Question.find_or_fail(Request.param('id'))
     except:
         return Request.status('404 Not Found')
     return view('questions/show', {'question': question, 'categories': categories})
Esempio n. 3
0
    def store(self, Request, Session):
        ok, errors = self.validate_input(Request.all())

        if not ok:
            display = ''
            for error in errors:
                display += '{0} {1} \n\n\n'.format(error.title(),
                                                   errors[error][0])
            Session.flash('danger', display)
            return Request.redirect('/ask')

        Question.create(title=Request.input('title'),
                        body=Request.input('body'),
                        user_id=Request.user().id)
        Session.flash('success', 'Question added successfuly!')
        return Request.redirect('/')
Esempio n. 4
0
    def index(self, Request):
        page = Request.input('page', 1)

        questions = Question.paginate(10, int(page))
        categories = Category.all()

        search = Request.input('search')

        if search:
            questions = Question.where('title', 'like',
                                       '%{0}%'.format(search)).paginate(
                                           10, int(page))

        return view('index', {
            'questions': questions,
            'categories': categories
        })
Esempio n. 5
0
    def store(self, Request, Session):
        tags = Request.input('tags')
        validate = QuestionValidator(Request).validate_new_form()

        if not validate.check():
            display = ''
            for error in validate.errors():
                display += '{0} {1} \n\n\n'.format(error.title(),
                                                   validate.errors()[error][0])
            Session.flash('danger', display)
            return Request.redirect('/ask')

        Question.create(title=Request.input('title'),
                        body=Request.input('body'),
                        user_id=Request.user().id,
                        tags=self.clean_tags(tags))

        Session.flash('success', 'Question added successfuly!')
        return Request.redirect('/')
Esempio n. 6
0
    def index(self, Request):
        page = Request.input('page', 1)
        category_id = Request.param('id')
        try:
            category = Category.find_or_fail(category_id)
        except:
            return Request.status('404 Not Found')
        categories = Category.all()
        questions = Question.where('category_id',
                                   category.id).paginate(10, int(page))

        return view('index', {
            'questions': questions,
            'categories': categories
        })
Esempio n. 7
0
def add_a_questions():

    if not request.form['user']:
        response = jsonify({'error': 'User field  is empty'})
        response.status_code = 400
        return response

    if not request.form['qn']:
        response = jsonify({'error': 'Question field is empty'})
        response.status_code = 400
        return response

    new_qn = Question(2, request.form['qn'], request.form['user'])
    response = jsonify(store.add_question(new_qn))
    response.status_code = 201
    return response
Esempio n. 8
0
 def show(self, Request):
     question = Question.find(Request.param('id'))
     return view('questions/show', {'question': question})
Esempio n. 9
0
    def accept_answer(self, Request):
        question = Question.find(Request.param('id'))
        question.accepted_answer = Request.param('answer_id')
        question.save()

        return Request.back()
Esempio n. 10
0
 def questions(self, Request):
     questions = Question.where('user_id', Request.user().id).get()
     return view('questions/me', {'questions': questions})
Esempio n. 11
0
 def questions(self):
     return Question.where('user_id', self.id).get()
Esempio n. 12
0
def test_has_user_id():
    new_qtn = Question(10, "Who?", "Simon")
    assert hasattr(new_qtn, "user_id")
Esempio n. 13
0
def test_is_instance_of_Question_class():
    new_qtn = Question(6, "What?", "Arthur")
    assert isinstance(new_qtn, Question)
Esempio n. 14
0
def test_has_user():
    new_qtn = Question(3, "Where?", "Ethan")
    assert hasattr(new_qtn, "user")
Esempio n. 15
0
 def index(self):
     questions = Question.all()
     return view('index', {'questions': questions})