本文整理汇总了Python中students.models.Student类的典型用法代码示例。如果您正苦于以下问题:Python Student类的具体用法?Python Student怎么用?Python Student使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Student类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_object_to_db
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)
示例2: setUp
def setUp(self):
self.c = Client()
# Create the test badge.
self.b = Badge( name = "The Super Badge",
shortname = "superbadge",
description = "This badge is quite super.",
graphic = "superbadge" )
self.b.save()
# Create some test users.
self.u1 = User.objects.create_user("ishara",
"[email protected]",
"ishararulz")
self.u2 = User.objects.create_user("alexis",
"[email protected]",
"alexisrulz")
self.s1 = Student( user=self.u1 )
self.s2 = Student( user=self.u2 )
self.s1.save()
self.s2.save()
# Award the badge to s1
self.b.awarded_to.add( self.s2 )
self.b.save()
# Give the test users memorable names.
self.ishara = self.s1
self.alexis = self.s2
示例3: test_create_new_student
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
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: view_feedback
def view_feedback(request, name):
me = Student.from_request(request)
if "alerts" not in request.session: request.session["alerts"] = []
if not me:
request.session["alerts"].append(("alert-error","Please sign in first."))
return redirect("sign-in")
# First, try to get the challenge.
try: challenge = Challenge.objects.get(slug=name)
except exceptions.ObjectDoesNotExist: raise Http404()
# Now get all of the SOSses related to this user and challenge.
feedback = SOS.objects.filter(challenge=challenge, student=me)
# Mark feedback as helpful or not.
if "helpful" in request.GET or "unhelpful" in request.GET:
helpful = True
if "unhelpful" in request.GET: helpful = False
f_id = request.GET["helpful" if helpful else "unhelpful"]
if f_id.isdigit():
f = Feedback.objects.get(id=int(f_id))
if f.sos in feedback and f.helpful is None:
f.helpful = helpful
f.save()
if helpful:
f.author.award_xp(50)
me.award_xp(5)
LogEntry.log(request, "Marked as %shelpful"%("" if helpful else "un"))
return render(request, "feedback.html", {'challenge': challenge,
'feedback': feedback})
示例6: user_profile
def user_profile(request, username):
me = Student.from_request(request)
if "alerts" not in request.session: request.session["alerts"] = []
if not me:
request.session["alerts"].append(("alert-error","Please sign in first."))
return redirect("sign-in")
try: student = Student.objects.get( user=User.objects.get(username=username) )
except: return redirect("user_list")
# If we are doing a POST, then let's affect the output a bit.
form = ProfileEditForm( {"bio": me.bio, "twitter": me.twitter, "email": me.public_email} )
if request.method == "POST":
form = ProfileEditForm(request.POST)
if form.is_valid():
data = form.cleaned_data
me.bio = data["bio"]
me.public_email = data["email"]
me.twitter = data["twitter"]
me.save()
return redirect( "profile", username=me.username )
else:
request.session["alerts"].append(("alert-error",
"There were some issues with your profile update."))
for e in form.non_field_errors():
alerts.append( ("alert-error", e ) )
# Render the magic.
projects = list(me.owns.all())+list(me.works_on.all())
return render(request, "user_profile.html", {"student": student,
"collaborators": student.collaborators(),
"projects": projects,
"form": form,
'alerts': request.session.pop('alerts', []) } )
示例7: view_feedback
def view_feedback(request, name):
me = Student.from_request(request)
# First, try to get the challenge.
try: challenge = Challenge.objects.get(slug=name)
except exceptions.ObjectDoesNotExist: raise Http404()
# Now get all of the SOSses related to this user and challenge.
feedback = SOS.objects.filter(challenge=challenge, student=me)
# Mark feedback as helpful or not.
if "helpful" in request.GET or "unhelpful" in request.GET:
helpful = True
if "unhelpful" in request.GET: helpful = False
f_id = request.GET["helpful" if helpful else "unhelpful"]
if f_id.isdigit():
try:
f = Feedback.objects.get(id=int(f_id))
if f.sos in feedback and f.helpful is None:
f.helpful = helpful
f.save()
LogEntry.log(request, "Marked as %shelpful"%("" if helpful else "un"))
except exceptions.ObjectDoesNotExist:
LogEntry.log(request, "Feedback voting naughtiness.")
return render(request, "feedback.html", {'challenge': challenge,
'feedback': feedback})
示例8: register_student_add
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)
示例9: get_context_data
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
exam_rooms = ExamRoom.objects.filter(available=True)
context['student_count'] = Student.get_current(want_exam=True).order_by('name', 'prename').count()
context['free_places_1'] = sum([exam_room.capacity(1) for exam_room in exam_rooms])
context['free_places_2'] = sum([exam_room.capacity(2) for exam_room in exam_rooms])
return context
示例10: list_badges
def list_badges(request):
badge_list = Badge.objects.all()
for b in badge_list:
try: b.check = True if b.held_by( Student.from_request(request) ) else False
except exceptions.ObjectDoesNotExist: b.check = False
return render( request, "badge_list.html", {"badge_list":badge_list} )
示例11: view_board
def view_board(request, category):
me = Student.from_request(request)
# First, try to get the board.
try: board = DiscussionBoard.objects.get(slug=category)
except exceptions.ObjectDoesNotExist: raise Http404()
if not board.can_read(me): raise Http404()
# Get the page number!
page = 0
pagination = 50
if "page" in request.GET and request.GET["page"].isdigit():
page = max(0,int(request.GET["page"])-1)
# If this is a POST, we are creating a new topic. Redirect when finished.
if request.method == "POST":
if board.can_write(me):
content = str(request.POST.get("content"))
title = content[:100]+"..."
if "title" in request.POST:
title = request.POST["title"]
t = DiscussionTopic()
t.author = me
t.board = board
t.title = title
t.save()
p = DiscussionPost()
p.topic = t
p.author = me
p.content = content
p.save()
return redirect( "thread", category=board.slug, thread=t.id )
else:
return redirect( "board", category=board.slug )
# Get all of the topics, along with the last person who commented on them
# and when that was.
topic_tuples = []
topics = DiscussionTopic.objects.filter(board=board)
if not me.ta:
topics = topics.filter(hidden=False)
for t in topics[pagination*page:pagination*(page+1)]:
posts = DiscussionPost.objects.filter(topic=t, hidden=False).order_by("-timestamp")
count = len(posts)
new = False
if count == 0: posts = [None]
else: new = ( posts[0].timestamp > me.unread_since )
topic_tuples.append( (t,count,posts[0],new) )
return render( request, "forum_topics.html", {'board': board,
'topics': topic_tuples,
'alerts': request.session.pop('alerts', []),
'page': page+1,
'pages': (len(topic_tuples)/pagination)+1,
'can_write': board.can_write(me) } )
示例12: test_link_course
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')
示例13: student_add
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'})
示例14: view_board
def view_board(request, name):
me = Student.from_request(request)
if "alerts" not in request.session: request.session["alerts"] = []
if not me:
request.session["alerts"].append(("alert-error","Please sign in first."))
return redirect("sign-in")
# First, try to get the board.
try: board = DiscussionBoard.objects.get(slug=name)
except exceptions.ObjectDoesNotExist: raise Http404()
if board.restricted > me.level: raise Http404()
# Get the page number!
page = 0
pagination = 200
if "page" in request.GET and request.GET["page"].isdigit():
page = max(0,int(request.GET["page"])-1)
# If this is a POST, we are creating a new topic. Redirect when finished.
if request.method == "POST" and (me.level >= board.wrestricted or me.ta):
content = str(request.POST.get("content"))
title = content[:100]+"..."
if "title" in request.POST:
title = request.POST["title"]
t = DiscussionTopic()
t.author = me
t.board = board
t.title = title
t.save()
p = DiscussionPost()
p.topic = t
p.author = me
p.content = content
p.save()
return redirect( "thread", name=board.slug, thread=t.id )
# Get all of the topics, along with the last person who commented on them
# and when that was.
topic_tuples = []
for t in DiscussionTopic.objects.filter(hidden=False, board=board)[pagination*page:pagination*(page+1)]:
posts = DiscussionPost.objects.filter(topic=t, hidden=False).order_by("-timestamp")
count = len(posts)
new = False
if count == 0: posts = [None]
else: new = ( posts[0].timestamp > me.last_login )
topic_tuples.append( (t,count,posts[0],new) )
return render( request, "forum_topics.html", {'board': board,
'topics': topic_tuples,
'student': me,
'alerts': request.session.pop('alerts', []),
'page': page+1,
'pages': (len(topic_tuples)/pagination)+1 } )
示例15: test_log_student_deleted_event
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)