Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def autocreate_delivery(group):
active_deadline = group.get_active_deadline()
cand = group.candidates.all()[0]
delivery = active_deadline.deliveries.create(delivered_by=cand, successful=True)
delivery.add_file('helloworld.txt', ['hello cruel world'])
delivery.add_file('helloworld.py', ['print "hello world"'])
delivery.add_file('helloworld.java', [
'// Too much code for a sane "hello world"'])
others = Delivery.objects.filter(deadline__assignment_group=group).order_by("-number")
if others.count() == 1:
if active_deadline.deadline < datetime.now():
if randint(0, 100) <= 30:
# 30% chance to get the first delivery after the deadline
offset = timedelta(minutes=-randint(1, 20))
logging.info(" (deliveries after deadline)")
else:
offset = timedelta(hours=randint(0, 15),
minutes=randint(0, 59))
delivery.time_of_delivery = active_deadline.deadline - offset
else:
# Deadline is in the future. Deliver a random time before
# "now". They can not deliver more than 5 deliveries (see
# create_example_deliveries_and_feedback), so if
# we say 5*3 hours in the past as a minimum for the first
# delivery, we will never get deliveries in the future
def autocreate_delivery(group):
active_deadline = group.get_active_deadline()
cand = group.candidates.all()[0]
delivery = active_deadline.deliveries.create(delivered_by=cand, successful=True)
delivery.add_file('helloworld.txt', ['hello cruel world'])
delivery.add_file('helloworld.py', ['print "hello world"'])
delivery.add_file('helloworld.java', [
'// Too much code for a sane "hello world"'])
others = Delivery.objects.filter(deadline__assignment_group=group).order_by("-number")
if others.count() == 1:
if active_deadline.deadline < datetime.now():
if randint(0, 100) <= 30:
# 30% chance to get the first delivery after the deadline
offset = timedelta(minutes=-randint(1, 20))
logging.info(" (deliveries after deadline)")
else:
offset = timedelta(hours=randint(0, 15),
minutes=randint(0, 59))
delivery.time_of_delivery = active_deadline.deadline - offset
else:
# Deadline is in the future. Deliver a random time before
# "now". They can not deliver more than 5 deliveries (see
# create_example_deliveries_and_feedback), so if
# we say 5*3 hours in the past as a minimum for the first
# delivery, we will never get deliveries in the future
# Candidates
if len(pathsplit) > 3:
usernames = pathsplit[3].split(',')
users = []
for u in usernames:
try:
user = get_user_model().objects.get(shortname=u)
except get_user_model().DoesNotExist:
user = get_user_model().objects.create_user(username=u)
users.append(user)
assignment_group = AssignmentGroup(parentnode=assignment)
assignment_group.clean()
assignment_group.save()
for user in users:
assignment_group.candidates.add(Candidate(student=user))
last = assignment_group
return last
Examples::
assignmentgroup = create_from_path(
'ifi:inf1100.spring05.oblig1.student1,student2')
oblig1 = create_from_path(
'ifi:inf1100.spring05.oblig1')
"""
split = path.split(':', 1)
nodes = split[0].split('.')
pathsplit = split[1].split('.')
# Subject
subjectname = pathsplit[0]
subject = Subject(short_name=subjectname,
long_name=subjectname.capitalize())
try:
subject.clean()
subject.save()
except:
subject = Subject.objects.get(short_name=subjectname)
last = subject
# Period
if len(pathsplit) > 1:
periodname = pathsplit[1]
period = Period(parentnode=subject, short_name=periodname,
long_name=periodname.capitalize(), start_time=timezone.now(),
end_time=timezone.now() + timedelta(10))
try:
period.clean()
'ifi:inf1100.spring05.oblig1')
"""
split = path.split(':', 1)
nodes = split[0].split('.')
pathsplit = split[1].split('.')
# Subject
subjectname = pathsplit[0]
subject = Subject(short_name=subjectname,
long_name=subjectname.capitalize())
try:
subject.clean()
subject.save()
except:
subject = Subject.objects.get(short_name=subjectname)
last = subject
# Period
if len(pathsplit) > 1:
periodname = pathsplit[1]
period = Period(parentnode=subject, short_name=periodname,
long_name=periodname.capitalize(), start_time=timezone.now(),
end_time=timezone.now() + timedelta(10))
try:
period.clean()
period.save()
except:
period = Period.objects.get(parentnode=subject,
short_name=periodname)
last = period
def add_students(self, *users):
candidates = [Candidate(student=user) for user in users]
self.add_candidates(*candidates)
return self
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
score = models.IntegerField()
introtext = models.TextField()
text = models.TextField()
@simplified_modelapi
class SimplifiedUser(object):
#@classmethod
#def read_authorize(cls, user, obj):
#return True
class Meta:
model = User
resultfields = FieldSpec('id', 'first', 'last', 'email', 'score',
textfields=['introtext', 'text'])
searchfields = FieldSpec('first', 'last')
methods = []
@restful_modelapi
class RestUser(ModelRestfulView):
class Meta:
simplified = SimplifiedUser
belongs_to = 'RestUser'
has_many = 'RestUser'
# Override to avoid having to add the rest as an url
@classmethod
def get_rest_url(cls, *args, **kwargs):
return '/restuser'