本文整理汇总了Python中models.Answer.user方法的典型用法代码示例。如果您正苦于以下问题:Python Answer.user方法的具体用法?Python Answer.user怎么用?Python Answer.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Answer
的用法示例。
在下文中一共展示了Answer.user方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _saveable_answer
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import user [as 别名]
def _saveable_answer(self, ans=None):
if ans is None:
ans = Answer()
ans.question = self.question
ans.session_key = self.session_key
if self.user.is_authenticated():
ans.user = self.user
else:
ans.user = None
ans.interview_uuid = self.interview_uuid
return ans
示例2: save
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import user [as 别名]
def save(self, commit=True):
if not self.cleaned_data['answer']:
if self.fields['answer'].required:
raise ValidationError, _('This field is required.')
return
ans = Answer()
ans.question = self.question
ans.session_key = self.session_key
if self.user.is_authenticated():
ans.user = self.user
else:
ans.user = None
ans.interview_uuid = self.interview_uuid
ans.text = self.cleaned_data['answer']
if commit: ans.save()
return ans
示例3: save
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import user [as 别名]
def save(self, commit=True):
if not self.cleaned_data["answer"]:
if self.fields["answer"].required:
raise ValidationError, _("This field is required.")
return
ans_list = []
for text in self.cleaned_data["answer"]:
ans = Answer()
ans.question = self.question
ans.session_key = self.session_key
if self.user.is_authenticated():
ans.user = self.user
else:
ans.user = None
ans.interview_uuid = self.interview_uuid
ans.text = text
if commit:
ans.save()
ans_list.append(ans)
return ans_list
示例4: create_answer
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import user [as 别名]
def create_answer(request):
user = User.objects.get(code=request.POST['user_code'])
image = Image.objects.get(pk=request.POST['image_id'])
a = Answer()
a.user = user
a.image = image
a.index_1 = request.POST['index_1']
a.index_2 = request.POST['index_2']
a.score = request.POST['score']
a.save()
user.answer_number += 1
user.save()
return HttpResponse()
示例5: experiment_page
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import user [as 别名]
def experiment_page(request):
participant_id = request.session['participant_id']
if not participant_id:
return HttpResponseRedirect("/")
# Get participant & an image set ID that we don't have yet.
participant = Participant.objects.get(id=participant_id)
if not participant:
return Http404()
if request.method == "GET":
answers_count = participant.answer_set.count()
image_sets = {x.imageSet_id for x in participant.answer_set.all()}
total_set = {x for x in range(1, 61)}
allowed = total_set.difference(image_sets)
if len(allowed) > 0:
random.seed()
idx = random.sample(allowed, 1)[0]
next_set = ImageSet.objects.get(id=idx)
if not next_set:
return HttpResponseServerError(content="No image set found")
# TODO : Add "which" parameter
data = {"image_set": next_set,
"num_images": "two" if participant.num_images is 2 else "three"}
return render_to_response("entry.html",
data,
context_instance=RequestContext(request))
else:
return HttpResponseRedirect("/survey")
elif request.method == "POST":
answer = Answer()
answer.user = participant
answer.imageSet_id=int(request.POST["image-set-id"])
answer.value = int(request.POST["dollar-value"])
# TODO : Add "which" parameter
answer.save()
return HttpResponseRedirect("/experiment")