diff --git a/hyperlinks/__pycache__/models.cpython-37.pyc b/hyperlinks/__pycache__/models.cpython-37.pyc index e0997a5..eaffc8d 100644 Binary files a/hyperlinks/__pycache__/models.cpython-37.pyc and b/hyperlinks/__pycache__/models.cpython-37.pyc differ diff --git a/hyperlinks/models.py b/hyperlinks/models.py index b0772ea..7d2e876 100644 --- a/hyperlinks/models.py +++ b/hyperlinks/models.py @@ -13,9 +13,9 @@ class HyperLink(models.Model): child = models.OneToOneField(Child, null=True, on_delete=models.CASCADE, unique=False) organ = models.OneToOneField(Organisator, null=True, on_delete=models.CASCADE, unique=False) -@receiver(signal=post_save, sender=Organisator) -def org_recieve(sender, instance, **kwargs): - HyperLink.objects.create(organ=instance) +#@receiver(signal=post_save, sender=Organisator) +#def org_recieve(sender, instance, **kwargs): +# HyperLink.objects.create(organ=instance) diff --git a/lessons/LessonType.py b/lessons/LessonType.py new file mode 100644 index 0000000..620b96b --- /dev/null +++ b/lessons/LessonType.py @@ -0,0 +1,37 @@ +from .models import Lesson +import graphene +import graphene_django +from graphene import relay +from .gqlTypes import TestsType + + +class LessonType(graphene_django.DjangoObjectType): + class Meta: + model=Lesson + interfaces = (relay.Node,) + filter_fields = { + "name": ["exact", "contains"], + "descr": ["exact", "contains"] + } + pk = graphene.Int() + tests = graphene.List(TestsType) + testsLen = graphene.Int() + materialsLen = graphene.Int() + materials = graphene.List(Material) + + def resolve_tests(self, info): + return self.tests_set.all() + + def resolve_pk(self, info): + return self.pk + + def resolve_testsLen(self, info): + return len(self.tests_set.all()) + + + def resolve_materialsLen(self, info): + return len(self.materials_set.all()) + + + def resolve_materials(self, info): + return self.materials_set.all() \ No newline at end of file diff --git a/lessons/__pycache__/LessonType.cpython-37.pyc b/lessons/__pycache__/LessonType.cpython-37.pyc new file mode 100644 index 0000000..92ac0e9 Binary files /dev/null and b/lessons/__pycache__/LessonType.cpython-37.pyc differ diff --git a/lessons/__pycache__/gqlTypes.cpython-37.pyc b/lessons/__pycache__/gqlTypes.cpython-37.pyc new file mode 100644 index 0000000..5a5d4c0 Binary files /dev/null and b/lessons/__pycache__/gqlTypes.cpython-37.pyc differ diff --git a/lessons/__pycache__/models.cpython-37.pyc b/lessons/__pycache__/models.cpython-37.pyc index 9684f73..809b587 100644 Binary files a/lessons/__pycache__/models.cpython-37.pyc and b/lessons/__pycache__/models.cpython-37.pyc differ diff --git a/lessons/__pycache__/schema.cpython-37.pyc b/lessons/__pycache__/schema.cpython-37.pyc index 3e1d34c..072efcc 100644 Binary files a/lessons/__pycache__/schema.cpython-37.pyc and b/lessons/__pycache__/schema.cpython-37.pyc differ diff --git a/lessons/gqlTypes.py b/lessons/gqlTypes.py new file mode 100644 index 0000000..1d444d5 --- /dev/null +++ b/lessons/gqlTypes.py @@ -0,0 +1,146 @@ +import graphene +import graphene_django + +from .models import Subject, Lesson, SubjectClassLocal, Tests, Task, AnswerSheet, Answer, Materials +from organisations.gqlTypes import ChildType, TeacherType + +from organisations.models import Organisation, Group, Child, Teacher + +from graphene import relay +from graphene_django.filter import DjangoFilterConnectionField +from users.models import Profile + +from django.db.models import Model + + +class Material(graphene_django.DjangoObjectType): + class Meta: + model = Materials + +class AnswerType(graphene_django.DjangoObjectType): + class Meta: + model = Answer + interfaces = (relay.Node,) + filter_fields = { + "sheet" : ("exact",), + } + pk = graphene.Int() + + def resolve_pk(self, info): return self.pk + +class AnswerSheetType(graphene_django.DjangoObjectType): + class Meta: + model = AnswerSheet + interfaces = (relay.Node,) + filter_fields = { + "test" : ("exact",), + "child": ("exact",) + } + + +class TaskType(graphene_django.DjangoObjectType): + class Meta: + model = Task + interfaces = (relay.Node,) + filter_fields = { + "test": ("exact",), + "types": ("contains",) + } + pk = graphene.Int() + + def resolve_pk(self, info): + return self.pk + + +class TestsType(graphene_django.DjangoObjectType): + class Meta: + model = Tests + interfaces = (relay.Node,) + filter_fields = { + "name": ("exact", "contains"), + "lesson": ("exact",) + } + pk = graphene.Int() + taskLen = graphene.Int() + + def resolve_pk(self, info): + return self.id + + + def resolve_taskLen(self, info): + return len(self.task_set.all()) + + + +class SubjectType(graphene_django.DjangoObjectType): + class Meta: + model=Subject + interfaces = (relay.Node,) + + filter_fields = { + "name" : ("exact", "contains",), + "organisation" : ("exact",), + "teachers_give" : ("contains",) + } + pk = graphene.Int() + + def resolve_pk(self, info): return self.pk + + +class LessonType(graphene_django.DjangoObjectType): + class Meta: + model=Lesson + interfaces = (relay.Node,) + filter_fields = { + "name": ["exact", "contains"], + "descr": ["exact", "contains"] + } + pk = graphene.Int() + tests = graphene.List(TestsType) + testsLen = graphene.Int() + materialsLen = graphene.Int() + materials = graphene.List(Material) + + def resolve_tests(self, info): + return self.tests_set.all() + + def resolve_pk(self, info): + return self.pk + + def resolve_testsLen(self, info): + return len(self.tests_set.all()) + + + def resolve_materialsLen(self, info): + return len(self.materials_set.all()) + + + def resolve_materials(self, info): + return self.materials_set.all() + + +class LocalSubjectType(graphene_django.DjangoObjectType): + class Meta: + model=SubjectClassLocal + interfaces = (relay.Node,) + filter_fields = { + "name": ("exact", "contains"), + "id": ("exact",), + "group": ("exact",) + } + pk = graphene.Int() + teachers_set = graphene.List(TeacherType) + lessonsLen = graphene.Int() + + def resolve_pk(self, info): + return self.pk + + + def resolve_teachers_set(self, info): + return self.teachers.all() + + + def resolve_lessonsLen(self, info): + return len(self.lesson_set.all()) + + diff --git a/lessons/migrations/0007_lesson_time_lesson.py b/lessons/migrations/0007_lesson_time_lesson.py new file mode 100644 index 0000000..fd7f7d3 --- /dev/null +++ b/lessons/migrations/0007_lesson_time_lesson.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.5 on 2021-01-30 11:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lessons', '0006_auto_20210117_2008'), + ] + + operations = [ + migrations.AddField( + model_name='lesson', + name='time_lesson', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/lessons/migrations/0008_materials_lesson.py b/lessons/migrations/0008_materials_lesson.py new file mode 100644 index 0000000..d25cff8 --- /dev/null +++ b/lessons/migrations/0008_materials_lesson.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.5 on 2021-01-30 12:39 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('lessons', '0007_lesson_time_lesson'), + ] + + operations = [ + migrations.AddField( + model_name='materials', + name='lesson', + field=models.ForeignKey(default=3, on_delete=django.db.models.deletion.CASCADE, to='lessons.lesson'), + ), + ] diff --git a/lessons/migrations/0009_lesson_content.py b/lessons/migrations/0009_lesson_content.py new file mode 100644 index 0000000..e953d8d --- /dev/null +++ b/lessons/migrations/0009_lesson_content.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.5 on 2021-01-30 17:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lessons', '0008_materials_lesson'), + ] + + operations = [ + migrations.AddField( + model_name='lesson', + name='content', + field=models.TextField(default=''), + ), + ] diff --git a/lessons/migrations/0010_auto_20210203_0122.py b/lessons/migrations/0010_auto_20210203_0122.py new file mode 100644 index 0000000..19e1dc5 --- /dev/null +++ b/lessons/migrations/0010_auto_20210203_0122.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.5 on 2021-02-02 22:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lessons', '0009_lesson_content'), + ] + + operations = [ + migrations.AddField( + model_name='materials', + name='Type', + field=models.CharField(default='link', max_length=100), + ), + migrations.AddField( + model_name='materials', + name='data', + field=models.TextField(blank=True), + ), + ] diff --git a/lessons/migrations/__pycache__/0007_lesson_time_lesson.cpython-37.pyc b/lessons/migrations/__pycache__/0007_lesson_time_lesson.cpython-37.pyc new file mode 100644 index 0000000..6012566 Binary files /dev/null and b/lessons/migrations/__pycache__/0007_lesson_time_lesson.cpython-37.pyc differ diff --git a/lessons/migrations/__pycache__/0008_materials_lesson.cpython-37.pyc b/lessons/migrations/__pycache__/0008_materials_lesson.cpython-37.pyc new file mode 100644 index 0000000..7199082 Binary files /dev/null and b/lessons/migrations/__pycache__/0008_materials_lesson.cpython-37.pyc differ diff --git a/lessons/migrations/__pycache__/0009_lesson_content.cpython-37.pyc b/lessons/migrations/__pycache__/0009_lesson_content.cpython-37.pyc new file mode 100644 index 0000000..c6cb4a2 Binary files /dev/null and b/lessons/migrations/__pycache__/0009_lesson_content.cpython-37.pyc differ diff --git a/lessons/migrations/__pycache__/0010_auto_20210203_0122.cpython-37.pyc b/lessons/migrations/__pycache__/0010_auto_20210203_0122.cpython-37.pyc new file mode 100644 index 0000000..a755b90 Binary files /dev/null and b/lessons/migrations/__pycache__/0010_auto_20210203_0122.cpython-37.pyc differ diff --git a/lessons/models.py b/lessons/models.py index 2a6ee51..0c255df 100644 --- a/lessons/models.py +++ b/lessons/models.py @@ -24,11 +24,16 @@ class Lesson(models.Model): type_lesson = models.ForeignKey(SubjectClassLocal, on_delete=models.CASCADE) name = models.TextField(default="") descr = models.TextField(default="") + content = models.TextField(default="") + time_lesson = models.DateTimeField(auto_now=True) class Materials(models.Model): link = models.URLField() name = models.CharField(max_length=100, blank=True) + data = models.TextField(blank=True) + Type = models.CharField(max_length=100, default="link") + lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE, default=3) class Tests(models.Model): diff --git a/lessons/schema.py b/lessons/schema.py index 6587c73..60692ab 100644 --- a/lessons/schema.py +++ b/lessons/schema.py @@ -12,99 +12,10 @@ from users.models import Profile from django.db.models import Model - -class AnswerType(graphene_django.DjangoObjectType): - class Meta: - model = Answer - interfaces = (relay.Node,) - filter_fields = { - "sheet" : ("exact",), - } - pk = graphene.Int() - - def resolve_pk(self, info): return self.pk - -class AnswerSheetType(graphene_django.DjangoObjectType): - class Meta: - model = AnswerSheet - interfaces = (relay.Node,) - filter_fields = { - "test" : ("exact",), - "child": ("exact",) - } +from .gqlTypes import * -class TaskType(graphene_django.DjangoObjectType): - class Meta: - model = Task - interfaces = (relay.Node,) - filter_fields = { - "test": ("exact",), - "types": ("contains",) - } - pk = graphene.Int() - - def resolve_pk(self, info): - return self.pk - - -class TestsType(graphene_django.DjangoObjectType): - class Meta: - model = Tests - interfaces = (relay.Node,) - filter_fields = { - "name": ("exact", "contains"), - "lesson": ("exact",) - } - pk = graphene.Int() - - def resolve_pk(self, info): - return self.id - - - -class SubjectType(graphene_django.DjangoObjectType): - class Meta: - model=Subject - interfaces = (relay.Node,) - - filter_fields = { - "name" : ("exact", "contains",), - "organisation" : ("exact",), - "teachers_give" : ("contains",) - } - pk = graphene.Int() - - def resolve_pk(self, info): return self.pk - - -class LessonType(graphene_django.DjangoObjectType): - class Meta: - model=Lesson - interfaces = (relay.Node,) - filter_fields = { - "name": ["exact", "contains"], - "descr": ["exact", "contains"] - } - pk = graphene.Int() - - def resolve(self, info): - return self.pk - - -class LocalSubjectType(graphene_django.DjangoObjectType): - class Meta: - model=SubjectClassLocal - interfaces = (relay.Node,) - filter_fields = { - "name": ("exact", "contains"), - "id": ("exact",), - "group": ("exact",) - } - pk = graphene.Int() - - def resolve_pk(self, info): - return self.pk +from graphql_relay.node.node import from_global_id class CreateLesson(graphene.Mutation): class Arguments: @@ -412,6 +323,23 @@ class AnswerQuestion(graphene.Mutation): return AnswerQuestion(answer=answerT) +class CreateMaterial(graphene.Mutation): + class Arguments: + lesson_id = graphene.ID() + data = graphene.String() + name = graphene.String() + + material = graphene.Field(Material) + + + def mutate(self, info, lesson_id, data, name): + lessonId = from_global_id(lesson_id)[1] + print(lessonId) + lesson = Lesson.objects.get(id=lessonId) + material = Materials.objects.create(lesson=lesson, data=data, link="google.com", name=name) + return CreateMaterial(material=material) + + class Mutation(graphene.ObjectType): create_lesson = CreateLesson.Field() update_lesson_registration = UpdateLessonRegistration.Field() @@ -441,6 +369,9 @@ class Mutation(graphene.ObjectType): answer_question = AnswerQuestion.Field() + + create_material = CreateMaterial.Field() + class Query(graphene.ObjectType): all_test = DjangoFilterConnectionField(TestsType) diff --git a/organisations/__pycache__/gqlTypes.cpython-37.pyc b/organisations/__pycache__/gqlTypes.cpython-37.pyc index b764f7a..175e55a 100644 Binary files a/organisations/__pycache__/gqlTypes.cpython-37.pyc and b/organisations/__pycache__/gqlTypes.cpython-37.pyc differ diff --git a/organisations/__pycache__/query.cpython-37.pyc b/organisations/__pycache__/query.cpython-37.pyc index 75dc8c7..346f1cd 100644 Binary files a/organisations/__pycache__/query.cpython-37.pyc and b/organisations/__pycache__/query.cpython-37.pyc differ diff --git a/organisations/gqlTypes.py b/organisations/gqlTypes.py index d14c971..ff7dc97 100644 --- a/organisations/gqlTypes.py +++ b/organisations/gqlTypes.py @@ -3,7 +3,6 @@ from .models import Organisation, Role, Group, Teacher, Child, Organisator from graphene import relay import graphene -print(Teacher, Child) class OrganisatorType(graphene_django.DjangoObjectType): class Meta: @@ -25,28 +24,26 @@ class OrganisationType(graphene_django.DjangoObjectType): 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())) class RoleType(graphene_django.DjangoObjectType): class Meta: model = Role -class TeacherType(graphene_django.DjangoObjectType): - class Meta: - model = Teacher - 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 class ChildType(graphene_django.DjangoObjectType): @@ -68,6 +65,30 @@ class ChildType(graphene_django.DjangoObjectType): def resolve_pk(self, info): return self.pk +class TeacherType(graphene_django.DjangoObjectType): + + class Meta: + model = Teacher + 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 + class GroupType(graphene_django.DjangoObjectType): class Meta: model = Group @@ -77,6 +98,14 @@ class GroupType(graphene_django.DjangoObjectType): "name" : ("exact", "contains"), } pk = graphene.Int() + classes = graphene.List(LocalSubjectType) + childrenLen = graphene.Int() def resolve(self, info): - return self.pk \ No newline at end of file + return self.pk + + def resolve_classes(self, info): + return self.subjectclasslocal_set.all() + + def resolve_childrenLen(self, info): + return len(self.child_set.all()) \ No newline at end of file diff --git a/users/__pycache__/schema.cpython-37.pyc b/users/__pycache__/schema.cpython-37.pyc index 48e75c6..42ea728 100644 Binary files a/users/__pycache__/schema.cpython-37.pyc and b/users/__pycache__/schema.cpython-37.pyc differ diff --git a/users/schema.py b/users/schema.py index 44c26bb..087ae9f 100644 --- a/users/schema.py +++ b/users/schema.py @@ -38,10 +38,14 @@ class RegisterUserInput(graphene.InputObjectType): class RegisterUser(graphene.Mutation): class Arguments: input = RegisterUserInput(required=True) - user = graphene.Field(UserType) + ok = graphene.Boolean() def mutate(self, info, input=None): - return RegisterUser(User.objects.create_user(username=input.username, password=input.password)) + try: + User.objects.create_user(username=input.username, password=input.password) + except: + return RegisterUser(ok=False) + return RegisterUser(ok=True) class Mutation(graphene.ObjectType): token_auth = graphql_jwt.ObtainJSONWebToken.Field()