本文整理汇总了Python中students.models.Student.save方法的典型用法代码示例。如果您正苦于以下问题:Python Student.save方法的具体用法?Python Student.save怎么用?Python Student.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类students.models.Student
的用法示例。
在下文中一共展示了Student.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_log_student_updated_added_event
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def test_log_student_updated_added_event(self):
"""Check logging signal for newly created dtudent"""
# add own root handler to catch student signals output
out = StringIO()
handler = logging.StreamHandler(out)
logging.root.addHandler(handler)
# now create student, this should raise new message inside our logger output file
student = Student(first_name='Demo', last_name='Student')
student.save()
# check output file content
out.seek(0)
self.assertEqual(out.readlines()[-1],
'Student added: Demo Student (ID: %d)\n' % student.id)
# now update existing student and check last line in out
student.ticket = '12345'
student.save()
out.seek(0)
self.assertEqual(out.readlines()[-1],
'Student updated: Demo Student (ID: %d)\n' % student.id)
# remove our handler from root logger
logging.root.removeHandler(handler)
示例2: _add_object_to_db
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def _add_object_to_db(self, name):
if name == 'student':
student = Student(
first_name=self._random_value('first_name'),
last_name=self._random_value('last_name'),
ticket=self._random_value(),
birthday=timezone.now(),
)
student.save()
if name == 'group':
group = Group(
title=self._random_value('title'),
notes='note about group',
)
group.save()
if name == 'user':
user = User(
username=self._random_value('username'),
first_name=self._random_value('first_name'),
last_name=self._random_value('last_name'),
email=self._random_value("email") + '@example.com',
)
# User model have an unique field 'username'.
# Generated 'username' can be not unique
# in compare with existing objects.
# In case of exception repeat creating object 'user'.
try:
user.save()
except:
self._add_object_to_db(name)
示例3: test_create_new_student
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def test_create_new_student(self):
new_student = Student(name='New Student',
dob=datetime.today(),
civil_id='1234567890',
mobile_number=generate_random_numbers(12),
home_number=generate_random_numbers(12),
parent_number=generate_random_numbers(12))
new_student.save()
self.assertIsInstance(new_student, Student)
self.assertTrue(new_student.pk)
self.assertEquals('P', new_student.status)
示例4: create_demo_user
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def create_demo_user(request):
me = Student.from_request(request)
if not settings.DEMO_MODE:
request.session["alerts"].append(("alert-error","Demo users are not enabled at this time."))
return redirect("index")
username = "DemoUser%d"%len(Student.objects.all())
user = User.objects.create_user(username, username+"@example.com", str(random.randint(100000000,999999999)))
user.save()
student = Student(user=user)
student.save()
user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, user)
return redirect("index")
示例5: register_student_add
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def register_student_add(request):
if request.method=="POST":
first_name=request.POST['first_name']
last_name=request.POST['last_name']
gender=request.POST['gender']
username=request.POST['username']
password=request.POST['password']
class_id=request.POST['class_id']
# hash the password
hashed_password = sha256_crypt.encrypt(password)
student=Student(first_name=first_name,last_name=last_name,gender=gender,username=username,password=hashed_password,classid_id=class_id)
student.save()
return login_student_form(request)
示例6: student_add
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def student_add(request):
if request.method == 'POST':
form = StudentForm(request.POST)
if form.is_valid():
print form.cleaned_data
student = Student(
first_name=form.cleaned_data['first_name'],
last_name=form.cleaned_data['last_name'],
email=form.cleaned_data['email'],
phone_number=form.cleaned_data['phone_number'],
package=form.cleaned_data['package'],
# courses=form.cleaned_data['courses'], ???????????????????
)
student.save()
return redirect('students_list')
else:
form = StudentForm()
return render(request, 'student_edit.html', {'form': form, 'title': 'Add student'})
示例7: test_link_course
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def test_link_course(self):
course = Course.objects.create(
name='Django Base',
short_description='Django Base Course')
course.save()
student = Student(
name="Ivan",
surname="Ivanov",
date_of_birth="1999-09-09",
email="[email protected]",
phone="1234567890",
address="Mykolyiv",
skype="test")
student.save()
student.courses.add(course)
response = self.client.get('/students/1/')
self.assertContains(response, '/courses/{}/'.format(student.id))
self.assertContains(response, 'Django Base')
示例8: test_log_student_deleted_event
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def test_log_student_deleted_event(self):
"""Check logging signals for deleted student"""
student = Student(first_name='Demo', last_name='Student')
student.save()
# now override signal
# add own root handler to catch student signals output
out = StringIO()
handler = logging.StreamHandler(out)
logging.root.addHandler(handler)
# delete existing student and check logger output
sid = student.id
student.delete()
out.seek(0)
self.assertEqual(out.readlines()[-1], 'Student Demo Student deleted (ID: %d)\n' % sid)
# remove our handler from root logger
logging.root.removeHandler(handler)
示例9: StudentTests
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
class StudentTests(TestCase):
def setUp(self):
self.c = Client()
self.u1 = User.objects.create_user("ishara",
"[email protected]",
"ishararulz")
self.s1 = Student( user=self.u1 )
self.s1.save()
# Give the test users memorable names.
self.ishara = self.s1
# Test User Connection decorators.
def test_user_fields(self):
self.assertEquals(self.s1.username, self.u1.username)
self.assertEquals(self.s1.email, self.u1.email)
# Test the Profile page.
def test_profile_page(self):
response = self.c.get("/~ishara")
self.assertEqual(response.status_code, 200)
示例10: student_add
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def student_add(request):
if request.method == 'POST':
form = StudentForm(request.POST)
if form.is_valid():
student = Student()
student.name = form.cleaned_data['student_name']
student.surname = form.cleaned_data['student_surname'],
student.email = form.cleaned_data['student_email'],
student.phone = form.cleaned_data['student_phone'],
student.package = form.cleaned_data['student_package']
student.save()
return redirect('Student_list')
else:
form = StudentForm(initial={
'student_name': '',
'student_surname': '',
'student_email': '',
'student_phone': '',
'student_package': '',
})
return render(request,'students/edit.html', {'form': form})
示例11: test_log_student_deleted_event
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def test_log_student_deleted_event(self):
"""Check logging signal for deleted student"""
# add own root handler to catch student signals output
out = StringIO()
handler = logging.StreamHandler(out)
logging.root.addHandler(handler)
# now create and delete student, this should raise new message inside
# our logger output file
student = Student(first_name='Demo', last_name='Student', ticket='123')
student.save()
student_id = student.id
student.delete()
# check output file content
out.seek(0)
self.assertEqual(out.readlines()[-1],
'Student deleted: Demo Student (ID: %d)\n' % student_id)
# remove our handler from root logger
logging.root.removeHandler(handler)
示例12: test_Entry_Fields_Links
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
def test_Entry_Fields_Links(self):
course = Course.objects.create(
name='Django Base',
short_description='Django Base Course')
course.save()
student = Student(
name="Ivan",
surname="Ivanov",
date_of_birth="1999-09-09",
email="[email protected]",
phone="1234567890",
address="Mykolyiv",
skype="test")
student.save()
student.courses.add(course)
response = self.client.get('/students/')
self.assertContains(response, 'Django Base')
self.assertContains(response, '/students/edit/{}/'.format(student.id))
self.assertContains(response, '/students/remove/{}/'.format(student.id))
self.assertContains(response, '/students/add/')
self.assertEqual(student.name, "Ivan")
self.assertEqual(student.date_of_birth, "1999-09-09")
self.assertEqual(course.name, 'Django Base')
self.assertEqual(student.courses.all()[0], course)
示例13: TestMooc
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
class TestMooc(TestCase):
def setUp(self):
self.c = Client()
self.u1 = User.objects.create_user("ishara",
"[email protected]",
"ishararulz")
self.u1.save()
self.s1 = Student( user=self.u1 )
self.s1.save()
p = Page(name="index", content="Hello world")
p.save()
p = Page(name="test", content="This is a test.")
p.save()
# Give the test users memorable names.
self.ishara = self.s1
# Try to go to the home page.
def test_home_page(self):
response = self.c.get("/")
self.assertEqual(response.status_code, 200)
self.assertTrue("/sign-up/" in response.content)
# Log in and go to the home page.
def test_logged_in_dash(self):
self.c.login(username="ishara", password="ishararulz")
response = self.c.get("/")
self.assertEqual(response.status_code, 200)
self.assertTrue("/sign-out/" in response.content)
# Make sure searching works.
def test_search(self):
response = self.c.get("/search/?query=world", follow=True)
self.assertTrue( "/help/index/" in response.content )
示例14: TestNESViews
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
class TestNESViews(TestCase):
def setUp(self):
self.c = Client()
self.u1 = User.objects.create_user("ishara",
"[email protected]",
"ishararulz")
self.u1.save()
self.s1 = Student( user=self.u1, twitter="isharacomix" )
self.s1.save()
# Give the test users memorable names.
self.ishara = self.s1
self.G = Game(title="Foo", code="")
self.G.save()
self.G.authors.add(self.ishara)
#
def test_arcade(self):
response = self.c.get("/arcade/1/")
self.assertEqual(response.status_code, 200)
self.assertTrue("http://twitter.com/isharacomix" in response.content)
response = self.c.get("/arcade/1/?download", follow=True)
self.assertEqual(response.status_code, 200)
示例15: StudentModelTests
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import save [as 别名]
class StudentModelTests(TestCase):
def setUp(self):
self.o1 = Ophase.objects.create(name="Testophase 1", is_active=True)
self.gc = OphaseCategory.objects.create(name="Super Mario", priority=10)
self.assertEqual(self.gc.name, "Super Mario")
self.tg = TutorGroup.objects.create(
ophase=self.o1, name="Mario", group_category=self.gc)
self.assertEqual(self.tg.name, "Mario")
self.st = Student(prename="John", name="Doe", email="[email protected]",
tutor_group=self.tg, want_exam=True)
self.n1 = Newsletter(name='Test Newsletter',
description='This newsletter is only for test')
def test_student_create(self):
"""Ensure creating of a student object works"""
stud1 = Student.objects.create(
prename='Cora',
name='Nickerson',
email='[email protected]',
tutor_group=self.tg,
want_exam=True,
)
stud1.save()
# check that save works
self.assertEqual(stud1.prename, 'Cora')
self.assertEqual(stud1.name, 'Nickerson')
self.assertEqual(stud1.tutor_group, self.tg)
self.assertEqual(stud1.want_exam, True)
self.assertEqual(stud1.ophase, self.o1)
# test __str__
tg_string = self.tg.__str__()
self.assertEqual(stud1.__str__(), 'Nickerson, Cora (%s)' % (tg_string))
# The E-Mail is stored even if the student did not select any
# newsletter
self.assertEqual(stud1.email, '[email protected]')
self.assertEqual(stud1.want_newsletter(), False)
# Add a newsletter
self.n1.save()
stud1.newsletters.add(self.n1)
self.assertEqual(stud1.want_newsletter(), True)
def test_student_update(self):
"""Ensure update of a student object works"""
stud1 = self.st
stud1.save()
# check values
self.assertEqual(stud1.prename, 'John')
self.assertEqual(stud1.name, 'Doe')
self.assertEqual(stud1.email, '[email protected]')
self.assertEqual(stud1.tutor_group, self.tg)
self.assertEqual(stud1.want_exam, True)
self.assertEqual(stud1.ophase, self.o1)
stud1.prename = 'John Peter'
stud1.save()
self.assertEqual(stud1.prename, 'John Peter')
self.assertEqual(stud1.name, 'Doe')
self.assertEqual(stud1.email, '[email protected]')
self.assertEqual(stud1.tutor_group, self.tg)
self.assertEqual(stud1.want_exam, True)
self.assertEqual(stud1.ophase, self.o1)
def test_student_foreign_key_ophase(self):
"""Ensure Student is created with active Ophase as ForeignKey."""
# create Student with an active Ophase
self.st.save()
self.assertEqual(self.st.ophase.name, "Testophase 1")
# create another Ophase which is active (i.e. old Ophase becomes inactive) and update old Person
# Ophase ForeignKey should stay the same as before!
Ophase.objects.create(name="Testophase 2", is_active=True)
self.o1.is_active = False
self.o1.save()
self.st.email = "[email protected]"
self.st.save()
st = Student.objects.get(pk=self.st.pk)
self.assertEqual(st.ophase.name, "Testophase 1")
self.assertEqual(st.email, "[email protected]")
self.assertEqual(Student.objects.count(), 1)
# Delete the Ophase object
self.o1.delete()
#.........这里部分代码省略.........