本文整理汇总了Python中models.Question.question方法的典型用法代码示例。如果您正苦于以下问题:Python Question.question方法的具体用法?Python Question.question怎么用?Python Question.question使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.question方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_item
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import question [as 别名]
def process_item(self, item, spider):
session = self.Session()
question = Question(
question_number=item.get('question_number', ''),
question=item.get('question', ''),
possible_answers=item.get('possible_answers', ''),
correct_answer=item.get('correct_answer', ''),
explanation=item.get('explanation', ''),
section=item.get('section', ''),
type_of_quiz=item.get('type_of_quiz', ''),
)
existing_query = session.query(Question).filter(
Question.question_number == question.question_number).first()
if existing_query:
question = existing_query
question.question_number = item.get('question_number', '')
question.question = item.get('question', '')
question.possible_answers = item.get('possible_answers', '')
question.correct_answer = item.get('correct_answer', '')
question.explanation = item.get('explanation', '')
question.section = item.get('section', '')
question.type_of_quiz = item.get('type_of_quiz', '')
else:
session.add(question)
session.commit()
session.close()
return item
示例2: test_get_user
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import question [as 别名]
def test_get_user():
user = User()
user.username = u"test"
user.set_password("test123")
assert user.save()
assert user._id
q = Question()
q.question = u"test"
q.author = u"anon"
q.user = user.username
assert q.save(validate=True)
assert q._id
user_from_question = q.get_user()
assert user_from_question._id == user._id
q.user = u"anon!"
q.save()
assert not q.get_user()
示例3: __make_question_choice_for_fields
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import question [as 别名]
def __make_question_choice_for_fields(entries, user_id, process_id):
"""
Вспомогательная функция сохранения ответов на вопросы пользователя
:param entries: список виджетов, которые используются для отображения и получения ответов пользователя (list)
:param user_id: идентификатор пользователя (int)
:param process_id: идентификатор процесса (int)
:return: None
"""
for entry in entries:
# Получаем ответ пользователя
choice = entry.data
# Обращаемся к БД, получаем запись вопроса по его имени и идентификатору процесса
question = Question.question(entry.label, process_id).one()
# Формируем JSON, включая в него список необходимых параметров для анализа
user_choice = {'process_id': process_id,
'question_id': question.id,
'mark': question.question_mark(choice),
'weight': question.weight,
'correct_answers': question.correct_answers}
if not type(choice) == ListType:
choice = [choice]
user_choice['choice'] = choice
# Создаём новую запись в таблице UserChoice с типом ответа 'question'
UserChoice.create_question_choice(user_id=user_id,
choice=user_choice)
示例4: test_get_unanswered_questions
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import question [as 别名]
def test_get_unanswered_questions():
user = User()
user.username = u"test"
user.set_password("test123")
assert user.save()
assert user._id
q = Question()
q.question = u"test"
q.author = u"anon"
q.user = user.username
assert q.save(validate=True)
assert q._id
user_from_db = User.one({'username': 'test'})
assert user_from_db.unanswered_questions().count() == 1
示例5: import_mp_votes
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import question [as 别名]
def import_mp_votes(subset=False):
if MPVote.all().count() > 0:
print "Import already complete"
return
subset_const = [
"Brighton, Kemptown",
"Brighton, Pavillion",
"Hove",
"Hackney South and Shoreditch",
"Edinburgh North, and Leith"
]
subset_mp = [
"Caroline Lucas",
"Simon Kirby",
"Mike Weatherley",
"Meg Hillier",
"Mark Lazarowicz"
]
question_list = {}
csvfile = open('fixtures/mp_votes/vote_questions.csv', 'rU')
for row in csv.reader(csvfile):
d = Question()
d.question = row[0]
d.title = row[1]
d.date = datetime.datetime.now()
d.publicwhip_url = row[3]
d.put()
question_list[row[4]] = d
mps_created = []
consts_created = []
for question in question_list:
print question
csvfile = open('fixtures/mp_votes/%s.csv' % question, 'rU')
for row in csv.reader(csvfile):
if subset and row[1] not in subset_const and row[0] not in subset_mp:
continue
try:
v = MPVote(parent=question_list[question])
v.question = str(question_list[question].key())
v.mp_name = row[0]
v.mp_slug = slugify(row[0])
v.mp_constituency = row[1]
v.mp_party = normalise_party(row[2]).lower()
v.selection = normalise_selection(row[3])
v.mp_whilst = get_whilst(row[2])
v.put()
if v.mp_slug not in mps_created:
mp = MP()
mp.slug = v.mp_slug
mp.name = v.mp_name
mp.constituency = v.mp_constituency
mp.party = v.mp_party
mp.put()
mps_created.append(v.mp_slug)
if v.mp_constituency not in consts_created:
const = Constituency()
const.name = v.mp_constituency
const.slug = slugify(v.mp_constituency)
const.mp_name = v.mp_name
const.mp_party = v.mp_party
const.put()
consts_created.append(v.mp_constituency)
except:
print "Failed insert"