当前位置: 首页>>代码示例>>Python>>正文


Python Question.get方法代码示例

本文整理汇总了Python中models.Question.get方法的典型用法代码示例。如果您正苦于以下问题:Python Question.get方法的具体用法?Python Question.get怎么用?Python Question.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Question的用法示例。


在下文中一共展示了Question.get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: question_result

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
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)
开发者ID:johl,项目名称:futureproof,代码行数:32,代码来源:views.py

示例2: getAnsweredQuestions

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
	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)
开发者ID:ahume,项目名称:politmus-api,代码行数:9,代码来源:questions.py

示例3: getUnansweredQuestionsFor

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
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
开发者ID:ahume,项目名称:politmus-api,代码行数:12,代码来源:utils.py

示例4: get

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
	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)
开发者ID:ahume,项目名称:politmus-api,代码行数:14,代码来源:questions.py

示例5: getUnansweredQuestions

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
	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)
开发者ID:ahume,项目名称:politmus-api,代码行数:15,代码来源:questions.py

示例6: post

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
 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)
开发者ID:BeyondeLabs,项目名称:quizer,代码行数:17,代码来源:explore.py

示例7: questions

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
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))
开发者ID:lachlanmarks,项目名称:meno,代码行数:46,代码来源:views.py

示例8: update

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
	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 =', username)[0]
			question = Question.get(question_key)
		except:
			response['error'] = 'Cannot find user or question'
			self.returnJSON(404, response)
			return None

		# Get existing or new question
		existing = UserVote.all().filter('user_username =', user.username).filter('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
开发者ID:ahume,项目名称:politmus-api,代码行数:41,代码来源:uservotes.py

示例9: user

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
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))
开发者ID:lachlanmarks,项目名称:meno,代码行数:26,代码来源:views.py

示例10: test_answering_question

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
 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)
开发者ID:sudhirj,项目名称:boragle,代码行数:8,代码来源:web_question_tests.py

示例11: question

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import get [as 别名]
def question(id):
    return jsonify(question=Question.get(id=id).serialize_to_dict())
开发者ID:V07D,项目名称:findastupid,代码行数:4,代码来源:jayson.py


注:本文中的models.Question.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。