本文整理汇总了Python中models.Question类的典型用法代码示例。如果您正苦于以下问题:Python Question类的具体用法?Python Question怎么用?Python Question使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Question类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_new_question
def upload_new_question(question_source, question, tags):
new_question = Question(question = question, question_source=question_source)
new_question.save()
tags_final = []
for tag in tags:
try:
search_tag = Tag.objects.get(tag=tag)
tags_final.append(search_tag)
continue
except Tag.DoesNotExist:
new_tag = Tag(tag=tag)
new_tag.save()
tags_final.append(new_tag)
continue
continue
for tag in tags_final:
print tag.tag
for tag in tags_final:
tag.questions.append(new_question)
tag.save()
continue
return new_question.id
示例2: create_question
def create_question(request):
if request.method != 'POST':
return HttpResponseNotAllowed(['POST'])
recording_url = request.POST['RecordingUrl']
recording_url.replace('2010-04-01', '2008-08-01')
to_number = request.POST['To']
from_number = request.POST['From']
number = PhoneNumber.objects.get(number=to_number)
language = number.language
log.debug(recording_url)
q = Question(to_number=to_number,
from_number=from_number,
language=language,
recording_url=recording_url)
q.save()
log.debug('Question Created: %s' % q)
r = twiml.Response()
r.hangup()
return HttpResponse(r)
示例3: get
def get( self ):
q = get_approving_question()
if q == None or q.question == None:
q = get_unapproved_question()
if q == None:
q = Question()
"""
q_submitters = get_questions_with_submitters()
submitters = []
for s in q_submitters:
if s.submitter and not s.submitter in submitters:
submitters.append( s.submitter )
"""
logging.info('Question: %s %s %s' % (q.question, q.category, q.answer))
q.state = 'approving'
q.put()
template_values = {
'CSS_FILE' : 'admin',
'JS_FILE' : '',
'q' : q,
'num_not_approved' : get_unapproved_question_count()
}
self.response.out.write( template.render( 'templates/admin.html', template_values ) )
示例4: new_question
def new_question():
"""Creates a new question"""
form = QuestionForm()
if request.method == 'POST' and form.validate_on_submit():
question = Question(
content=form.content.data,
added_by=users.get_current_user(),
location=get_location(form.location.data)
)
try:
question.put()
question_id = question.key.id()
create_nearby_question(question_id)
flash(u'Question %s successfully saved.' % question_id, 'success')
add_question_to_search_index(question)
return redirect(url_for('list_questions_for_user'))
except CapabilityDisabledError:
flash(u'App Engine Datastore is currently in read-only mode.', 'info')
return redirect(url_for('list_questions_for_user'))
else:
flash_errors(form)
return redirect(url_for('list_questions_for_user'))
示例5: get
def get(self):
numADQuestions = Question.gql('WHERE product = :1', 'ADSync').count()
numSPQuestions = Question.gql('WHERE product = :1', 'SharePoint Web Part').count()
numSSOQuestions = Question.gql('WHERE product = :1', 'SSO').count()
values = { 'numADQuestions': numADQuestions, 'numSPQuestions': numSPQuestions, 'numSSOQuestions': numSSOQuestions }
self.response.out.write(template.render('templates/index.html', values))
示例6: list_questions_for_user
def list_questions_for_user():
"""Lists all questions posted by a user"""
form = QuestionForm()
search_form = QuestionSearchForm()
user = users.get_current_user()
login_url = users.create_login_url(url_for('home'))
query_string = request.query_string
latitude = request.args.get('lat')
longitude = request.args.get('lon')
radius = request.args.get('r')
# If searching w/ params (GET)
if request.method == 'GET' and all(v is not None for v in (latitude, longitude, radius)):
q = "distance(location, geopoint(%f, %f)) <= %f" % (float(latitude), float(longitude), float(radius))
index = search.Index(name="myQuestions")
results = index.search(q)
# TODO: replace this with a proper .query
questions = [Question.get_by_id(long(r.doc_id)) for r in results]
questions = filter(None, questions) # filter deleted questions
if questions:
questions = sorted(questions, key=lambda question: question.timestamp)
else:
questions = Question.all_for(user)
channel_token = safe_channel_create(all_user_questions_answers_channel_id(user))
return render_template('list_questions_for_user.html', questions=questions, form=form, user=user, login_url=login_url, search_form=search_form, channel_token=channel_token)
示例7: ask_display
def ask_display(request):
if not request.user.is_authenticated():
raise PermissionDenied
if request.method == 'POST':
request_title = request.POST.get('title')
request_text = request.POST.get('text')
request_tags = request.POST.get('tags')
if request_title == '' or request_text == '':
return render(request, 'ask.html', {'page_title': 'New Question', 'errors': '1'})
new_question = Question(title = request_title,
date = datetime.datetime.now(),
author = UserProfile.objects.get(user_account = request.user),
text = request_text)
new_question.save()
for tag_str in request_tags.split(','):
if Tag.objects.filter(name = tag_str).exists():
tag = Tag.objects.get(name = tag_str)
new_question.tags.add(tag)
else:
new_tag = Tag(name = tag_str)
new_tag.save()
new_question.tags.add(new_tag)
return HttpResponseRedirect('/question/{}'.format(new_question.id))
return render(request, 'ask.html', {'page_title': 'New Question', 'errors': '0'})
示例8: ask
def ask(request):
if request.method == 'POST':
form = QuestionForm(request.POST)
if form.is_valid():
q = Question(
created_by=request.user,
author=request.user,
category=form.cleaned_data['category'],
title=form.cleaned_data['title'],
text=form.cleaned_data['text'],
)
q.save()
return redirect(reverse('support:question', args=(q.id,)))
else:
form = QuestionForm()
c = {
'form': form,
'search_form': SearchForm(),
'categories': p.CATEGORIES,
'title': _("Ask a question"),
'site_title': g.SITE_TITLE,
}
return render(request, 'support/ask.html', c)
示例9: askquestion
def askquestion(request):
"""提问模板"""
name =request.session.get('name')
if request.method == "POST" and request.is_ajax():
form = QuestionForm(request.POST)
if form.is_valid():
data = form.cleaned_data
title = data['title']
text = data['text']
qtype = data['q_type'].lower()
user = User.objects.get(name=name.split()[0])
try:
questiontype = QuestionType.objects.get(name=qtype)
except QuestionType.DoesNotExist:
questiontype = QuestionType(name=qtype)
questiontype.save()
question = Question(user=user, title=title, text=text, q_type=questiontype)
question.save()
# return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
return JsonResponse({'status':'ok'})
else:
# return HttpResponse(request.POST.get('title'))
return render(request, 'askquestion.html')
if name:
return render(request,'askquestion.html',{'QuestionForm':QuestionForm, 'name':name.split()})
else:
return HttpResponseRedirect("/")
示例10: save_scratch
def save_scratch(kind='', subject='', theme='', text='', answers=[]):
'''
save question from scratch to database
'''
q = Question(kind=kind, subject=subject, theme=theme, text=text, answers=answers)
q.save()
return True
示例11: create_test_backup
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
示例12: test_was_published_recently_with_recent_question
def test_was_published_recently_with_recent_question(self):
"""
was_published_recently() should return True for questions whos pub_date is within the last day.
"""
time = timezone.now() + datetime.timedelta(hours=-1)
recent_question=Question(pub_date=time)
self.assertEqual(recent_question.was_published_recently(), True)
示例13: test_was_published_recently_wit_old_question
def test_was_published_recently_wit_old_question(self):
"""
was_published_recently() should return False for question whose pub_date is in within the last day
"""
time = timezone.now() + datetime.timedelta(days=-30)
old_question = Question(pub_date=time)
self.assertEqual(old_question.was_published_recently(), False)
示例14: save
def save(self, commit=True):
# question = super(AskForm, self).save(commit=False)
question = Question(title=self.cleaned_data['title'],
text=self.cleaned_data['text'],
author=self._user)
question.save()
return question
示例15: test_was_published_recently_with_future_question
def test_was_published_recently_with_future_question(self):
"""
was_published_recently() should return False for questions whose pub_date is in the future.
"""
time = timezone.now() + datetime.timedelta(days=30)
future_question = Question(pub_date=time)
self.assertEqual(future_question.was_published_recently(), False)