evg-app-back/organisations/gqlTypes.py

111 lines
2.6 KiB
Python
Raw Normal View History

2021-01-10 15:51:59 +03:00
import graphene_django
2021-01-20 22:10:57 +03:00
from .models import Organisation, Role, Group, Teacher, Child, Organisator
from graphene import relay
import graphene
2021-01-10 15:51:59 +03:00
2021-01-20 22:10:57 +03:00
class OrganisatorType(graphene_django.DjangoObjectType):
class Meta:
model = Organisator
interfaces = (relay.Node,)
filter_fields = {
"name": ("exact", "contains"),
"surname": ("exact", "contains"),
"midname": ("exact", "contains"),
"org" : ("exact",),
"profile" : ("exact",),
"groups" : ("contains",)
}
2021-01-10 15:51:59 +03:00
class OrganisationType(graphene_django.DjangoObjectType):
class Meta:
model = Organisation
2021-01-20 22:10:57 +03:00
interfaces = (relay.Node,)
filter_fields = {
"name" : ("exact", "contains",),
}
children_length = graphene.Int()
classes_length = graphene.Int()
subjects = graphene.List(graphene.String)
def resolve_children_length(self, info):
print(self, self._meta.fields)
return len(self.child_set.all())
def resolve_classes_length(self, info):
return len(self.group_set.all())
def resolve_subjects(self, info):
return list(map(lambda x : x.name, self.subject_set.all()))
2021-01-10 15:51:59 +03:00
class RoleType(graphene_django.DjangoObjectType):
class Meta:
model = Role
class ChildType(graphene_django.DjangoObjectType):
2021-01-10 15:51:59 +03:00
class Meta:
model = Child
2021-01-20 22:10:57 +03:00
interfaces = (relay.Node,)
filter_fields = {
"name": ("exact", "contains"),
"surname": ("exact", "contains"),
"midname": ("exact", "contains"),
"org" : ("exact",),
"profile" : ("exact",),
"groups" : ("contains",)
}
pk = graphene.Int()
def resolve_pk(self, info): return self.pk
2021-01-10 15:51:59 +03:00
class TeacherType(graphene_django.DjangoObjectType):
2021-01-20 22:10:57 +03:00
class Meta:
model = Teacher
2021-01-20 22:10:57 +03:00
interfaces = (relay.Node,)
filter_fields = {
"name": ("exact", "contains"),
"surname": ("exact", "contains"),
"midname": ("exact", "contains"),
"org" : ("exact",),
"profile" : ("exact",),
"groups" : ("contains",)
}
pk = graphene.Int()
def resolve_pk(self, info): return self.pk
def resolve_local_lessons(self, info):
return self.subjectclasslocal_set.all()
from lessons.gqlTypes import LocalSubjectType
2021-01-20 22:10:57 +03:00
class GroupType(graphene_django.DjangoObjectType):
class Meta:
model = Group
interfaces = (relay.Node,)
filter_fields = {
"name" : ("exact", "contains"),
}
pk = graphene.Int()
classes = graphene.List(LocalSubjectType)
childrenLen = graphene.Int()
2021-01-20 22:10:57 +03:00
def resolve(self, info):
return self.pk
def resolve_classes(self, info):
return self.subjectclasslocal_set.all()
def resolve_childrenLen(self, info):
return len(self.child_set.all())