Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now use pltp.indexed_pl() instead of pltp.pl.all() #197

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions server/serverpl/classmanagement/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def course(request, pk):
'name': elem.json['title'],
'state': Answer.pl_state(elem, request.user)
}
for elem in item.pltp.pl.all()
for elem in item.pltp.indexed_pl()
]

activity.append({
Expand Down Expand Up @@ -103,7 +103,7 @@ def course_summary(request, pk):
except Course.DoesNotExist:
raise Http404("Impossible d'accéder à la page, cette classe n'existe pas.")
if request.user not in course.teacher.all():
logger.info("User '" + request.user.username
logger.info("User '" + request.user.username
+ "' denied to access summary of course'" + course.name + "'.")
raise PermissionDenied("Vous n'êtes pas professeur de cette classe.")

Expand Down Expand Up @@ -159,7 +159,7 @@ def activity_summary(request, pk, activity_pk):
student = list()
for user in course.student.all():
tp = list()
for pl in activity.pltp.pl.all():
for pl in activity.pltp.indexed_pl():
tp.append({
'name': pl.json['title'],
'state': Answer.pl_state(pl, user)
Expand All @@ -179,7 +179,7 @@ def activity_summary(request, pk, activity_pk):
'course_name': course.name,
'activity_name': activity.name,
'student': student,
'range_tp': range(len(activity.pltp.pl.all())),
'range_tp': range(len(activity.pltp.indexed_pl())),
'course_id': pk,
})

Expand All @@ -201,7 +201,7 @@ def student_summary(request, course_id, student_id):
tp = list()
for activity in activities:
question = list()
for pl in activity.pltp.pl.all():
for pl in activity.pltp.indexed_pl():
state = Answer.pl_state(pl, student)
question.append({
'state': state,
Expand Down
2 changes: 1 addition & 1 deletion server/serverpl/loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def reload_pltp(directory, rel_path, original):
warnings += pl_warnings
pl_list.append(pl)

originals = list(original.pl.all())
originals = list(original.indexed_pl())
original.pl.clear()
for pl in pl_list:
correspond = list(
Expand Down
2 changes: 1 addition & 1 deletion server/serverpl/loader/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __str__(self): # pragma: no cover
def delete(self, *args, **kwargs):
""" Overriding delete() to also delete his PL if they're not in
relation with any other PLTP """
pl_list = self.pl.all()
pl_list = self.indexed_pl()
logger.info("PLTP '" + self.sha1 + " (" + self.name + ")' has been deleted")
for pl in pl_list:
if len(pl.pltp_set.all()) <= 1:
Expand Down
10 changes: 5 additions & 5 deletions server/serverpl/playexo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def create_session_exercise(sender, instance, created, **kwargs):
"""When an ActivitySession is created, automatically create a SessionExercise for the PLTP
and every PL."""
if created:
for pl in instance.activity.pltp.pl.all():
for pl in instance.activity.pltp.indexed_pl():
SessionExercise.objects.create(session_activity=instance, pl=pl)
SessionExercise.objects.create(session_activity=instance) # For the pltp

Expand Down Expand Up @@ -359,7 +359,7 @@ def get_exercise(self, request, context=None):
dic = dict(self.context if not context else context)
dic['user_settings__'] = self.session_activity.user.profile
dic['user__'] = self.session_activity.user
dic['first_pl__'] = self.session_activity.activity.pltp.pl.all()[0].id
dic['first_pl__'] = self.session_activity.activity.pltp.indexed_pl()[0].id
for key in dic:
if type(dic[key]) is str:
dic[key] = Template(dic[key]).render(RequestContext(request, dic))
Expand All @@ -378,7 +378,7 @@ def get_navigation(self, request):
'state': None,
'title': self.session_activity.activity.pltp.json['title'],
}]
for pl in self.session_activity.activity.pltp.pl.all():
for pl in self.session_activity.activity.pltp.indexed_pl():
pl_list.append({
'id' : pl.id,
'state': Answer.pl_state(pl, self.session_activity.user),
Expand Down Expand Up @@ -510,7 +510,7 @@ def pl_state(pl, user):
@staticmethod
def pltp_state(pltp, user):
"""Return a list of tuples (pl_id, state) where state follow pl_state() rules."""
return [(pl.id, Answer.pl_state(pl, user)) for pl in pltp.pl.all()]
return [(pl.id, Answer.pl_state(pl, user)) for pl in pltp.indexed_pl()]


@staticmethod
Expand All @@ -536,7 +536,7 @@ def pltp_summary(pltp, user):
State.ERROR : [0.0, 0],
}

for pl in pltp.pl.all():
for pl in pltp.indexed_pl():
state[Answer.pl_state(pl, user)][1] += 1

nb_pl = max(sum([state[k][1] for k in state]), 1)
Expand Down
12 changes: 6 additions & 6 deletions server/serverpl/playexo/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,18 @@ def test_pl_state(self):

def test_pl_state(self):
self.assertEqual(Answer.pltp_state(self.pltp, self.user),
[(self.pltp.pl.all()[0].id, State.NOT_STARTED),
(self.pltp.pl.all()[1].id, State.NOT_STARTED)])
Answer.objects.create(pl=self.pltp.pl.all()[0], user=self.user, grade=10)
[(self.pltp.indexed_pl()[0].id, State.NOT_STARTED),
(self.pltp.indexed_pl()[1].id, State.NOT_STARTED)])
Answer.objects.create(pl=self.pltp.indexed_pl()[0], user=self.user, grade=10)
self.assertEqual(Answer.pltp_state(self.pltp, self.user),
[(self.pltp.pl.all()[0].id, State.PART_SUCC),
(self.pltp.pl.all()[1].id, State.NOT_STARTED)])
[(self.pltp.indexed_pl()[0].id, State.PART_SUCC),
(self.pltp.indexed_pl()[1].id, State.NOT_STARTED)])


def test_pltp_summary(self):
self.assertEqual(Answer.pltp_summary(self.pltp, self.user)[State.NOT_STARTED],
['100.0', '2'])
Answer.objects.create(pl=self.pltp.pl.all()[0], user=self.user, grade=10)
Answer.objects.create(pl=self.pltp.indexed_pl()[0], user=self.user, grade=10)
self.assertEqual(Answer.pltp_summary(self.pltp, self.user)[State.PART_SUCC], ['50.0', '1'])


Expand Down
2 changes: 1 addition & 1 deletion server/serverpl/playexo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def activity_view(request, activity_id):
exercise.save()

elif session.current_pl and action == "next":
pls = activity.pltp.pl.all()
pls = activity.pltp.indexed_pl()
for previous, next in zip(pls, list(pls[1:]) + [None]):
if previous == session.current_pl:
session.current_pl = next
Expand Down