本文整理汇总了Python中models.Question.title方法的典型用法代码示例。如果您正苦于以下问题:Python Question.title方法的具体用法?Python Question.title怎么用?Python Question.title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.title方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import title [as 别名]
def create(request):
if request.method == "GET":
return render(request,'question/create.html',{})
q = Question()
q.title = request.POST["title"]
q.text = request.POST["text"]
q.save()
return redirect('lookup',q.id)
示例2: write
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import title [as 别名]
def write(request):
user = request.session.get('username')
if request.method == "POST":
title = request.POST['title']
content = request.POST['content']
if title and content:
question_new = Question()
question_new.title = title
question_new.content = content
question_new.save()
return JsonResponse({'message': '提交问题成功', 'status': 200})
else:
return JsonResponse({'message': '格式错误', 'status': 500})
return render_to_response('question-write.html', {'username': user})
示例3: asking
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import title [as 别名]
def asking(request, **kwargs):
try:
q_body = request.form['question-body']
q_title = request.form['question-title']
q_cat = request.form['question-category']
except KeyError:
return questions(request)
q = Question()
q.views = 0
q.votes = 0
q.body = q_body
q.title = q_title
q.category_id = Category.get(where=('category_name',q_cat))[0].id
q.user_id = local.request.session['uid']
q.insert()
return question(request, qid = q.id)
示例4: post
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import title [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))
示例5: import_mp_votes
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import title [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"