Skip to content
Snippets Groups Projects

Resolve "Adapt to active school term"

Merged magicfelix requested to merge 319-adapt-to-active-school-term into master
3 files
+ 20
1
Compare changes
  • Side-by-side
  • Inline
Files
3
from django.core.exceptions import PermissionDenied
import graphene
from graphene_django import bypass_get_queryset
from graphene_django.types import DjangoObjectType
from reversion import create_revision, set_comment, set_user
@@ -32,7 +33,6 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
fields = (
"id",
"course",
"amends",
"subject",
"topic",
"homework",
@@ -62,6 +62,14 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
old_id = graphene.ID(required=False)
@staticmethod
@bypass_get_queryset
def resolve_amends(root: Documentation, info, **kwargs):
if hasattr(root, "_amends_prefetched"):
return root._amends_prefetched
return root.amends
@staticmethod
@bypass_get_queryset
def resolve_teachers(root: Documentation, info, **kwargs):
if not str(root.pk).startswith("DUMMY") and hasattr(root, "teachers"):
return root.teachers
@@ -100,6 +108,7 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
)
@staticmethod
@bypass_get_queryset
def resolve_participations(root: Documentation, info, **kwargs):
# A dummy documentation will not have any participations
if str(root.pk).startswith("DUMMY") or not hasattr(root, "participations"):
@@ -112,6 +121,11 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
p for p in root.participations.all() if p.person == info.context.user.person
]
return []
# Annotate participations with prefetched documentation data for personal notes
for participation in root.participations.all():
participation._prefetched_documentation = root
return root.participations.all()
Loading