Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __create_assignmentgroups_for_assignment(self, assignment):
"""
Generate AssignmentGroups for Assignment and
GroupComments for FeedbackSet
"""
groups = []
for num in range(RelatedStudent.objects.filter(period=assignment.parentnode).count()):
assignmentgroup = mommy.prepare('core.AssignmentGroup', parentnode=assignment)
groups.append(assignmentgroup)
AssignmentGroup.objects.bulk_create(groups)
relatedstudents = [relatedstudent for relatedstudent
in RelatedStudent.objects.filter(period=assignment.parentnode)]
relatedexaminers = [relatedexaminer for relatedexaminer
in RelatedExaminer.objects.filter(period=assignment.parentnode)]
assignmentgroups = [assignmentgroup for assignmentgroup
in AssignmentGroup.objects.filter(parentnode=assignment)]
candidates = []
list_index = 0
for relatedstudent in relatedstudents:
candidate = mommy.prepare(
'core.Candidate',
def add_relatedstudents(self, *users):
relatedstudents = []
for user in users:
if isinstance(user, RelatedStudent):
relatedstudent = user
else:
relatedstudent = RelatedStudent(
user=user)
relatedstudent.period = self.period
relatedstudents.append(relatedstudent)
RelatedStudent.objects.bulk_create(relatedstudents)
return self
def add_relatedstudents(self, *users):
relatedstudents = []
for user in users:
if isinstance(user, RelatedStudent):
relatedstudent = user
else:
relatedstudent = RelatedStudent(
user=user)
relatedstudent.period = self.period
relatedstudents.append(relatedstudent)
RelatedStudent.objects.bulk_create(relatedstudents)
return self
from devilry.simplified import (simplified_modelapi, FieldSpec, FilterSpecs,
FilterSpec)
from devilry.apps.core import models
from relatedusersbase import RelatedUsersBase
from relatedusersmetabase import RelatedUsersMetaBase
@simplified_modelapi
class SimplifiedRelatedStudent(RelatedUsersBase):
""" Simplified wrapper for :class:`devilry.apps.core.models.RelatedStudent`. """
class Meta(RelatedUsersMetaBase):
""" Defines what methods an Administrator can use on a RelatedStudent object using the Simplified API """
model = models.RelatedStudent
resultfields = RelatedUsersMetaBase.resultfields + FieldSpec('candidate_id')
searchfields = RelatedUsersMetaBase.searchfields + FieldSpec('candidate_id')
editablefields = RelatedUsersMetaBase.editablefields + ('candidate_id',)
filters = RelatedUsersMetaBase.filters + FilterSpecs(FilterSpec('candidate_id'))
# Create assignment groups and add students
for num in range(num_students):
assignment_group = coremodels.AssignmentGroup(
parentnode=assignment
)
assignment_group.save()
print(('Create assignment group#{}'.format(num)))
student_user = get_user_model()(
fullname='Student#{}'.format(num),
shortname='student#{}@example.com'.format(num)
)
student_user.save()
print(('Create studentuser#{}'.format(num)))
relatedstudent = coremodels.RelatedStudent(
user=student_user,
period=period
)
relatedstudent.save()
print(('Create relatedstudent#{}'.format(num)))
coremodels.Candidate(
relatedstudent=relatedstudent,
assignment_group=assignment_group
).save()
print(('Create candidate#{}'.format(num)))
assignment_groups.append(assignment_group.id)
# Random organize examiners
relatedexaminer_ids = [relatedexaminer_id for relatedexaminer_id in relatedexaminers]
assignmentgroup_ids = [group_id for group_id in assignment_groups]
def add_duck1100(self):
duck1100 = self.duckburgh.add_subject('duck1100',
long_name='DUCK1100 - Programming for the natural sciences')
duck1100.add_admins(self.thor)
relatedstudents = [RelatedStudent(user=self.april, tags='group1')]
relatedstudents.extend(self._as_relatedstudents(self.good_students.values(), 'group1'))
relatedstudents.extend(self._as_relatedstudents(self.bad_students.values(), 'group2'))
testsemester = duck1100.add_6month_active_period(
short_name='testsemester', long_name='Testsemester',
relatedstudents=relatedstudents,
relatedexaminers=[
RelatedExaminer(user=self.thor, tags=''),
RelatedExaminer(user=self.donald, tags='group1'),
RelatedExaminer(user=self.scrooge, tags='group2')
])
old_relatedstudentusers = [
self.april, self.bad_students['dewey'],
self.bad_students['louie'], self.bad_students['june'],
self.good_students['loki'], self.good_students['kvasir']]
old_relatedstudents = self._as_relatedstudents(old_relatedstudentusers)
def get_related_students_count(self):
return RelatedStudent.objects\
.filter(period=self.assignment.period, active=True)\
.distinct('user').count()
def __create_relatedstudents(self, selected_users):
period = self.request.cradmin_role
relatedstudents = []
for user in selected_users:
relatedstudent = RelatedStudent(
period=period,
user=user)
relatedstudents.append(relatedstudent)
RelatedStudent.objects.bulk_create(relatedstudents)
def add_duck1100(self):
duck1100 = self.duckburgh.add_subject(
short_name='duck1100',
long_name='DUCK1100 - Programming for the natural sciences')
duck1100.add_admins(self.thor)
relatedstudents = [
RelatedStudent(user=self.april, tags='group1'),
]
relatedstudents.extend(self._as_relatedstudents(self.good_students.values(), 'group1'))
relatedstudents.extend(self._as_relatedstudents(self.bad_students.values(), 'group2'))
testsemester = duck1100.add_6month_active_period(
short_name='testsemester', long_name='Testsemester',
relatedstudents=relatedstudents,
relatedexaminers=[
RelatedExaminer(user=self.thor, tags=''),
RelatedExaminer(user=self.donald, tags='group1'),
RelatedExaminer(user=self.scrooge, tags='group2')
])
# old_relatedstudentusers = [
# self.thor,
# self.april, self.bad_students['dewey'],
# self.bad_students['louie'], self.bad_students['june'],
def __get_relatedstudents(self):
"""
Get all ``RelatedStudents`` for the period.
Returns:
(QuerySet): QuerySet of :class:`~.devilry.apps.core.models.RelatedStudents`.
"""
relatedstudent_queryset = core_models.RelatedStudent.objects\
.filter(period=self.period)\
.filter(id__in=self.related_student_ids)\
.select_related('period', 'period__parentnode', 'user')\
.prefetch_related(
models.Prefetch(
'candidate_set',
queryset=self.__get_candidate_queryset()))
return relatedstudent_queryset