本文整理汇总了Python中models.Response.save方法的典型用法代码示例。如果您正苦于以下问题:Python Response.save方法的具体用法?Python Response.save怎么用?Python Response.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Response
的用法示例。
在下文中一共展示了Response.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _on_rmq_message
# 需要导入模块: from models import Response [as 别名]
# 或者: from models.Response import save [as 别名]
def _on_rmq_message(self, *args, **kwargs):
if 'rmq_message' in kwargs:
rmq_message = kwargs['rmq_message']
else:
return
if rmq_message is not None:
channel, user, message, plugin_name, plugin_response = \
self._process_rmq_message(rmq_message)
if channel is not None:
if user is not None:
if message is not None:
if plugin_name is not None:
if plugin_response is not None:
is_approved = True if channel.is_secure is False \
else False
response = Response(
text=plugin_response,
from_plugin=plugin_name,
in_response_to=message,
to_channel=channel,
to_user=user,
is_approved=is_approved,
is_sent=False,
)
response.save()
示例2: take_survey
# 需要导入模块: from models import Response [as 别名]
# 或者: from models.Response import save [as 别名]
def take_survey(request, survey_id):
survey = get_object_or_404(Survey, pk=survey_id)
questions = survey.question_set.all()
AnswerFormset = get_answer_formset(questions)
formset = AnswerFormset(request.POST or None, queryset=Answer.objects.none())
if formset.is_valid():
answers = formset.save(commit=False)
response = Response(survey=survey)
response.save()
for answer in answers:
answer.response = response
answer.save()
return HttpResponseRedirect(reverse('simple_survey.views.list_surveys'))
for index in range(len(questions)):
question = questions[index]
form = formset.forms[index]
form.fields['answer'].label = question.question
form.fields['question'].initial = question
responseParameters = {
"survey" : survey,
"formset" : formset,
}
return render_to_response('simple_survey/take_survey.html', responseParameters, context_instance=RequestContext(request))
示例3: answer
# 需要导入模块: from models import Response [as 别名]
# 或者: from models.Response import save [as 别名]
def answer(request, poll_id, user_uuid):
poll = get_object_or_404(Poll, pk=poll_id)
participant = get_object_or_404(Participant, unique_id=user_uuid)
if participant.completed:
return redirect(reverse('polls:thanks',
args=(poll.id,
user_uuid,)))
questions = poll.question_set.all()
if request.method == 'POST':
form = DetailForm(request.POST, questions=questions)
if form.is_valid():
to_delete = Response.objects.filter(participant=participant)
to_delete.delete()
for choice_id in form.answers():
response = Response(participant=participant,
choice_id=choice_id)
response.save()
return HttpResponseRedirect(reverse('polls:sign',
args=(poll.id,
user_uuid,)))
else:
form = DetailForm(questions=questions)
return render(request, 'polls/detail.html',
{
'poll': poll,
'form': form,
'user_uuid': user_uuid,
})
示例4: post
# 需要导入模块: from models import Response [as 别名]
# 或者: from models.Response import save [as 别名]
def post(self, request):
if request.POST.get('response', False):
response = Response()
question = Question.objects.get(id=request.POST['question'])
response.message = request.POST['response']
response.question = question
response.user = request.user
response.save()
return HttpResponseRedirect(request.META['HTTP_REFERER'])
示例5: respond
# 需要导入模块: from models import Response [as 别名]
# 或者: from models.Response import save [as 别名]
def respond(request):
"""
Request handler when someone posts a response
1. Add response content to the database
2. Send push notification to client device
3. Update the credit of the responder
"""
if request.method == 'POST':
json_data = json.loads(request.body)
try:
thread_id = json_data['thread_id']
response_content = json_data['content']
device_id = json_data['device_id']
except KeyError:
print "Error: A posted response did not have a JSON object with the required properties"
else:
# check that the thread id and the device ids are valid
thread = Thread.objects.filter(id=thread_id)
device = Device.objects.filter(device_id=device_id)
print "Passed parameter validation"
print thread.count()
print device.count()
if thread.exists() and device.exists():
# add response to database
response = Response(thread=thread[0], responder_device=device[0], response_content=response_content)
response.save()
# add update to the other device
asker_device = thread[0].asker_device
answerer_device = thread[0].answerer_device
print "Thread and device actually exist"
print device_id
print asker_device.device_id
print answerer_device.device_id
if asker_device.device_id == device_id:
ResponseUpdates.add_update(answerer_device, response)
print "Adding an update to the answerers queue"
elif answerer_device.device_id == device_id:
ResponseUpdates.add_update(asker_device, response)
print "Adding an update to the askers queue"
return HttpResponse(json.dumps({}), content_type="application/json")
示例6: add_response
# 需要导入模块: from models import Response [as 别名]
# 或者: from models.Response import save [as 别名]
def add_response():
username = request.form.get('username')
username = username or 'anonymous'
board_id = request.form.get('board_id')
items = request.form.getlist('item')
# print 'Items: {} // {}'.format(type(items), items)
items = [int(x) for x in items if x]
# print 'Items: {} // {}'.format(type(items), items)
response = Response(username=username, board_id=int(board_id),
items=items)
saved = response.save()
# print 'saved response? : {}'.format(saved)
if saved == True:
flash('Response saved. Thanks {}.'.format(username))
else:
flash('Could not save response')
return redirect(url_for('response', response_id=response.id))