本文整理汇总了Python中models.Test.save方法的典型用法代码示例。如果您正苦于以下问题:Python Test.save方法的具体用法?Python Test.save怎么用?Python Test.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Test
的用法示例。
在下文中一共展示了Test.save方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_path_or_resource
# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import save [as 别名]
def test_path_or_resource(self):
c = Client()
obj = TestModel()
obj.test = "TESTING"
obj.save()
resource = resources1.Test_1_1_Resource()
list_path = resource.get_resource_list_uri()
object_path = resource.get_resource_uri(obj)
result = c._path_or_resource(list_path)
expected = list_path
self.assertEqual(result, expected, "Bare path.\nResult:%s\nExpected:%s" % (result, expected))
result = c._path_or_resource(list_path, obj)
expected = list_path
self.assertEqual(result, expected, "Bare path w/obj.\nResult:%s\nExpected:%s" % (result, expected))
result = c._path_or_resource(resource)
expected = list_path
self.assertEqual(result, expected, "Empty resource.\nResult:%s\nExpected:%s" % (result, expected))
result = c._path_or_resource(resource, obj)
expected = object_path
self.assertEqual(result, expected, "Populated resource.\nResult:%s\nExpected:%s" % (result, expected))
示例2: create_test_backup
# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import save [as 别名]
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
示例3: save_test
# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import save [as 别名]
def save_test(request):
print 'POST: ', request.POST
rule = None
if request.POST['pattern']:
rule = Rule(pattern=request.POST['pattern'], replacement=request.POST['replacement'])
rule.save()
if rule:
test = Test(input=request.POST['input'], output=request.POST['output'], rule=rule)
else:
test = Test(input=request.POST['input'], output=request.POST['output'])
test.save()
response_data = {}
return HttpResponse(simplejson.dumps(response_data), mimetype="application/json")
示例4: create_test
# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import save [as 别名]
def create_test(request):
c=None
if request.method=='POST':
testname = request.POST.get('testname','')
number = request.POST.get('q_number','')
if 'course' in request.session:
c = Course.objects.get(name=request.session['course'])
if c :
t = Test(name=testname,course = c.id ,question_number=number)
t.save()
c.number_test+=1
c.save()
return HttpResponseRedirect(reverse('teacher_course',args=(c.name,)))
else :
return HttpResponse('wrong method')
示例5: send_presses
# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import save [as 别名]
def send_presses(request, instance_name):
instance = get_object_or_404(ExperimentInstance, name=instance_name)
sessions = Session.objects.filter(instance=instance)
searched_session = 0
_dict = request.POST.copy()
for session in sessions:
tests = Test.objects.filter(session=session)
if len(tests) < instance.definition.session_length:
searched_session = session
new_test = Test(session=searched_session, number=_dict['config'])
new_test.save()
del(_dict['config'])
print _dict
for i in _dict:
new_press = Press(test=new_test, key_number=int(i), time=int(_dict[i]), correct=True)
new_press.save()
return JsonResponse({'ok': 'ok'})
示例6: test4031
# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import save [as 别名]
def test4031(request):
data = json.loads(request.body)
group = data["group"]
score = data["score"]
if group == None or score == None:
return HttpResponse("Missing fields: group or score.")
test = Test(name = "4031", group = group, score = score)
test.save()
text = "Vous avez eu " + str(score) + " nombres.</br>"
text += "<a href='https://github.com/melodieverroeulst/psy'>Code Source</a>"
return HttpResponse(json.dumps({
"title": "Merci!",
"text": text,
"html": True,
"redirectTo": "/"
}))
示例7: post
# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import save [as 别名]
def post(self, request):
form = UploadFileForm(request.POST, request.FILES)
msg = ''
if form.is_valid():
test = Test(
start_time = convert_time(form.cleaned_data['start']),
end_time = convert_time(form.cleaned_data['end']),
author_id = UserProfile.objects.get(user__id=request.user.id),
time = int(form.cleaned_data['time'])
)
test.save()
try:
test.room = Room.objects.get(id=form.cleaned_data.get('room'))
except:
test.room = None
finally:
test.save()
try:
self.handle_uploaded_file(test.id, request.FILES['file'])
except:
test.delete()
msg = {'error': 'Wystąpił konflikt terminów. Test nie został dodany.'}
return render(request, self.template_name, {'form': form, 'msg': msg})
else:
test.name = self.get_test_name_from_file(test.id)
test.save()
return HttpResponseRedirect(reverse('tests'))
else:
msg = {'error': u'Wystąpił błąd podczas ładowania pliku.'}
form = UploadFileForm()
return render(request, self.template_name, {'form': form, 'msg': msg})
示例8: parse
# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import save [as 别名]
def parse(self):
t = Test(name="aaaaaaaasd", type="yxc")
t.save()
return t.name