本文整理汇总了Python中models.Question.question_text方法的典型用法代码示例。如果您正苦于以下问题:Python Question.question_text方法的具体用法?Python Question.question_text怎么用?Python Question.question_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.question_text方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dummy
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import question_text [as 别名]
def dummy(count):
words = [
'why','do','federer','nadal','elena','deepak','rudra','go','live','love','startup','india',
'near', 'far', 'about','give', 'take', 'bird', 'lion', 'window','door', 'try', 'yoda', 'prestige',
'star', 'sun', 'father', 'mother'
]
ans = [
'maybe', 'yes', 'no', 'never', 'do', 'lie', 'cheat', 'steal',
'run', 'whatever', 'see', 'eat', 'why', 'not'
]
topics = Topic.objects.all()
for i in xrange(count):
q = Question()
q.question_text = ' '.join(random.sample(words, random.randint(8,15)))
q.topic = topics[random.randint(0,len(topics)-1)]
q.user = random.sample(User.objects.all(), 1)[0]
q.save()
choice_count = random.randint(2,6)
for j in xrange(choice_count):
ch = Choice()
ch.choice_text = ' '.join(random.sample(ans, random.randint(2,4)))
ch.question = q
ch.save()
示例2: create_test_backup
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import question_text [as 别名]
def create_test_backup(request):
test_obj = json.loads(request.body)
test = Test()
#import pdb; pdb.set_trace()
if request.user.is_authenticated():
owner = User_Profile.objects.filter(user = request.user)
test.owner = owner[0]
test.test_name = test_obj['PRE_TEST']['test_name']
#test.subject = test_obj['PRE_TEST'].subject
#test.target_exam = test_obj['PRE_TEST'].target_exam
#test.topics = test_obj['PRE_TEST'].topics_included
test.total_time = test_obj['PRE_TEST']['total_time']
test.pass_criteria = test_obj['PRE_TEST']['pass_criteria']
test.assoicated_class = Class.objects.get(pk=test_obj['CLASS_INFO'])
test.save()
try:
for item in test_obj['QUESTIONS']:
question = Question()
question.question_text = item['question_text']
question.explanation = item['explanation']
question.options = json.dumps(item['options'])
question.hint = item['hint']
question.difficulty = item['difficulty_level']
question.points = item['points']
question.owner = owner[0]
#question.target_exam = test.target_exam
#question.subject = test.subject
#question.topic = item.topic
question.save()
test.questions.add(question)
data = {"status" : "success"}
return JsonResponse(data)
except Exception, e:
raise e
示例3: question_add
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import question_text [as 别名]
def question_add(request):
survey_add=Survey.objects.get(id=int(request.session['current_survey']))
new_question=Question()
new_question.question_text=request.POST['question_text']
survey_add.question_set.add(new_question)
new_question.save()
survey_add.save()
request.session['current_question']=new_question.id
return redirect('admin-choice-add-view')
示例4: api_poll_create
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import question_text [as 别名]
def api_poll_create(request):
api_result = {"api": "poll_create", "status": "success"}
try:
token = request.POST["token"]
user = get_user_from_token(token)
if not user:
api_result["status"] = "failure"
api_result["error"] = "user not found"
else:
question = request.POST["question"]
choice_text = request.POST["choices"]
group_id = request.POST["group_id"]
if group_id == "0":
group = None
else:
group = Group.objects.get(pk=group_id)
choices = set(choice_text.split("##"))
if "" in choices:
choices.remove("")
try:
topic = Topic.objects.get(name=request.POST["topic"])
except:
topic = Topic.objects.get(name="others")
if len(question) == 0 or len(choices) < 2:
raise ValueError("invalid poll arguments")
q = Question()
q.question_text = question.strip()
q.user = user
q.topic_id = topic.id
q.group = group
# q.pub_date = datetime.now(pytz.timezone("Asia/Calcutta"))
q.save()
for choice in choices:
c = Choice()
c.choice_text = choice
c.question = q
c.votes = 0
c.save()
print c.id
print q.id
api_result["question_id"] = q.id
except Exception as e:
api_result["status"] = "failure"
api_result["error"] = e.message
return JsonResponse(api_result)
示例5: create
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import question_text [as 别名]
def create(request):
topics = Topic.objects.all()
context = {}
context["topics"] = topics
if request.method == "POST":
print "inside"
print request.POST
try:
question = request.POST["question"]
print "question", question
choices = set(request.POST["choices"].split("##"))
if "" in choices:
choices.remove("")
print "choices", choices
topic_id = request.POST["topic_id"]
print "topic_id", topic_id
if len(question) == 0 or len(choices) < 2:
raise ValueError("invalid poll arguments")
q = Question()
q.question_text = question.strip()
q.user = request.user
q.topic_id = topic_id
# q.pub_date = datetime.now(pytz.timezone("Asia/Calcutta"))
q.save()
for choice in choices:
c = Choice()
c.choice_text = choice
c.question = q
c.votes = 0
c.save()
print c.id
print q.id
data = {}
data["question_id"] = q.id
return JsonResponse(data)
except Exception as e:
print e.errno
print e.strerror
context["error"] = "Please enter valid question and at least two choices"
return render(request, "polls/v1_create.html", context)
else:
return render(request, "polls/v1_create.html", context)