本文整理汇总了Python中students.models.Student.get_current方法的典型用法代码示例。如果您正苦于以下问题:Python Student.get_current方法的具体用法?Python Student.get_current怎么用?Python Student.get_current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类students.models.Student
的用法示例。
在下文中一共展示了Student.get_current方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context_data
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import get_current [as 别名]
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
示例2: assign
# 需要导入模块: from students.models import Student [as 别名]
# 或者: from students.models.Student import get_current [as 别名]
def assign(self):
"""
Do the real assignment based on object properties
"""
spacing = self.spacing
capacity_string = 'capacity_{:d}_free'.format(spacing)
order_by_string = "-{:s}".format(capacity_string)
exam_rooms = ExamRoom.objects.filter(available=True).order_by(order_by_string)
exam_students = Student.get_current(tutor_group__group_category=self.group_category, want_exam=True)
exam_students = exam_students.order_by('name', 'prename')
student_count = exam_students.count()
if exam_rooms.count() == 0 or student_count == 0:
return 0
maximum_capacity = exam_rooms.aggregate(maximum_capacity=Sum(capacity_string)).get('maximum_capacity')
# Set ratio so that all room gets equals percentage
ratio = student_count / maximum_capacity
# on minimal room mode and if the ratio is less then 90% the ratio is set to 90%
# e.g. the first rooms get filled by 90%. The other rooms are not used
if self.mode == 1 and ratio < 0.9:
ratio = 0.9
# returns each room as often as seats are available for the given ratio
exam_room_list = chain.from_iterable(repeat(room, room.seats(spacing, ratio)) for room in exam_rooms)
assign = partial(PersonToExamRoomAssignment, assignment=self)
assignments = (assign(person=student, room=room) for student, room in zip(exam_students, exam_room_list))
result = PersonToExamRoomAssignment.objects.bulk_create(assignments)
return len(result)