本文整理汇总了Python中models.Question.put方法的典型用法代码示例。如果您正苦于以下问题:Python Question.put方法的具体用法?Python Question.put怎么用?Python Question.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.put方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import put [as 别名]
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 ) )
示例2: QuestionTests
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import put [as 别名]
class QuestionTests(base.ExtendedTestCase):
def setUp(self):
super(QuestionTests, self).setUp()
self.boragle = Boragle(name='test1', slugs = ['t1'], desc = 'desc', creator = self.creator)
self.boragle.put()
self.avatar = Avatar(boragle = self.boragle, creator = self.creator)
self.avatar.put()
self.question = Question(boragle = self.boragle, text = "why ?", creator = self.avatar)
self.question.put()
def test_creation(self):
self.app.post('/t1/ask', dict(text = 'why? why? why?', details = 'simply, maybe'))
question = Question.find_by_slug('why-why-why')
self.assertTrue(question)
self.assertEqual("why? why? why?",question.text)
self.assertEqual("simply, maybe",question.details)
self.assertEqual(self.creator.name,question.creator.creator.name)
def test_creation_security(self):
self.logout()
self.app.post('/t1/ask', dict(text = 'why? why? why?', details = 'simply, maybe'),
status = 403)
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)
def test_answering_question_security(self):
self.logout()
self.app.post(self.question.url, dict(answer = 'zimbly'), status = 403)
def test_smoke_question_page(self):
self.app.get(self.question.url)
def test_voting_security(self):
answer = Answer.create(question = self.question, text= 'fake answer', creator = self.avatar)
self.app.get(answer.voting_url+'/up', status = 302)
answer = Answer.get(answer.key())
self.assertEqual(answer.vote_count, 1)
self.logout()
self.app.get(answer.voting_url+'/down', status = 302)
answer = Answer.get(answer.key())
self.assertEqual(answer.vote_count, 1)
def test_voting_up(self):
answer = Answer.create(question = self.question, text= 'fake answer', creator = self.avatar)
self.app.get(answer.voting_url+'/up', status = 302)
answer = Answer.get(answer.key())
self.assertEqual(answer.vote_count,1)
self.app.get(answer.voting_url+'/down', status = 302)
answer = Answer.get(answer.key())
self.assertEqual(answer.vote_count,-1)
示例3: new_question
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import put [as 别名]
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'))
示例4: post
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import put [as 别名]
def post(self, boragle_slug):
boragle = Boragle.find_by_slug(boragle_slug)
avatar = self.get_avatar_for_boragle(boragle)
text = self.read('text')
if not text or not text.strip(): raise PostingError('Please enter a question.')
assert avatar
new_question = Question(text = text,
details = self.read('details'),
boragle = boragle,
creator = avatar)
new_question.put()
self.redirect(new_question.url)
示例5: post
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import put [as 别名]
def post(self):
if self.current_user is not None:
question = self.request.get("question")
user_anon = self.request.get("user_anon")
asker_name = None
if user_anon == "anon":
asker_name = "Anonymous"
elif user_anon == "notanon":
asker_name = self.current_user['name']
else:
pass
q = Question(question=question, asked_by=self.current_user['name'], asker_name = asker_name)
q.put()
self.redirect("/q")
示例6: post
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import put [as 别名]
def post( self, user ):
question = self.request.get( 'question' )
correct = self.request.get( 'correct' )
cat = self.request.get( 'category' )
diff = self.request.get( 'difficulty' )
incorrect_1 = self.request.get( 'incorrect_1' )
incorrect_2 = self.request.get( 'incorrect_2' )
incorrect_3 = self.request.get( 'incorrect_3' )
if not question == 'Question':
q = Question( question=question, opt_1=correct, opt_2=incorrect_1, opt_3=incorrect_2, opt_4=incorrect_3, answer=correct, state='not_approved', category=cat, difficulty=diff, submitter=user )
q.put()
Emailer.feedback ( question, correct, incorrect_1, incorrect_2, incorrect_3, user )
self.redirect( '/about' )
示例7: create_question
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import put [as 别名]
def create_question(self, request):
""" Allows players to create questions.
This function allows players to create questions.
Returns:
QuestionForm -- QuestionForm representation of the created question
"""
# Construct a question from the request
question = Question(question=request.question,
incorrect_answers=request.incorrect_answers,
correct_answer=request.correct_answer)
key = question.put()
logger.debug("Question successfully created.")
# If a game key has been provided, add the question to the game
if request.urlsafe_game_key is not None:
game = get_by_urlsafe(request.urlsafe_game_key, Game)
game.questions.append(key)
game.put()
logger.debug("Question added to game.")
# Return confirmation of question creation and/or added to a game
return question.to_form()
示例8: post
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import put [as 别名]
def post(self):
# Grab album from url
urlstring = self.request.POST['album']
album_key = ndb.Key(urlsafe=urlstring)
album = album_key.get()
# Check whether we're storing a album or a Question
if self.request.GET['album'] == '1':
album.title = self.request.POST['albumTitle']
album.category = self.request.POST['categoryTitle']
album.put()
time.sleep(0.1)
# Save album and redirect to edit if the user clicks on 'Save and continue editing'
# Else, save album and go back to the main page which lists all albums
if self.request.POST.get('stay') == '1':
self.redirect('/edit?album=1&id='+urlstring)
else:
if album.album_type == 'match':
self.redirect('/match')
elif album.album_type == 'correlate':
self.redirect('/correlate')
else:
self.redirect('/oddmanout')
else:
# Create Question with the album as parent for strong consistency
question = ""
new = "1"
if self.request.POST['question'] == "":
question = Question(parent=album_key)
question.question_id = question.put().id()
else:
new = "0"
question_url = self.request.POST['question']
question_key = ndb.Key(urlsafe=question_url)
question = question_key.get()
question.title = self.request.get('title')
question.fact = self.request.get('fact')
question.effect = self.request.get('revealEffect')
question.difficulty = self.request.get('difficulty')
# Create answer choices
answer = int(self.request.get('correct_answer'))
input_images = self.request.get('image', allow_multiple=True)
num_images = 4
if album.album_type == 'correlate':
num_images = 5
image_list = []
for i in range(num_images):
img = ""
input_img = input_images[i]
# If old retrieve the Image
if new == "0":
img = question.images[i]
else:
img = Image()
# Resize image
if input_img:
op_img = images.Image(input_img)
op_img.resize(width=256, height=256, crop_to_fit=True)
result_img = op_img.execute_transforms(output_encoding=images.JPEG)
img.image = result_img
# Set the title and correct fields
if answer == i:
img.title = "correct_answer_"+str(i)
img.correct = True
elif num_images == 5 and i == 0: # This is if the album is of type Correlate
img.title = "main_image_"+str(i)
img.correct = False
else:
img.title = "incorrect_answer_"+str(i)
img.correct = False
# If old Question, free up the old Image and put in new Image
if new == "0":
question.images.pop(i)
question.images.insert(i, img)
else:
question.images.append(img)
question.put()
# Query all Question(s) for the album in recently added order for /create
# Retrieve previously input values, and indicate whether this is a new album (edit)
questions = Question.query(ancestor=album_key).order(-Question.date).fetch()
retrieve = 1
edit = self.request.GET['edit']
template_values = {
'album': album,
'album_type': album.album_type,
'questions': questions,
'edit': edit,
'retrieve': retrieve
}
template = JINJA_ENVIRONMENT.get_template('create.html')
self.response.write(template.render(template_values))
示例9: import_mp_votes
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import put [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"
示例10: post
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import put [as 别名]
def post(self):
newQuestion = Question(text = self.request.get('questionText'), product = self.request.get('productChoice'))
newQuestion.put()
self.redirect('/qadmin')