diff --git a/evgenApp/__pycache__/settings.cpython-37.pyc b/evgenApp/__pycache__/settings.cpython-37.pyc index 28e9ca8..af690d1 100644 Binary files a/evgenApp/__pycache__/settings.cpython-37.pyc and b/evgenApp/__pycache__/settings.cpython-37.pyc differ diff --git a/evgenApp/settings.py b/evgenApp/settings.py index 584783f..19a6d98 100644 --- a/evgenApp/settings.py +++ b/evgenApp/settings.py @@ -103,8 +103,12 @@ WSGI_APPLICATION = 'evgenApp.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': "EvgenApp", + "USER": "postgres", + "PASSWORD" : "Ilvas2006", + "HOST" : "127.0.1.1", + "PORT" : "5432" } } diff --git a/hyperlinks/__pycache__/models.cpython-37.pyc b/hyperlinks/__pycache__/models.cpython-37.pyc index eaffc8d..213876c 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 7d2e876..84f1071 100644 --- a/hyperlinks/models.py +++ b/hyperlinks/models.py @@ -15,16 +15,4 @@ class HyperLink(models.Model): #@receiver(signal=post_save, sender=Organisator) #def org_recieve(sender, instance, **kwargs): -# HyperLink.objects.create(organ=instance) - - - -@receiver(signal=post_save, sender=Child) -def child_recieve(sender, instance, **kwargs): - HyperLink.objects.create(child=instance) - - - -@receiver(signal=post_save, sender=Teacher) -def teacher_recieve(sender, instance, **kwargs): - HyperLink.objects.create(teacher=instance) +# HyperLink.objects.create(organ=instance) \ No newline at end of file diff --git a/lessons/__pycache__/gqlTypes.cpython-37.pyc b/lessons/__pycache__/gqlTypes.cpython-37.pyc index 258ea64..8413773 100644 Binary files a/lessons/__pycache__/gqlTypes.cpython-37.pyc 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 faf1e7e..e79cefe 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 845478d..bde4bb5 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 index f201eff..e9eb125 100644 --- a/lessons/gqlTypes.py +++ b/lessons/gqlTypes.py @@ -28,6 +28,7 @@ class AnswerType(graphene_django.DjangoObjectType): interfaces = (relay.Node,) filter_fields = { "sheet" : ("exact",), + "number" : ("exact",) } pk = graphene.Int() @@ -43,13 +44,15 @@ class AnswerSheetType(graphene_django.DjangoObjectType): } + class TaskType(graphene_django.DjangoObjectType): class Meta: model = Task interfaces = (relay.Node,) filter_fields = { "test": ("exact",), - "types": ("contains",) + "types": ("contains",), + "number":("exact",) } pk = graphene.Int() @@ -68,6 +71,11 @@ class TestsType(graphene_django.DjangoObjectType): pk = graphene.Int() taskLen = graphene.Int() + answerLen = graphene.Int() + + def resolve_answerLen(self, info): + return len(self.answersheet_set.all()) + def resolve_pk(self, info): return self.id @@ -153,4 +161,11 @@ class TaskTypeType(graphene_django.DjangoObjectType): class Meta: model = taskType interfaces = (relay.Node,) + filter_fields = {} + + +class AnswerSheetType(graphene_django.DjangoObjectType): + class Meta: + model = AnswerSheet + interfaces = (relay.Node,) filter_fields = {} \ No newline at end of file diff --git a/lessons/migrations/0009_auto_20210210_2116.py b/lessons/migrations/0009_auto_20210210_2116.py new file mode 100644 index 0000000..4c16434 --- /dev/null +++ b/lessons/migrations/0009_auto_20210210_2116.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.5 on 2021-02-10 18:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lessons', '0008_auto_20210205_1858'), + ] + + operations = [ + migrations.AddField( + model_name='tests', + name='is_timing', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='tests', + name='time_sec', + field=models.IntegerField(default=300), + ), + ] diff --git a/lessons/migrations/__pycache__/0009_auto_20210210_2116.cpython-37.pyc b/lessons/migrations/__pycache__/0009_auto_20210210_2116.cpython-37.pyc new file mode 100644 index 0000000..3f88d46 Binary files /dev/null and b/lessons/migrations/__pycache__/0009_auto_20210210_2116.cpython-37.pyc differ diff --git a/lessons/models.py b/lessons/models.py index aa6f0aa..fc89e56 100644 --- a/lessons/models.py +++ b/lessons/models.py @@ -40,6 +40,8 @@ class Tests(models.Model): name = models.CharField(max_length=150) deadline = models.DateTimeField() lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE) + is_timing = models.BooleanField(default=False) + time_sec = models.IntegerField(default=300) class Type(models.Model): name = models.TextField(max_length=150) @@ -48,6 +50,10 @@ class Type(models.Model): class TaskType(models.Model): name = models.TextField() + + def __str__(self) : + return self.name + class Task(models.Model): theory = models.TextField() practise = models.TextField() @@ -80,18 +86,4 @@ class Answer(models.Model): content = models.TextField() number = models.IntegerField() completed = models.BooleanField(default=False) - score = models.IntegerField(default=0) - - -@receiver(post_save, sender=Tests) -def _post_save_receiver_(sender, instance, created, **kwargs): - print(created, instance, instance.lesson.type_lesson.group.child_set.all()) - if created: - for child in instance.lesson.type_lesson.group.child_set.all(): - AnswerSheet.objects.create(child=child, completed=False, test=instance) - -'''@receiver(post_save, sender=Task) -def _post_save_receiver(sender, instance, created, **kwargs): - if created: - for child in instance.test.lesson.type_lesson.group.child_set.all(): - Answer.objects.create(number=instance.number, sheet=child.answersheet_set.all().filter(test=instance.test)[0], content="")''' \ No newline at end of file + score = models.IntegerField(default=0) \ No newline at end of file diff --git a/lessons/schema.py b/lessons/schema.py index fd4cee2..59c1b95 100644 --- a/lessons/schema.py +++ b/lessons/schema.py @@ -17,6 +17,45 @@ from .gqlTypes import * from graphql_relay.node.node import from_global_id +class CreateAnwerSheet(graphene.Mutation): + class Arguments: + child = graphene.ID() + test = graphene.ID() + + answer = graphene.Field(AnswerSheetType) + + def mutate(self, info, child, test): + answerSheet = AnswerSheet.objects.create( + test=Tests.objects.get(id=from_global_id(test)[1]), + child=Child.objects.get(id=from_global_id(child)[1]), + completed=False + ) + return CreateAnwerSheet(answer=answerSheet) + + +class CreateAnswer(graphene.Mutation): + class Arguments: + sheet = graphene.ID() + data = graphene.String() + number = graphene.Int() + + answer = graphene.Field(AnswerType) + + def mutate(self, info, sheet, data, number): + print(number,sheet, "number") + sheet = AnswerSheet.objects.get(id=from_global_id(sheet)[1]) + candidate = Answer.objects.filter(sheet__id=sheet.id, number=number) + print(candidate) + if len(candidate): + candidate.all().delete() + answer = Answer.objects.create( + sheet = sheet, + content = data, + number = number, + ) + return CreateAnswer(answer=answer) + + class CreateLesson(graphene.Mutation): class Arguments: name = graphene.String() @@ -27,6 +66,7 @@ class CreateLesson(graphene.Mutation): lesson = graphene.Field(LessonType) def mutate(self, info, name, descr, subject): + print(from_global_id(subject), subject) lesson = Lesson.objects.create(name=name, descr=descr, type_lesson= SubjectClassLocal.objects.get(id=from_global_id(subject)[1])) return CreateLesson(ok=True, lesson=lesson) @@ -57,7 +97,7 @@ class DeleteLesson(graphene.Mutation): ok = graphene.Boolean() def mutate(self, info, id): - lesson = Lesson.objects.get(id=id) + lesson = Lesson.objects.get(id=from_global_id(id)[1]) if lesson == None: return DeleteLesson(ok=False) lesson.delete() return DeleteLesson(ok=True) @@ -137,7 +177,7 @@ class createTask(graphene.Mutation): def mutate(self, info, test_id, theory, practise, number, max_score, Type): task = Tests.objects.get(id=from_global_id(test_id)[1]) - print(task) + print(from_global_id(Type)) m = createModel(model=Task, fields = { "theory": theory, "practise": practise, @@ -170,16 +210,31 @@ class updateTask(graphene.Mutation): m = updateModel(Task, task, { "theory": [theory, task.theory], "practise": [practise, task.practise], - "number": [number, task.number], "max_score": [max_score, task.max_score], "Type": [taskType(from_global_id(Type)[1]), task.Type], "is_autoCheck": [autoCheck, task.is_autoCheck], "autoCheckData": [autoCheckData, task.autoCheckData], "is_timing": [is_time, task.is_timing], - "time" : [time, task.time] + "time" : [time, task.time], }) return updateTask(task=m) +class ScoringTasks(graphene.Mutation): + class Arguments: + answerSheetId = graphene.ID() + score = graphene.Int() + number = graphene.Int() + + answer = graphene.Field(AnswerType) + + + def mutate(self, info, answerSheetId, score=0, number=0): + answer = AnswerSheet.objects.get(id=from_global_id(answerSheetId)[1]).answer_set.all().filter(number=number)[0] + answer.score = score + answer.completed = True + answer.save() + return ScoringTasks(answer=answer) + class deleteTask(graphene.Mutation): class Arguments: @@ -427,6 +482,14 @@ class Mutation(graphene.ObjectType): deleteMaterial = DeleteMaterial.Field() changeMaterial = ChangeMaterail.Field() + + create_anwer_sheet = CreateAnwerSheet.Field() + + create_answer = CreateAnswer.Field() + + + scoring_tasks = ScoringTasks.Field() + class Query(graphene.ObjectType): all_test = DjangoFilterConnectionField(TestsType) @@ -460,5 +523,7 @@ class Query(graphene.ObjectType): tasks = DjangoFilterConnectionField(TaskType) task = relay.Node.Field(TaskType) + + schema = graphene.Schema(query=Query) \ No newline at end of file