first commit

This commit is contained in:
Ilia 2021-03-20 02:26:38 +03:00
parent e4987f7092
commit 49b4cdee6c
134 changed files with 216 additions and 1970 deletions

@ -1 +0,0 @@
Subproject commit 4be809b3dbdfa14caf3adc6a5b5024a163ee3b8b

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,15 +1,11 @@
import graphene import graphene
import users.schema
import organisations.schema
import lessons.schema
import hyperlinks.schema
class Query(users.schema.Query, organisations.schema.Query, import users.schema
lessons.schema.Query, hyperlinks.schema.Query, graphene.ObjectType):
class Query(users.schema.Query, graphene.ObjectType):
pass pass
class Mutation(users.schema.Mutation, organisations.schema.Mutation, class Mutation(users.schema.Mutation, graphene.ObjectType):
lessons.schema.Mutation, hyperlinks.schema.Mutation, graphene.ObjectType):
pass pass

View File

@ -40,10 +40,7 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django_filters', 'django_filters',
'users', "users"
'organisations',
'lessons',
'hyperlinks'
] ]
GRAPHENE = { GRAPHENE = {
'SCHEMA': 'evgenApp.schema.schema', 'SCHEMA': 'evgenApp.schema.schema',

View File

View File

@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@ -1,5 +0,0 @@
from django.apps import AppConfig
class HyperlinksConfig(AppConfig):
name = 'hyperlinks'

View File

@ -1,26 +0,0 @@
# Generated by Django 3.1.5 on 2021-01-20 17:35
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
('organisations', '0005_auto_20210120_1944'),
]
operations = [
migrations.CreateModel(
name='HyperLink',
fields=[
('link', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('child', models.OneToOneField(blank=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.child')),
('organ', models.OneToOneField(blank=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.organisator')),
('teacher', models.OneToOneField(blank=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.teacher')),
],
),
]

View File

@ -1,30 +0,0 @@
# Generated by Django 3.1.5 on 2021-01-20 18:19
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('organisations', '0005_auto_20210120_1944'),
('hyperlinks', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='hyperlink',
name='child',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.child'),
),
migrations.AlterField(
model_name='hyperlink',
name='organ',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.organisator'),
),
migrations.AlterField(
model_name='hyperlink',
name='teacher',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.teacher'),
),
]

View File

@ -1,18 +0,0 @@
from django.db import models
from organisations.models import Organisator, Child, Teacher
import uuid
from django.dispatch import receiver
from django.db.models.signals import post_save
class HyperLink(models.Model):
link = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=False)
teacher = models.OneToOneField(Teacher, null=True, on_delete=models.CASCADE, unique=False)
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)

View File

@ -1,51 +0,0 @@
import graphene
import graphene_django
from organisations.gqlTypes import TeacherType
from .models import HyperLink
from graphene import relay
from django.contrib.auth.models import User
class HyperLinkType(graphene_django.DjangoObjectType):
class Meta:
model = HyperLink
class getProfile(graphene.Mutation):
class Arguments:
profile_token = graphene.ID()
user_id = graphene.ID()
id = graphene.ID()
user_type = graphene.String()
def mutate(self, info, profile_token, user_id):
user_type = ""
user = User.objects.get(id=user_id)
print(HyperLink.objects.all())
hl = HyperLink.objects.get(link=profile_token)
print(hl, "hl")
model = hl.teacher or hl.child or hl.organ
if hl.teacher: user_type = "teacher"
if hl.child: user_type = "child"
if hl.organ: user_type = "organ"
print(model, "profile")
model.delete()
model.profile = user.profile
model.save()
return getProfile(id=model.id, user_type = user_type)
class Mutation(graphene.ObjectType):
get_profile = getProfile.Field()
class Query(graphene.ObjectType):
hyper_links = graphene.Field(graphene.List(HyperLinkType))
def resolve_hyper_links(self, info):
return HyperLink.objects.all()
schema = graphene.Schema(query=Query, mutation=Mutation)

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@ -1,37 +0,0 @@
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()

View File

View File

@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@ -1,5 +0,0 @@
from django.apps import AppConfig
class LessonsConfig(AppConfig):
name = 'lessons'

View File

@ -1,27 +0,0 @@
from .models import Subject, SubjectClassLocal
from organisations.models import Organisation
def extendOrganisationSubject(org, sub_name):
Subject.objects.create(name=sub_name, organisation=org)
def addSubjectToGroup(group, subName, subject):
SubjectClassLocal.objects.create(name=subName, subject=subject, group=group)
def addClassToTeacher(classLocal, teacher):
classLocal.teachers.add(teacher)
def removeTeacherFromClass(classLocal, teacher):
classLocal.teachers.remove(teacher)
def addLessonToClass(classLocal):
Lesson.objects.create(type_lesson=classLocal)
def addTestToLesson(lesson, deadline, name):
Tests.objects.create(name=name, deadline=deadline, lesson=lesson)
def addTaskToTest(test, theory, practise, mark):
Task.objects.create(theory=theory, practise=practise, test=test, number=mark)

View File

@ -1,171 +0,0 @@
import graphene
import graphene_django
from .models import Subject, Lesson, SubjectClassLocal, Tests, Task, AnswerSheet, Answer, Materials, TaskType as taskType
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
interfaces = (relay.Node,)
filter_fields = {
"name": ("exact",)
}
class AnswerType(graphene_django.DjangoObjectType):
class Meta:
model = Answer
interfaces = (relay.Node,)
filter_fields = {
"sheet" : ("exact",),
"number" : ("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",),
"number":("exact",)
}
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()
answerLen = graphene.Int()
def resolve_answerLen(self, info):
return len(self.answersheet_set.all())
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())
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 = {}

View File

@ -1,125 +0,0 @@
# Generated by Django 3.1.5 on 2021-02-05 08:53
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('organisations', '0005_auto_20210120_1944'),
]
operations = [
migrations.CreateModel(
name='Lesson',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField(default='')),
('descr', models.TextField(default='')),
('content', models.TextField(default='')),
('time_lesson', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='Subject',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('organisation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.organisation')),
('teachers_give', models.ManyToManyField(to='organisations.Teacher')),
],
),
migrations.CreateModel(
name='Task',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('theory', models.TextField()),
('practise', models.TextField()),
('number', models.IntegerField()),
('max_score', models.IntegerField(default=0)),
],
),
migrations.CreateModel(
name='Type',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField(max_length=150)),
],
),
migrations.CreateModel(
name='Theme',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=150)),
('tasks', models.ManyToManyField(to='lessons.Task')),
],
),
migrations.CreateModel(
name='Tests',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=150)),
('deadline', models.DateTimeField()),
('lesson', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lessons.lesson')),
],
),
migrations.AddField(
model_name='task',
name='test',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lessons.tests'),
),
migrations.AddField(
model_name='task',
name='types',
field=models.ManyToManyField(to='lessons.Type'),
),
migrations.CreateModel(
name='SubjectClassLocal',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.group')),
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lessons.subject')),
('teachers', models.ManyToManyField(to='organisations.Teacher')),
],
),
migrations.CreateModel(
name='Materials',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('link', models.URLField()),
('name', models.CharField(blank=True, max_length=100)),
('data', models.TextField(blank=True)),
('Type', models.CharField(default='link', max_length=100)),
('lesson', models.ForeignKey(default=3, on_delete=django.db.models.deletion.CASCADE, to='lessons.lesson')),
],
),
migrations.AddField(
model_name='lesson',
name='type_lesson',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lessons.subjectclasslocal'),
),
migrations.CreateModel(
name='AnswerSheet',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('completed', models.BooleanField(default=False)),
('child', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.child')),
('test', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lessons.tests')),
],
),
migrations.CreateModel(
name='Answer',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
('number', models.IntegerField()),
('completed', models.BooleanField(default=False)),
('score', models.IntegerField(default=0)),
('sheet', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lessons.answersheet')),
],
),
]

View File

@ -1,38 +0,0 @@
# Generated by Django 3.1.5 on 2021-02-05 10:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('lessons', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='task',
name='Type',
field=models.CharField(default='line', max_length=150),
),
migrations.AddField(
model_name='task',
name='autoCheckData',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='task',
name='is_autoCheck',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='task',
name='is_timing',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='task',
name='time',
field=models.IntegerField(default=30),
),
]

View File

@ -1,26 +0,0 @@
# Generated by Django 3.1.5 on 2021-02-05 12:41
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('lessons', '0002_auto_20210205_1326'),
]
operations = [
migrations.CreateModel(
name='TaskType',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
],
),
migrations.AlterField(
model_name='task',
name='Type',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lessons.tasktype'),
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 3.1.5 on 2021-02-05 12:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('lessons', '0003_auto_20210205_1541'),
]
operations = [
migrations.AlterField(
model_name='task',
name='Type',
field=models.CharField(default='line', max_length=150),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 3.1.5 on 2021-02-05 12:44
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('lessons', '0004_auto_20210205_1543'),
]
operations = [
migrations.AlterField(
model_name='task',
name='Type',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lessons.tasktype'),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 3.1.5 on 2021-02-05 15:48
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('lessons', '0005_auto_20210205_1544'),
]
operations = [
migrations.AlterField(
model_name='task',
name='test',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lessons.tests'),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 3.1.5 on 2021-02-05 15:57
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('lessons', '0006_auto_20210205_1848'),
]
operations = [
migrations.AlterField(
model_name='task',
name='test',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lessons.tests'),
),
]

View File

@ -1,22 +0,0 @@
# Generated by Django 3.1.5 on 2021-02-05 15:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('lessons', '0007_auto_20210205_1857'),
]
operations = [
migrations.RemoveField(
model_name='task',
name='test',
),
migrations.AddField(
model_name='task',
name='test',
field=models.ManyToManyField(to='lessons.Tests'),
),
]

View File

@ -1,23 +0,0 @@
# 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),
),
]

View File

@ -1,89 +0,0 @@
from django.db import models
from organisations.models import Organisation, Teacher, Group, Child
from django.dispatch import receiver
from django.db.models.signals import post_save
class Subject(models.Model):
name = models.CharField(max_length=100)
organisation = models.ForeignKey(Organisation, on_delete=models.CASCADE)
teachers_give = models.ManyToManyField(Teacher)
class SubjectClassLocal(models.Model):
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
teachers = models.ManyToManyField(Teacher)
group = models.ForeignKey(Group, on_delete=models.CASCADE)
name = models.CharField(max_length=100, unique=False)
def __str__(self):
return self.name
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):
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)
class TaskType(models.Model):
name = models.TextField()
def __str__(self) :
return self.name
class Task(models.Model):
theory = models.TextField()
practise = models.TextField()
test = models.ManyToManyField(Tests)
types = models.ManyToManyField(Type)
number = models.IntegerField()
max_score = models.IntegerField(default=0)
is_timing = models.BooleanField(default=False)
time = models.IntegerField(default=30)
Type = models.ForeignKey(TaskType, on_delete=models.CASCADE)
is_autoCheck = models.BooleanField(default=False)
autoCheckData = models.TextField(blank=True)
class Theme(models.Model):
tasks = models.ManyToManyField(Task)
name = models.CharField(max_length=150)
class AnswerSheet(models.Model):
child = models.ForeignKey(Child, on_delete=models.CASCADE)
completed = models.BooleanField(default=False)
test = models.ForeignKey(Tests, on_delete=models.CASCADE)
class Answer(models.Model):
sheet = models.ForeignKey(AnswerSheet, on_delete=models.CASCADE)
content = models.TextField()
number = models.IntegerField()
completed = models.BooleanField(default=False)
score = models.IntegerField(default=0)

View File

@ -1,529 +0,0 @@
import graphene
import graphene_django
from .models import Subject, Lesson, SubjectClassLocal, Tests, Task, AnswerSheet, Answer
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
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()
descr = graphene.String()
subject = graphene.ID()
ok = graphene.Boolean()
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)
class UpdateLessonRegistration(graphene.Mutation):
class Arguments:
id = graphene.ID()
descr = graphene.String()
name = graphene.String()
ok = graphene.Boolean()
def mutate(self, info, id, descr=None, name=None):
lesson = Lesson.objects.get(id=from_global_id(id)[1]) or None
if lesson == None: return UpdateLessonRegistration(ok=False)
descr_upd = lesson.descr
name_upd = lesson.name
if descr != None: descr_upd = descr
if name != None: name_upd = name
lesson.descr = descr_upd
lesson.name = name_upd
lesson.save()
return UpdateLessonRegistration(ok=True)
class DeleteLesson(graphene.Mutation):
class Arguments:
id = graphene.ID()
ok = graphene.Boolean()
def mutate(self, info, id):
lesson = Lesson.objects.get(id=from_global_id(id)[1])
if lesson == None: return DeleteLesson(ok=False)
lesson.delete()
return DeleteLesson(ok=True)
import datetime #fix
class CreateTest(graphene.Mutation):
class Arguments:
lesson_id = graphene.ID()
name = graphene.String()
deadline = graphene.Date()
test = graphene.Field(TestsType)
def mutate(self, info, lesson_id, name, deadline=None):
lesson = Lesson.objects.get(id=from_global_id(lesson_id)[1])
t = Tests.objects.create(name=name, lesson=lesson, deadline=datetime.datetime.now())
return CreateTest(test=t)
class updateTestRegistration(graphene.Mutation):
class Arguments:
test_id = graphene.ID()
name = graphene.String()
deadline = graphene.Date()
test = graphene.Field(TestsType)
def mutate(self, info, test_id, name=None, deadline=None):
test = Tests.objects.get(id=from_global_id(test_id)[1])
name_changed = test.name
deadline_changed = test.deadline
if name != None: name_changed = name
if deadline != None : deadline_changed = deadline
test.name = name_changed
test.deadline = deadline_changed
test.save()
return updateTestRegistration(test)
from collections.abc import Mapping
class deleteTest(graphene.Mutation):
class Arguments:
test_id = graphene.ID()
ok = graphene.Boolean()
def mutate(self, info, test_id):
test = Tests.objects.get(id=from_global_id(test_id)[1])
test.delete()
return deleteTest(ok=True)
def createModel(model, fields):
return model.objects.create(**fields)
def updateModel(model:Model, instance:Model, fields:Mapping):
print(fields)
updated_fields = {}
for key, value in fields.items():
updated_fields.update({key: value[0] or value[1]})
print(updated_fields)
for key, value in updated_fields.items():
setattr(instance, key, value)
instance.save()
return instance
def deleteModel(model:Model):
model.delete()
class createTask(graphene.Mutation):
class Arguments:
test_id = graphene.ID()
theory = graphene.String()
practise = graphene.String()
number = graphene.Int()
max_score = graphene.Int()
Type = graphene.String()
task = graphene.Field(TaskType)
def mutate(self, info, test_id, theory, practise, number, max_score, Type):
task = Tests.objects.get(id=from_global_id(test_id)[1])
print(from_global_id(Type))
m = createModel(model=Task, fields = {
"theory": theory,
"practise": practise,
"number": number,
"max_score": max_score,
"Type" : taskType(id=from_global_id(Type)[1])
})
print(m)
m.test.set([task])
m.save()
return createTask(task=m)
class updateTask(graphene.Mutation):
class Arguments:
task_id = graphene.ID()
theory = graphene.String()
practise = graphene.String()
number = graphene.Int()
max_score = graphene.Int()
Type = graphene.ID()
autoCheck = graphene.Boolean()
autoCheckData = graphene.String()
is_time = graphene.Boolean()
time = graphene.Int()
task = graphene.Field(TaskType)
def mutate(self, info, task_id, theory=None, practise=None, number=None, max_score=None,
Type=None, autoCheck=None, autoCheckData=None, is_time=None, time=None):
task = Task.objects.get(id=from_global_id(task_id)[1])
m = updateModel(Task, task, {
"theory": [theory, task.theory],
"practise": [practise, task.practise],
"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],
})
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:
task_id = graphene.ID()
ok = graphene.Boolean()
def mutate(self, info, task_id):
deleteModel(Task.objects.get(id=task_id))
return deleteTask(ok=True)
class addChildToGroup(graphene.Mutation):
class Arguments:
group_id = graphene.ID()
child_id = graphene.ID()
child = graphene.Field(ChildType)
def mutate(self, info, group_id, child_id):
group = Group.objects.get(id=group_id)
child = Child.objects.get(id=child_id)
child.groups.add(group)
child.save()
return addChildToGroup(child=child)
class addChildToOrg(graphene.Mutation):
class Arguments:
org_id = graphene.ID()
child_id = graphene.ID()
name = graphene.String()
surname = graphene.String()
midname = graphene.String()
child = graphene.Field(ChildType)
def mutate(self, info, org_id, child_id, name, surname, midname):
user = Profile.objects.get(id=child_id)
org = Organisation.objects.get(id=org_id)
child = Child.objects.create(profile=user, org=org, name=name or "",
surname = surname or "", midname = midname or "")
return addChildToOrg(child=child)
class CreateSubjectClass(graphene.Mutation):
class Arguments:
group_id = graphene.ID()
subject_id = graphene.ID()
name = graphene.String()
subject_class = graphene.Field(LocalSubjectType)
def mutate(self, info, group_id, subject_id, name):
group = Group.objects.get(id=group_id)
subject = Subject.objects.get(id=subject_id)
local_subject = SubjectClassLocal.objects.create(name=name,
group=group, subject=subject)
return CreateSubjectClass(subject_class=local_subject)
class CreateSubject(graphene.Mutation):
class Arguments:
org_id = graphene.ID()
name = graphene.String()
subject = graphene.Field(SubjectType)
def mutate(self, info, org_id, name):
org = Organisation.objects.get(id=org_id)
subject = Subject.objects.create(name=name, organisation=org)
return CreateSubject(subject)
class UpdateSubjectReg(graphene.Mutation):
class Arguments:
subject_id = graphene.ID()
name = graphene.String()
subject = graphene.Field(SubjectType)
def mutate(self, info, subject_id, name):
subject = Subject.objects.get(id=subject_id)
subject.name = name or subject.name
subject.save()
return UpdateSubjectReg(subject=subject)
class DeleteSubject(graphene.Mutation):
class Arguments:
subject_id = graphene.ID()
ok = graphene.Boolean()
def mutate(self, info, subject_id):
subject = Subject.objects.get(id=subject_id)
subject.delete()
return DeleteSubject(ok=True)
class UpdateSubjectLocalReg(graphene.Mutation):
class Arguments:
subject_local_id = graphene.ID()
name = graphene.String()
subject_local = graphene.Field(LocalSubjectType)
def mutate(self, info, subject_local_id, name):
subject = SubjectClassLocal.objects.get(id=subject_local_id)
subject.name = name or subject.name
subject.save()
return UpdateSubjectLocalReg(subject_local=subject)
class DeleteSubjectLocal(graphene.Mutation):
class Arguments:
subject_local_id = graphene.ID()
ok = graphene.Boolean()
def mutate(self, info, subject_local_id):
SubjectClassLocal.objects.get(id=subject_local_id).delete()
return DeleteSubjectLocal(ok=True)
class AddSubjectToTeacher(graphene.Mutation):
class Arguments:
subject_id = graphene.ID()
teacher_id = graphene.ID()
teacher = graphene.Field(TeacherType)
def mutate(self, info, subject_id, teacher_id):
teacher = Teacher.objects.get(id=teacher_id)
subject= Subject.objects.get(id=subject_id)
subject.teachers_give.add(teacher)
subject.save()
return AddSubjectToTeacher(teacher=teacher)
class RemoveSubjectFromTeacher(graphene.Mutation):
class Arguments:
subject_id = graphene.ID()
teacher_id = graphene.ID()
teacher = graphene.Field(TeacherType)
def mutate(self, info, subject_id, teacher_id):
subject = Subject.objects.get(id=subject_id)
subject.teachers_give.all().filter(id=teacher_id)[0].delete()
return RemoveSubjectFromTeacher(teacher=Teacher.objects.get(id=teacher_id))
class AnswerQuestion(graphene.Mutation):
class Arguments:
answer_table_id = graphene.ID()
answer = graphene.String()
answer = graphene.Field(AnswerType)
def mutate(self, info, answer_table_id, answer):
answerT = Answer.objects.get(id=answer_table_id)
answerT.content = answer
answerT.completed = True
answerT.save()
return AnswerQuestion(answer=answerT)
class CreateMaterial(graphene.Mutation):
class Arguments:
lesson_id = graphene.ID()
data = graphene.String()
name = graphene.String()
lessonType = graphene.String()
material = graphene.Field(Material)
def mutate(self, info, lesson_id, data, name, lessonType):
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, Type=lessonType)
return CreateMaterial(material=material)
class DeleteMaterial(graphene.Mutation):
class Arguments:
material_id = graphene.ID()
ok = graphene.Boolean()
def mutate(self, info, material_id):
material_id = from_global_id(material_id)[1]
Materials.objects.get(id=material_id).delete()
return DeleteMaterial(ok=True)
class ChangeMaterail(graphene.Mutation):
class Arguments:
material_id = graphene.ID()
data = graphene.String()
name = graphene.String()
material = graphene.Field(Material)
def mutate(self, info, material_id, data, name):
material_id = from_global_id(material_id)[1]
material = Materials.objects.get(id=material_id)
material.name = name or material.name
material.data = data or material.data
material.save()
return ChangeMaterail(material=material)
class Mutation(graphene.ObjectType):
create_lesson = CreateLesson.Field()
update_lesson_registration = UpdateLessonRegistration.Field()
delete_lesson = DeleteLesson.Field()
create_test = CreateTest.Field()
update_test_registration = updateTestRegistration.Field()
delete_test = deleteTest.Field()
create_task = createTask.Field()
update_task = updateTask.Field()
delete_task = deleteTask.Field()
add_child_to_group = addChildToGroup.Field()
add_child_to_org = addChildToOrg.Field()
create_subject_class = CreateSubjectClass.Field()
update_subject_class = UpdateSubjectLocalReg.Field()
delete_subject_class = DeleteSubjectLocal.Field()
create_subject = CreateSubject.Field()
update_subject = UpdateSubjectReg.Field()
delete_subject = DeleteSubject.Field()
add_subject_to_teacher = AddSubjectToTeacher.Field()
remove_subject_from_teacher = RemoveSubjectFromTeacher.Field()
answer_question = AnswerQuestion.Field()
create_material = CreateMaterial.Field()
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)
test = relay.Node.Field(TestsType)
all_subject = DjangoFilterConnectionField(SubjectType)
subject = relay.Node.Field(SubjectType)
answer_sheet = relay.Node.Field(AnswerSheetType)
all_answer_sheet = DjangoFilterConnectionField(AnswerSheetType)
answer = relay.Node.Field(AnswerType)
all_answer = DjangoFilterConnectionField(AnswerType)
all_lessons = DjangoFilterConnectionField(LessonType)
lessons = relay.Node.Field(LessonType)
subject_class = relay.Node.Field(LocalSubjectType)
subject_classes = DjangoFilterConnectionField(LocalSubjectType)
materials = DjangoFilterConnectionField(Material)
material = relay.Node.Field(Material)
gettaskType = relay.Node.Field(TaskTypeType)
taskTypes = DjangoFilterConnectionField(TaskTypeType)
tasks = DjangoFilterConnectionField(TaskType)
task = relay.Node.Field(TaskType)
schema = graphene.Schema(query=Query)

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@ -1,5 +0,0 @@
from django.apps import AppConfig
class OrganisationsConfig(AppConfig):
name = 'organisations'

View File

@ -1,111 +0,0 @@
import graphene_django
from .models import Organisation, Role, Group, Teacher, Child, Organisator
from graphene import relay
import graphene
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",)
}
class OrganisationType(graphene_django.DjangoObjectType):
class Meta:
model = Organisation
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()))
class RoleType(graphene_django.DjangoObjectType):
class Meta:
model = Role
class ChildType(graphene_django.DjangoObjectType):
class Meta:
model = Child
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 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
interfaces = (relay.Node,)
filter_fields = {
"name" : ("exact", "contains"),
}
pk = graphene.Int()
classes = graphene.List(LocalSubjectType)
childrenLen = graphene.Int()
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())

View File

@ -1,75 +0,0 @@
# Generated by Django 3.1.5 on 2021-01-07 21:23
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('users', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Group',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20)),
],
),
migrations.CreateModel(
name='Organisation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
],
),
migrations.CreateModel(
name='Role',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name='Subject',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('org', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.organisation')),
],
),
migrations.CreateModel(
name='Teacher',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=150)),
('surname', models.CharField(blank=True, max_length=150)),
('midname', models.CharField(blank=True, max_length=150)),
('groups', models.ManyToManyField(to='organisations.Group')),
('org', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.organisation')),
('profile', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='users.profile')),
('subject_area', models.ManyToManyField(to='organisations.Subject')),
],
),
migrations.AddField(
model_name='group',
name='org',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.organisation'),
),
migrations.CreateModel(
name='Child',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=150)),
('surname', models.CharField(blank=True, max_length=150)),
('midname', models.CharField(blank=True, max_length=150)),
('groups', models.ManyToManyField(to='organisations.Group')),
('org', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.organisation')),
('profile', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='users.profile')),
],
),
]

View File

@ -1,20 +0,0 @@
# Generated by Django 3.1.5 on 2021-01-07 21:39
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0001_initial'),
('organisations', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='teacher',
name='profile',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.profile'),
),
]

View File

@ -1,20 +0,0 @@
# Generated by Django 3.1.5 on 2021-01-07 21:42
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0001_initial'),
('organisations', '0002_auto_20210107_2139'),
]
operations = [
migrations.AlterField(
model_name='child',
name='profile',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.profile'),
),
]

View File

@ -1,20 +0,0 @@
# Generated by Django 3.1.5 on 2021-01-08 20:13
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('organisations', '0003_auto_20210107_2142'),
]
operations = [
migrations.RemoveField(
model_name='teacher',
name='subject_area',
),
migrations.DeleteModel(
name='Subject',
),
]

View File

@ -1,37 +0,0 @@
# Generated by Django 3.1.5 on 2021-01-20 16:44
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0001_initial'),
('organisations', '0004_auto_20210108_2013'),
]
operations = [
migrations.AlterField(
model_name='child',
name='profile',
field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='users.profile'),
),
migrations.AlterField(
model_name='teacher',
name='profile',
field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='users.profile'),
),
migrations.CreateModel(
name='Organisator',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=150)),
('surname', models.CharField(blank=True, max_length=150)),
('midname', models.CharField(blank=True, max_length=150)),
('groups', models.ManyToManyField(to='organisations.Group')),
('org', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.organisation')),
('profile', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='users.profile')),
],
),
]

Some files were not shown because too many files have changed in this diff Show More