Esempio n. 1
0
def question_result(qid=None):
    import urllib
    escaped_url=urllib.quote_plus("http://www.isitfutureproof.com/question/" + qid)
    if ('vote_value' in request.form):
        agree = "didn't tell us if you agree or disagree"
        question = Question.get(qid)
        if (question.total == None):
            question.total = 0
        if (question.vote_no == None):
            question.vote_no = 0
        if (question.vote_yes == None):
            question.vote_yes = 0
        question.total = question.total + 1
        if (request.form['vote_value'] == "yes"):
            question.vote_yes = question.vote_yes +1
            agree = "disagree"
        if (request.form['vote_value'] == "no"):
            question.vote_no = question.vote_no +1
            agree = "agree"
        question.save()
        question = Question.get(qid)
        percent = 0
        stylepercent = "style-0"
        if (question.total > 0):
            percent = float(Decimal(str(float(1.0*question.vote_no/question.total)*100)).quantize(TWOPLACES))
            stylepercent = "style-" + str(int(percent))
        return render_template('question_result.html', escaped_url=escaped_url, qid=qid, question=question.question, percent=percent, vote_no=question.vote_no, total=question.total, agreed=agree, stylepercent=stylepercent)
    else:
        question = Question.get(qid)
        return render_template('question_clean.html', qid=qid, escaped_url=escaped_url, question=question.question)
Esempio n. 2
0
	def getAnsweredQuestions(self):

		if self.answered_ids is None:
			self.user_votes = UserVote.all().filter('user_username =', self.username)
			self.answered_ids = [v.question for v in self.user_votes]

		return Question.get(self.answered_ids)
Esempio n. 3
0
    def getAnsweredQuestions(self):

        if self.answered_ids is None:
            self.user_votes = UserVote.all().filter('user_username =',
                                                    self.username)
            self.answered_ids = [v.question for v in self.user_votes]

        return Question.get(self.answered_ids)
Esempio n. 4
0
def getUnansweredQuestionsFor(username):
	vote_ids = [a.question for a in getAnsweredQuestionsFor(username)]

	question_ids = [str(q.key()) for q in Question.all()]
	filtered_ids = []
	for qid in question_ids:
		if qid not in vote_ids:
			filtered_ids.append(qid)
	questions = Question.get(filtered_ids)
	return questions
Esempio n. 5
0
def getUnansweredQuestionsFor(username):
    vote_ids = [a.question for a in getAnsweredQuestionsFor(username)]

    question_ids = [str(q.key()) for q in Question.all()]
    filtered_ids = []
    for qid in question_ids:
        if qid not in vote_ids:
            filtered_ids.append(qid)
    questions = Question.get(filtered_ids)
    return questions
Esempio n. 6
0
def vote(question_id):
	question = Question.get(id=question_id)


	selected_choice = question.choices.select().where(Choice.id==request.form.get('choice')).get()


	selected_choice.votes += 1
	selected_choice.save()

	return redirect(url_for('results', question_id=question.id))
Esempio n. 7
0
	def get(self, question_key):

		response = {}

		try:
			question = Question.get(question_key)
			response['question'] = utils.question_to_dict(question)
		except:
			response['error'] = 'Cannot find question'
			self.returnJSON(404, response)

		self.returnJSON(200, response)
Esempio n. 8
0
    def get(self, question_key):

        response = {}

        try:
            question = Question.get(question_key)
            response['question'] = utils.question_to_dict(question)
        except:
            response['error'] = 'Cannot find question'
            self.returnJSON(404, response)

        self.returnJSON(200, response)
Esempio n. 9
0
    def getUnansweredQuestions(self):

        if self.answered_ids is None:
            self.getAnsweredQuestions()

        question_ids = [str(q.key()) for q in Question.all()]

        filtered_ids = []
        for q in question_ids:
            if q not in self.answered_ids:
                filtered_ids.append(q)

        return Question.get(filtered_ids)
Esempio n. 10
0
	def getUnansweredQuestions(self):

		if self.answered_ids is None:
			self.getAnsweredQuestions()

		question_ids = [str(q.key()) for q in Question.all()]

		filtered_ids = []
		for q in question_ids:
			if q not in self.answered_ids:
				filtered_ids.append(q)

		return Question.get(filtered_ids)
Esempio n. 11
0
def getNewRoomQuestion():
    cid = redis_db.get('sid:%s:cid' % request.sid).decode('utf-8')
    room_id = redis_db.get('client:%s:room_id' % cid).decode('utf-8')

    used = redis_db.lrange('room:%s:topics_seen' % room_id, 0, -1)
    used = [(int(x)) for x in used]

    id = Question.getRandomIndex(used)
    q = Question.get(id)

    redis_db.set('room:%s:topic_id' % room_id, id)
    redis_db.rpush('room:%s:topics_seen' % room_id, id)

    emit('message', {'type': 'q', 'question': q, 'id': id}, room=room_id)
Esempio n. 12
0
 def post(self):
     qkey = self.request.get('qkey')
     ukey = self.request.get('ukey')
     comment = self.request.get('comment')
     rev_key = self.request.get('rev_key')
     
     if comment != '':
         question = Question.get(qkey)
         q_comment = QuestionComment()
         q_comment.comment = comment
         q_comment.question = question
         q_comment.ukey = ukey
         q_comment.put()
     
     self.redirect("/explore/revision/%s"%rev_key)
Esempio n. 13
0
def questions(request, **kwargs):
    page_data = []
    session_data = {}
    if local.request.session['uid']:
        session_data['user_name'] = User.get_by_id(local.request.session['uid'])[0].name

    page = Page(session_data)
    if 'search' in request.args:
        questions_list = Question.search(request.args['search'])
        page.title = "Questions - '%s' - Meno" % request.args['search']
    if 'sort' in request.args:
        sorts = {
            'new': 'date_created',
            }
        sort_attr = sorts[request.args['sort']]
        questions_list = Question.get(order=(sort_attr, 'desc'), limit=30)
    else:
        page.title = 'Questions - Meno'
        questions_list = Question.get_latest(30)
    for question in questions_list:
        edit = question.latest_edit()[0]
        user = User.get_by_id(question.user_id)[0]
        age = question.age()
        stat = question.latest_status()[0]
        question_data = {
                'question_id': str(question.id),
                'user_id': str(question.user_id),
                'views': str(question.views),
                'votes': str(question.votes),
                'date_created': str(question.created),
                'category': str(Category.get_by_id(question.category_id)[0].name),
                'answers_count': str(count(question.answers())),
                'title': str(edit.title),
                'user': str(user.name),
                'status': str(stat.status),
                'age': str("Asked %sh %sm %ss ago" % (age[0], age[0], age[1])),
                }
        page_data.append(question_data)
        
    
    content = QuestionsList(page_data)

    local.request.session['last'] = request.base_url
    return respond(page.render(content))
Esempio n. 14
0
def create_submission(user_id: UUID, user_role: Role,
                      submission: schemas.Submission):
    is_authorized(user_role, "create_submission")

    question = Question.get(id=submission.question_id)
    if not question:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=("Question not found : question_id: {}".format(
                submission.question_id)))

    participant = Participant.get(exam=question.exam, user=User[user_id])
    if not participant:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=("Participant not found : exam_id: {}".format(
                question.exam.id)))

    if len(question.multi_choice) > 0:
        if submission.answer == question.answer:
            marks_obtained = question.marks
            mark = Mark.auto_tick
        else:
            marks_obtained = 0
            mark = Mark.auto_cross

        submission = Submission(answer=submission.answer,
                                question=question,
                                user=User[user_id],
                                marks_obtained=marks_obtained,
                                mark=mark)
    else:
        submission = Submission(answer=submission.answer,
                                question=question,
                                user=User[user_id])

    performance_review(submission)

    return submission.to_dict()
Esempio n. 15
0
	def update(self, username, question_key):

		response = {}

		allowed_selections = ['aye', 'no', 'dont-care', 'dont-understand']

		if self.request.get('selection') not in allowed_selections:
			logging.debug("hello")
			response['status'] = 'error'
			response['error'] = 'You did not send a selection [aye, no, dont-care, dont-understand]'
			self.returnJSON(406, response) # 406 Not Acceptable
			return None


		try:
			user = User.all().filter('username ='******'error'] = 'Cannot find user or question'
			self.returnJSON(404, response)
			return None

		# Get existing or new question
		existing = UserVote.all().filter('user_username ='******'question =', question_key)
		if existing.count() > 0:
			vote = existing[0]
		else:
			logging.debug(question)
			vote = UserVote(parent=question)

		vote.question = question_key
		vote.user_username = user.username
		vote.constituency = user.constituency
		vote.selection = self.request.get('selection')
		vote.put()

		response['vote'] = utils.vote_to_dict(vote)
		response['user'] = utils.user_to_dict(user)
		return response
Esempio n. 16
0
def user(request, uid, **kwargs):
    user = User.get_by_id(uid)[0]
    questions = Question.get(where=('author_id', uid), order=('date_created', 'desc'))
    try:
        user.questions_count = len(questions)
    except TypeError:
        user.questions_count = None

    answers = Answer.get(where=('author_id', uid), order=('date_created', 'desc'))
    try:
        user.answers_count = len(questions)
    except TypeError:
        user.answers_count = None

    session_data = {}
    if local.request.session['uid']:
        session_data['user_name'] = User.get_by_id(local.request.session['uid'])[0].name

    page = Page(session_data)
    page.title = user.name + "'s Profile - Meno"
    content = Profile(user)

    local.request.session['last'] = request.base_url
    return respond(page.render(content))
Esempio n. 17
0
def question(id):
    return jsonify(question=Question.get(id=id).serialize_to_dict())
Esempio n. 18
0
def getPartner(data):

    cid = redis_db.get('sid:%s:cid' % request.sid).decode('utf-8')

    lean = data['lean']
    search = data['search']

    redis_db.set('client:%s:wait-list' % cid, '%s-waiting-%s' % (lean, search))

    room_id = cid

    list = ''
    # wants to match with left leaning user
    if search == "l":
        if lean == 'left':
            if redis_db.llen('left-waiting-l'):
                list = 'left-waiting-l'
            elif redis_db.llen('left-waiting-lr'):
                list = 'left-waiting-lr'
            else:
                redis_db.rpush('left-waiting-l', cid)
        elif lean == 'right':
            if redis_db.llen('left-waiting-r'):
                list = 'left-waiting-r'
            elif redis_db.llen('left-waiting-lr'):
                list = 'left-waiting-lr'
            else:
                redis_db.rpush('right-waiting-l', cid)
    elif search == "r":
        if lean == 'left':
            if redis_db.llen('right-waiting-l'):
                list = 'right-waiting-l'
            elif redis_db.llen('right-waiting-lr'):
                list = 'right-waiting-lr'
            else:
                redis_db.rpush('left-waiting-r', cid)
        elif lean == 'right':
            if redis_db.llen('right-waiting-r'):
                list = 'right-waiting-r'
            elif redis_db.llen('right-waiting-lr'):
                list = 'right-waiting-lr'
            else:
                redis_db.rpush('right-waiting-r', cid)
    else:  # search is lr
        if lean == 'left':
            if redis_db.llen('right-waiting-l'):
                list = 'right-waiting-1'
            elif redis_db.llen('left-waiting-l'):
                list = 'left-waiting-l'
            elif redis_db.llen('right-waiting-lr'):
                list = 'right-waiting-lr'
            elif redis_db.llen('left-waiting-lr'):
                list = 'left-waiting-lr'
            else:
                redis_db.rpush('left-waiting-lr', cid)
        elif lean == 'right':
            if redis_db.llen('left-waiting-r'):
                list = 'left-waiting-r'
            elif redis_db.llen('right-waiting-r'):
                list = 'right-waiting-r'
            elif redis_db.llen('left-waiting-lr'):
                list = 'left-waiting-lr'
            elif redis_db.llen('right-waiting-lr'):
                list = 'right-waiting-lr'
            else:
                redis_db.rpush('right-waiting-lr', cid)

    if not list:
        emit('message', {'type': 'searching'})
    else:  # match found
        # pop from left_waiting
        partner_cid = redis_db.lpop(list).decode('utf-8')

        # remove waiting list data
        redis_db.delete('client:%s:wait-list' % cid)
        redis_db.delete('client:%s:wait-list' % partner_cid)

        # generate a new room
        generateRoom(room_id, type=1)

        # add the pair to the room
        joinRoom(room_id=room_id, sid=request.sid)
        joinRoom(room_id=room_id,
                 sid=redis_db.get('client:%s:sid' %
                                  partner_cid).decode('utf-8'))

        redis_db.set('client:%s:pcid' % cid, partner_cid)
        redis_db.set('client:%s:pcid' % partner_cid, cid)

        # Give them their discussion topic
        id = int(redis_db.get('room:%s:topic_id' % room_id).decode('utf-8'))
        q = Question.get(id)
        emit('message', {'type': 'q', 'question': q, 'id': id}, room=room_id)

        # Let clients know they've joined
        emit('message', {'type': 'matched'}, room=room_id)

    emit_user_count(True)
Esempio n. 19
0
def detail(question_id):
	question = Question.get(id=question_id)
	return render_template('detail.html', question=question)
Esempio n. 20
0
 def test_answering_question(self):
     self.app.post(self.question.url, dict(answer = 'zimbly'))
     question = Question.get(self.question.key())
     self.assertEqual('zimbly', question.answers[0].text)
     self.assertEqual(self.creator.name, question.answers[0].creator.name)
     self.assertEqual(1, question.answer_count)
Esempio n. 21
0
def results(question_id):
	question = Question.get(id=question_id)
	return render_template('results.html', question=question)