mirror of
https://github.com/evgen-app/evg-app-back.git
synced 2024-11-22 08:46:34 +03:00
finish backend
This commit is contained in:
parent
f0593b71c2
commit
c102376dc5
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/../../../../../../:\Users\ilvsl\evgen-app\evg-app-back\.idea/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
23
.idea/evg-app-back.iml
Normal file
23
.idea/evg-app-back.iml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="django" name="Django">
|
||||||
|
<configuration>
|
||||||
|
<option name="rootFolder" value="$MODULE_DIR$" />
|
||||||
|
<option name="settingsModule" value="evgenApp/settings.py" />
|
||||||
|
<option name="manageScript" value="$MODULE_DIR$/manage.py" />
|
||||||
|
<option name="environment" value="<map/>" />
|
||||||
|
<option name="doNotUseTestRunner" value="false" />
|
||||||
|
<option name="trackFilePattern" value="migrations" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.7 (emp-design)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
<component name="TemplatesService">
|
||||||
|
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (emp-design)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/evg-app-back.iml" filepath="$PROJECT_DIR$/.idea/evg-app-back.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"python.pythonPath": "C:\\Users\\ilvsl\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe"
|
||||||
|
}
|
BIN
evgenApp/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
evgenApp/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
evgenApp/__pycache__/schema.cpython-37.pyc
Normal file
BIN
evgenApp/__pycache__/schema.cpython-37.pyc
Normal file
Binary file not shown.
BIN
evgenApp/__pycache__/settings.cpython-37.pyc
Normal file
BIN
evgenApp/__pycache__/settings.cpython-37.pyc
Normal file
Binary file not shown.
BIN
evgenApp/__pycache__/urls.cpython-37.pyc
Normal file
BIN
evgenApp/__pycache__/urls.cpython-37.pyc
Normal file
Binary file not shown.
BIN
evgenApp/__pycache__/wsgi.cpython-37.pyc
Normal file
BIN
evgenApp/__pycache__/wsgi.cpython-37.pyc
Normal file
Binary file not shown.
|
@ -1,11 +1,15 @@
|
||||||
import graphene
|
import graphene
|
||||||
import users.schema
|
import users.schema
|
||||||
import organisations.schema
|
import organisations.schema
|
||||||
|
import lessons.schema
|
||||||
|
import hyperlinks.schema
|
||||||
|
|
||||||
class Query(users.schema.Query, organisations.schema.Query, graphene.ObjectType):
|
class Query(users.schema.Query, organisations.schema.Query,
|
||||||
|
lessons.schema.Query, hyperlinks.schema.Query, graphene.ObjectType):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Mutation(users.schema.Mutation, organisations.schema.Mutation, graphene.ObjectType):
|
class Mutation(users.schema.Mutation, organisations.schema.Mutation,
|
||||||
|
lessons.schema.Mutation, hyperlinks.schema.Mutation, graphene.ObjectType):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,11 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'django_filters',
|
||||||
'users',
|
'users',
|
||||||
'organisations',
|
'organisations',
|
||||||
'lessons'
|
'lessons',
|
||||||
|
'hyperlinks'
|
||||||
]
|
]
|
||||||
GRAPHENE = {
|
GRAPHENE = {
|
||||||
'SCHEMA': 'evgenApp.schema.schema',
|
'SCHEMA': 'evgenApp.schema.schema',
|
||||||
|
|
0
hyperlinks/__init__.py
Normal file
0
hyperlinks/__init__.py
Normal file
BIN
hyperlinks/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
hyperlinks/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
hyperlinks/__pycache__/admin.cpython-37.pyc
Normal file
BIN
hyperlinks/__pycache__/admin.cpython-37.pyc
Normal file
Binary file not shown.
BIN
hyperlinks/__pycache__/models.cpython-37.pyc
Normal file
BIN
hyperlinks/__pycache__/models.cpython-37.pyc
Normal file
Binary file not shown.
BIN
hyperlinks/__pycache__/schema.cpython-37.pyc
Normal file
BIN
hyperlinks/__pycache__/schema.cpython-37.pyc
Normal file
Binary file not shown.
3
hyperlinks/admin.py
Normal file
3
hyperlinks/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
5
hyperlinks/apps.py
Normal file
5
hyperlinks/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class HyperlinksConfig(AppConfig):
|
||||||
|
name = 'hyperlinks'
|
26
hyperlinks/migrations/0001_initial.py
Normal file
26
hyperlinks/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# 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')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
30
hyperlinks/migrations/0002_auto_20210120_2119.py
Normal file
30
hyperlinks/migrations/0002_auto_20210120_2119.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# 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'),
|
||||||
|
),
|
||||||
|
]
|
0
hyperlinks/migrations/__init__.py
Normal file
0
hyperlinks/migrations/__init__.py
Normal file
BIN
hyperlinks/migrations/__pycache__/0001_initial.cpython-37.pyc
Normal file
BIN
hyperlinks/migrations/__pycache__/0001_initial.cpython-37.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
hyperlinks/migrations/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
hyperlinks/migrations/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
30
hyperlinks/models.py
Normal file
30
hyperlinks/models.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@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)
|
51
hyperlinks/schema.py
Normal file
51
hyperlinks/schema.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
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)
|
3
hyperlinks/tests.py
Normal file
3
hyperlinks/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
3
hyperlinks/views.py
Normal file
3
hyperlinks/views.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
BIN
lessons/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
lessons/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
lessons/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
lessons/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
lessons/__pycache__/admin.cpython-37.pyc
Normal file
BIN
lessons/__pycache__/admin.cpython-37.pyc
Normal file
Binary file not shown.
BIN
lessons/__pycache__/models.cpython-37.pyc
Normal file
BIN
lessons/__pycache__/models.cpython-37.pyc
Normal file
Binary file not shown.
BIN
lessons/__pycache__/models.cpython-39.pyc
Normal file
BIN
lessons/__pycache__/models.cpython-39.pyc
Normal file
Binary file not shown.
BIN
lessons/__pycache__/schema.cpython-37.pyc
Normal file
BIN
lessons/__pycache__/schema.cpython-37.pyc
Normal file
Binary file not shown.
|
@ -18,4 +18,10 @@ def removeTeacherFromClass(classLocal, teacher):
|
||||||
classLocal.teachers.remove(teacher)
|
classLocal.teachers.remove(teacher)
|
||||||
|
|
||||||
def addLessonToClass(classLocal):
|
def addLessonToClass(classLocal):
|
||||||
Lesson
|
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)
|
22
lessons/migrations/0003_auto_20210113_2224.py
Normal file
22
lessons/migrations/0003_auto_20210113_2224.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 3.1.5 on 2021-01-13 19:24
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('lessons', '0002_auto_20210109_1220'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='task',
|
||||||
|
name='type',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='task',
|
||||||
|
name='types',
|
||||||
|
field=models.ManyToManyField(to='lessons.Type'),
|
||||||
|
),
|
||||||
|
]
|
18
lessons/migrations/0004_answer_completed.py
Normal file
18
lessons/migrations/0004_answer_completed.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.1.5 on 2021-01-13 20:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('lessons', '0003_auto_20210113_2224'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='answer',
|
||||||
|
name='completed',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
23
lessons/migrations/0005_auto_20210117_1752.py
Normal file
23
lessons/migrations/0005_auto_20210117_1752.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 3.1.5 on 2021-01-17 14:52
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('lessons', '0004_answer_completed'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='answer',
|
||||||
|
name='score',
|
||||||
|
field=models.IntegerField(default=0),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='task',
|
||||||
|
name='max_score',
|
||||||
|
field=models.IntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
23
lessons/migrations/0006_auto_20210117_2008.py
Normal file
23
lessons/migrations/0006_auto_20210117_2008.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 3.1.5 on 2021-01-17 17:08
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('lessons', '0005_auto_20210117_1752'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lesson',
|
||||||
|
name='descr',
|
||||||
|
field=models.TextField(default=''),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lesson',
|
||||||
|
name='name',
|
||||||
|
field=models.TextField(default=''),
|
||||||
|
),
|
||||||
|
]
|
BIN
lessons/migrations/__pycache__/0001_initial.cpython-37.pyc
Normal file
BIN
lessons/migrations/__pycache__/0001_initial.cpython-37.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lessons/migrations/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
lessons/migrations/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
|
@ -22,6 +22,8 @@ class SubjectClassLocal(models.Model):
|
||||||
|
|
||||||
class Lesson(models.Model):
|
class Lesson(models.Model):
|
||||||
type_lesson = models.ForeignKey(SubjectClassLocal, on_delete=models.CASCADE)
|
type_lesson = models.ForeignKey(SubjectClassLocal, on_delete=models.CASCADE)
|
||||||
|
name = models.TextField(default="")
|
||||||
|
descr = models.TextField(default="")
|
||||||
|
|
||||||
|
|
||||||
class Materials(models.Model):
|
class Materials(models.Model):
|
||||||
|
@ -41,8 +43,9 @@ class Task(models.Model):
|
||||||
theory = models.TextField()
|
theory = models.TextField()
|
||||||
practise = models.TextField()
|
practise = models.TextField()
|
||||||
test = models.ForeignKey(Tests, on_delete=models.CASCADE)
|
test = models.ForeignKey(Tests, on_delete=models.CASCADE)
|
||||||
type = models.ForeignKey(Type, on_delete=models.PROTECT)
|
types = models.ManyToManyField(Type)
|
||||||
number = models.IntegerField()
|
number = models.IntegerField()
|
||||||
|
max_score = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,10 +62,13 @@ class Answer(models.Model):
|
||||||
sheet = models.ForeignKey(AnswerSheet, on_delete=models.CASCADE)
|
sheet = models.ForeignKey(AnswerSheet, on_delete=models.CASCADE)
|
||||||
content = models.TextField()
|
content = models.TextField()
|
||||||
number = models.IntegerField()
|
number = models.IntegerField()
|
||||||
|
completed = models.BooleanField(default=False)
|
||||||
|
score = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Tests)
|
@receiver(post_save, sender=Tests)
|
||||||
def _post_save_receiver(sender, instance, created, **kwargs):
|
def _post_save_receiver_(sender, instance, created, **kwargs):
|
||||||
|
print(created, instance, instance.lesson.type_lesson.group.child_set.all())
|
||||||
if created:
|
if created:
|
||||||
for child in instance.lesson.type_lesson.group.child_set.all():
|
for child in instance.lesson.type_lesson.group.child_set.all():
|
||||||
AnswerSheet.objects.create(child=child, completed=False, test=instance)
|
AnswerSheet.objects.create(child=child, completed=False, test=instance)
|
||||||
|
@ -71,4 +77,4 @@ def _post_save_receiver(sender, instance, created, **kwargs):
|
||||||
def _post_save_receiver(sender, instance, created, **kwargs):
|
def _post_save_receiver(sender, instance, created, **kwargs):
|
||||||
if created:
|
if created:
|
||||||
for child in instance.test.lesson.type_lesson.group.child_set.all():
|
for child in instance.test.lesson.type_lesson.group.child_set.all():
|
||||||
Answer.objects.create(number=instance.number, sheet=child.answer_sheet_set.all().filter(test=instance.test)[0], content="")
|
Answer.objects.create(number=instance.number, sheet=child.answersheet_set.all().filter(test=instance.test)[0], content="")
|
467
lessons/schema.py
Normal file
467
lessons/schema.py
Normal file
|
@ -0,0 +1,467 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
class CreateLesson(graphene.Mutation):
|
||||||
|
class Arguments:
|
||||||
|
name = graphene.String()
|
||||||
|
descr = graphene.String()
|
||||||
|
subject = graphene.ID()
|
||||||
|
|
||||||
|
ok = graphene.Boolean()
|
||||||
|
|
||||||
|
def mutate(self, info, name, descr, subject):
|
||||||
|
Lesson.objects.create(name=name, descr=descr, type_lesson=
|
||||||
|
SubjectClassLocal.objects.get(pk=subject))
|
||||||
|
return CreateLesson(ok=True)
|
||||||
|
|
||||||
|
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=id) 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=id)
|
||||||
|
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=lesson_id)
|
||||||
|
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=test_id)
|
||||||
|
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
|
||||||
|
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=test_id)
|
||||||
|
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()
|
||||||
|
|
||||||
|
task = graphene.Field(TaskType)
|
||||||
|
|
||||||
|
def mutate(self, info, test_id, theory, practise, number, max_score):
|
||||||
|
m = createModel(model=Task, fields = {
|
||||||
|
"test": Tests.objects.get(id=test_id),
|
||||||
|
"theory": theory,
|
||||||
|
"practise": practise,
|
||||||
|
"number": number,
|
||||||
|
"max_score": max_score
|
||||||
|
})
|
||||||
|
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()
|
||||||
|
task = graphene.Field(TaskType)
|
||||||
|
|
||||||
|
def mutate(self, info, task_id, theory=None, practise=None, number=None, max_score=None):
|
||||||
|
task = Task.objects.get(id=task_id)
|
||||||
|
m = updateModel(Task, task, {
|
||||||
|
"theory": [theory, task.theory],
|
||||||
|
"practise": [practise, task.practise],
|
||||||
|
"number": [number, task.number],
|
||||||
|
"max_score": [max_score, task.max_score]
|
||||||
|
})
|
||||||
|
return updateTask(task=m)
|
||||||
|
|
||||||
|
|
||||||
|
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 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()
|
||||||
|
|
||||||
|
class Query(graphene.ObjectType):
|
||||||
|
|
||||||
|
all_test = DjangoFilterConnectionField(TestsType)
|
||||||
|
test = relay.Node.Field(TestsType)
|
||||||
|
|
||||||
|
all_subject = DjangoFilterConnectionField(SubjectType)
|
||||||
|
subject = relay.Node.Field(SubjectType)
|
||||||
|
|
||||||
|
task = relay.Node.Field(TaskType)
|
||||||
|
all_task = DjangoFilterConnectionField(TaskType)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
schema = graphene.Schema(query=Query)
|
BIN
organisations/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
organisations/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
organisations/__pycache__/admin.cpython-37.pyc
Normal file
BIN
organisations/__pycache__/admin.cpython-37.pyc
Normal file
Binary file not shown.
BIN
organisations/__pycache__/gqlTypes.cpython-37.pyc
Normal file
BIN
organisations/__pycache__/gqlTypes.cpython-37.pyc
Normal file
Binary file not shown.
BIN
organisations/__pycache__/mixins.cpython-37.pyc
Normal file
BIN
organisations/__pycache__/mixins.cpython-37.pyc
Normal file
Binary file not shown.
BIN
organisations/__pycache__/models.cpython-37.pyc
Normal file
BIN
organisations/__pycache__/models.cpython-37.pyc
Normal file
Binary file not shown.
BIN
organisations/__pycache__/mutation.cpython-37.pyc
Normal file
BIN
organisations/__pycache__/mutation.cpython-37.pyc
Normal file
Binary file not shown.
BIN
organisations/__pycache__/query.cpython-37.pyc
Normal file
BIN
organisations/__pycache__/query.cpython-37.pyc
Normal file
Binary file not shown.
BIN
organisations/__pycache__/schema.cpython-37.pyc
Normal file
BIN
organisations/__pycache__/schema.cpython-37.pyc
Normal file
Binary file not shown.
|
@ -1,27 +1,82 @@
|
||||||
import graphene_django
|
import graphene_django
|
||||||
from .models import Organisation, Role, Group, Teacher, Child
|
from .models import Organisation, Role, Group, Teacher, Child, Organisator
|
||||||
|
from graphene import relay
|
||||||
|
import graphene
|
||||||
|
|
||||||
print(Teacher, Child)
|
print(Teacher, Child)
|
||||||
|
|
||||||
|
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 OrganisationType(graphene_django.DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Organisation
|
model = Organisation
|
||||||
|
interfaces = (relay.Node,)
|
||||||
|
filter_fields = {
|
||||||
|
"name" : ("exact", "contains",),
|
||||||
|
}
|
||||||
|
|
||||||
class RoleType(graphene_django.DjangoObjectType):
|
class RoleType(graphene_django.DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Role
|
model = Role
|
||||||
|
|
||||||
|
|
||||||
class GroupType(graphene_django.DjangoObjectType):
|
|
||||||
class Meta:
|
|
||||||
model = Group
|
|
||||||
|
|
||||||
|
|
||||||
class TeacherType(graphene_django.DjangoObjectType):
|
class TeacherType(graphene_django.DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Teacher
|
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):
|
class ChildType(graphene_django.DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Child
|
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 GroupType(graphene_django.DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = Group
|
||||||
|
interfaces = (relay.Node,)
|
||||||
|
|
||||||
|
filter_fields = {
|
||||||
|
"name" : ("exact", "contains"),
|
||||||
|
}
|
||||||
|
pk = graphene.Int()
|
||||||
|
|
||||||
|
def resolve(self, info):
|
||||||
|
return self.pk
|
37
organisations/migrations/0005_auto_20210120_1944.py
Normal file
37
organisations/migrations/0005_auto_20210120_1944.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
# 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')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
BIN
organisations/migrations/__pycache__/0001_initial.cpython-37.pyc
Normal file
BIN
organisations/migrations/__pycache__/0001_initial.cpython-37.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
organisations/migrations/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
organisations/migrations/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
67
organisations/mixins.py
Normal file
67
organisations/mixins.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
import graphene
|
||||||
|
from .models import Organisation, Group
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
class RegModelToOrg(graphene.Mutation):
|
||||||
|
model = ""
|
||||||
|
|
||||||
|
class Arguments:
|
||||||
|
user_id = graphene.ID()
|
||||||
|
org_id = graphene.ID()
|
||||||
|
name = graphene.String(required=False)
|
||||||
|
surname = graphene.String(required=False)
|
||||||
|
midname = graphene.String(required=False)
|
||||||
|
modelType = graphene.Field(graphene.Int())
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def mutate(self, root, info, **kwargs):
|
||||||
|
surname = kwargs.get("surname", "")
|
||||||
|
name = kwargs.get("name", "")
|
||||||
|
midname = kwargs.get("midname", "")
|
||||||
|
org_id = kwargs.get("org_id", "")
|
||||||
|
user_id = kwargs.get("user_id", "")
|
||||||
|
print(self.model, "model")
|
||||||
|
profile = User.objects.get(id=user_id).profile
|
||||||
|
print(kwargs, self)
|
||||||
|
org = Organisation.objects.get(id=org_id)
|
||||||
|
print(self, info)
|
||||||
|
instance = self.model.objects.create(
|
||||||
|
org=org, profile=profile,
|
||||||
|
name=name or "", surname=surname or "", midname = midname or "")
|
||||||
|
return RegModelToOrg(modelType=instance)
|
||||||
|
|
||||||
|
|
||||||
|
class RegModelGroup(graphene.Mutation):
|
||||||
|
model = ""
|
||||||
|
modelType = graphene.Field(graphene.Int())
|
||||||
|
class Arguments:
|
||||||
|
group_id = graphene.ID()
|
||||||
|
user_id = graphene.ID()
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def mutate(self, root, info, group_id, user_id):
|
||||||
|
group = Group.objects.get(id=group_id)
|
||||||
|
user = self.model.objects.get(id=user_id)
|
||||||
|
user.groups.add(group)
|
||||||
|
user.save()
|
||||||
|
return RegModelGroup(modelType=user)
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteModelGroup(graphene.Mutation):
|
||||||
|
model = ""
|
||||||
|
modelType = graphene.Field(graphene.Int())
|
||||||
|
|
||||||
|
class Arguments:
|
||||||
|
group_id = graphene.ID()
|
||||||
|
model_id = graphene.ID()
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def mutate(self, root, info, group_id, model_id):
|
||||||
|
model = self.model.objects.get(id=model_id)
|
||||||
|
|
||||||
|
model.groups.all().filter(id=group_id)[0].delete()
|
||||||
|
|
||||||
|
return DeleteModelGroup(modelType=model)
|
|
@ -28,14 +28,22 @@ class Group(models.Model):
|
||||||
|
|
||||||
class Teacher(models.Model):
|
class Teacher(models.Model):
|
||||||
org = models.ForeignKey(Organisation, models.CASCADE, blank=True)
|
org = models.ForeignKey(Organisation, models.CASCADE, blank=True)
|
||||||
profile = models.ForeignKey(Profile, models.CASCADE)
|
profile = models.ForeignKey(Profile, models.CASCADE, blank=True)
|
||||||
groups = models.ManyToManyField(Group)
|
groups = models.ManyToManyField(Group)
|
||||||
name = models.CharField(max_length=150, blank=True)
|
name = models.CharField(max_length=150, blank=True)
|
||||||
surname = models.CharField(max_length=150, blank=True)
|
surname = models.CharField(max_length=150, blank=True)
|
||||||
midname = models.CharField(max_length=150, blank=True)
|
midname = models.CharField(max_length=150, blank=True)
|
||||||
|
|
||||||
class Child(models.Model):
|
class Child(models.Model):
|
||||||
profile = models.ForeignKey(Profile, models.CASCADE)
|
profile = models.ForeignKey(Profile, models.CASCADE, blank=True)
|
||||||
|
org = models.ForeignKey(Organisation, models.CASCADE, blank=True)
|
||||||
|
groups = models.ManyToManyField(Group)
|
||||||
|
name = models.CharField(max_length=150, blank=True)
|
||||||
|
surname = models.CharField(max_length=150, blank=True)
|
||||||
|
midname = models.CharField(max_length=150, blank=True)
|
||||||
|
|
||||||
|
class Organisator(models.Model):
|
||||||
|
profile = models.ForeignKey(Profile, models.CASCADE, blank=True)
|
||||||
org = models.ForeignKey(Organisation, models.CASCADE, blank=True)
|
org = models.ForeignKey(Organisation, models.CASCADE, blank=True)
|
||||||
groups = models.ManyToManyField(Group)
|
groups = models.ManyToManyField(Group)
|
||||||
name = models.CharField(max_length=150, blank=True)
|
name = models.CharField(max_length=150, blank=True)
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
from .gqlTypes import OrganisationType, RoleType, GroupType
|
from .gqlTypes import OrganisationType, RoleType, ChildType, TeacherType, GroupType, OrganisatorType
|
||||||
from .models import Organisation, Role, Group, Teacher, Child
|
from .models import Organisation, Role, Group, Teacher, Child, Organisator
|
||||||
|
from lessons.models import SubjectClassLocal
|
||||||
|
|
||||||
from users.schema import UserType
|
from users.schema import UserType
|
||||||
|
from graphene import relay
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
from .mixins import RegModelToOrg, RegModelGroup, DeleteModelGroup
|
||||||
|
|
||||||
class CreateGroup(graphene.Mutation):
|
class CreateGroup(graphene.Mutation):
|
||||||
class Arguments:
|
class Arguments:
|
||||||
|
@ -25,25 +31,6 @@ class CreateOrg(graphene.Mutation):
|
||||||
def mutate(self, info, name, **kwargs):
|
def mutate(self, info, name, **kwargs):
|
||||||
return CreateOrg(Org=Organisation.objects.create(name=name))
|
return CreateOrg(Org=Organisation.objects.create(name=name))
|
||||||
|
|
||||||
class RegUserOrg(graphene.Mutation):
|
|
||||||
class Arguments:
|
|
||||||
token = graphene.String()
|
|
||||||
orgName = graphene.String()
|
|
||||||
isTeacher = graphene.Boolean()
|
|
||||||
name = graphene.String(required=False)
|
|
||||||
surname = graphene.String(required=False)
|
|
||||||
midname = graphene.String(required=False)
|
|
||||||
|
|
||||||
ok = graphene.Boolean()
|
|
||||||
|
|
||||||
def mutate(self, info, token, orgName, isTeacher, **kwargs):
|
|
||||||
org = Organisation.objects.get(name=orgName)
|
|
||||||
if isTeacher:
|
|
||||||
t = Teacher.objects.create(profile=info.context.user.profile, org=org)
|
|
||||||
else:
|
|
||||||
t = Child.objects.create(profile=info.context.user.profile, org=org)
|
|
||||||
return RegUserOrg(ok=True)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AddGroupToOrg(graphene.Mutation):
|
class AddGroupToOrg(graphene.Mutation):
|
||||||
|
@ -57,20 +44,30 @@ class AddGroupToOrg(graphene.Mutation):
|
||||||
return AddGroupToOrg(group=group)
|
return AddGroupToOrg(group=group)
|
||||||
|
|
||||||
|
|
||||||
class RegUserGroup(graphene.Mutation):
|
|
||||||
class Arguments:
|
class RegTeacherToOrg(RegModelToOrg):
|
||||||
token = graphene.String()
|
model = Teacher
|
||||||
orgName = graphene.String()
|
modelType = graphene.Field(TeacherType)
|
||||||
groupName = graphene.String()
|
|
||||||
is_teacher = graphene.Boolean()
|
class RegChildToOrg(RegModelToOrg):
|
||||||
user = graphene.Field(UserType)
|
model = Child
|
||||||
def mutate(self, info, token, orgName, groupName, is_teacher, **kwargs):
|
modelType =graphene.Field(ChildType)
|
||||||
group = Organisation.objects.get(name=orgName).group_set.all().filter(name=groupName)[0]
|
|
||||||
if is_teacher:
|
|
||||||
info.context.user.profile.teacher_set.all().filter(org__name=orgName)[0].groups.add(group)
|
class RegOrganisatorToOrg(RegModelToOrg):
|
||||||
else:
|
model = Organisator
|
||||||
info.context.user.profile.child_set.all().filter(org__name=orgName)[0].groups.add(group)
|
modelType = graphene.Field(OrganisatorType)
|
||||||
return RegUserGroup(info.context.user)
|
|
||||||
|
|
||||||
|
class RegChildGroup(RegModelGroup):
|
||||||
|
model = Child
|
||||||
|
modelType = graphene.Field(ChildType)
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteChildGroup(DeleteModelGroup):
|
||||||
|
model = Child
|
||||||
|
modelType = graphene.Field(ChildType)
|
||||||
|
|
||||||
|
|
||||||
class DeleteGroup(graphene.Mutation):
|
class DeleteGroup(graphene.Mutation):
|
||||||
class Arguments:
|
class Arguments:
|
||||||
|
@ -80,32 +77,49 @@ class DeleteGroup(graphene.Mutation):
|
||||||
def mutate(self, info, orgName, groupName, **kwargs):
|
def mutate(self, info, orgName, groupName, **kwargs):
|
||||||
Organisation.objects.find(name=orgName).objects.groups.all().filter(name=groupName)[0].delete()
|
Organisation.objects.find(name=orgName).objects.groups.all().filter(name=groupName)[0].delete()
|
||||||
|
|
||||||
class DeleteUserFromGroup(graphene.Mutation):
|
|
||||||
class Arguments:
|
|
||||||
orgName = graphene.String()
|
|
||||||
groupName = graphene.String()
|
|
||||||
token = graphene.String()
|
|
||||||
is_teacher = graphene.Boolean()
|
|
||||||
user = graphene.Field(UserType)
|
|
||||||
def mutate(self, info, orgName, groupName, token, is_teacher, **kwargs):
|
|
||||||
if is_teacher:
|
|
||||||
group = info.context.user.profile.teacher_set.all().filter(org__name=orgName)[0].groups.all().filter(name=groupName)[0]
|
|
||||||
org = info.context.user.profile.teacher_set.all().filter(org__name=orgName)[0]
|
|
||||||
print(group, org)
|
|
||||||
org.groups.remove(group)
|
|
||||||
return DeleteuserFromGroup(info.context.user)
|
|
||||||
else:
|
|
||||||
group = info.context.user.profile.child_set.all().filter(org__name=orgName)[0].groups.all().filter(name=groupName)[0]
|
|
||||||
org = info.context.user.profile.child_set.all().filter(org__name=orgName)[0]
|
|
||||||
print(group, org)
|
|
||||||
org.groups.remove(group)
|
|
||||||
|
|
||||||
|
class RegTeacherClass(graphene.Mutation):
|
||||||
|
class Arguments:
|
||||||
|
teacher_id = graphene.ID()
|
||||||
|
class_id = graphene.ID()
|
||||||
|
|
||||||
|
teacher = graphene.Field(TeacherType)
|
||||||
|
|
||||||
|
def mutate(self, info, teacher_id, class_id):
|
||||||
|
teacher = Teacher.objects.get(id=teacher_id)
|
||||||
|
class_ = SubjectClassLocal.objects.get(id=class_id)
|
||||||
|
|
||||||
|
class_.teachers.add(teacher)
|
||||||
|
class_.save()
|
||||||
|
return RegTeacherClass(teacher=teacher)
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteTeacherClass(graphene.Mutation):
|
||||||
|
class Arguments:
|
||||||
|
teacher_id = graphene.ID()
|
||||||
|
class_id = graphene.ID()
|
||||||
|
|
||||||
|
teacher = graphene.Field(TeacherType)
|
||||||
|
|
||||||
|
def mutate(self, info, teacher_id, class_id):
|
||||||
|
class_ = SubjectClassLocal.objects.get(id=class_id)
|
||||||
|
class_.teachers.filter(id=teacher_id)[0].remove()
|
||||||
|
return DeleteTeacherClass(teacher=Teacher.objects.get(id=teacher_id))
|
||||||
|
|
||||||
class Mutation(graphene.ObjectType):
|
class Mutation(graphene.ObjectType):
|
||||||
create_org = CreateOrg.Field()
|
create_org = CreateOrg.Field()
|
||||||
reg_user_org = RegUserOrg.Field()
|
|
||||||
create_group = CreateGroup.Field()
|
create_group = CreateGroup.Field()
|
||||||
reg_user_to_group = RegUserGroup.Field()
|
|
||||||
add_group_to_org = AddGroupToOrg.Field()
|
add_group_to_org = AddGroupToOrg.Field()
|
||||||
delete_group = DeleteGroup.Field()
|
delete_group = DeleteGroup.Field()
|
||||||
delete_user_from_group = DeleteUserFromGroup.Field()
|
|
||||||
|
reg_teacher_org = RegTeacherToOrg.Field()
|
||||||
|
reg_child_org = RegChildToOrg.Field()
|
||||||
|
|
||||||
|
reg_child_group = RegChildGroup.Field()
|
||||||
|
|
||||||
|
delete_child_group = DeleteChildGroup.Field()
|
||||||
|
|
||||||
|
reg_teacher_class = RegTeacherClass.Field()
|
||||||
|
delete_teacher_class = DeleteTeacherClass.Field()
|
||||||
|
|
||||||
|
reg_organisator_to_org = RegOrganisatorToOrg.Field()
|
|
@ -1,15 +1,26 @@
|
||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
from .gqlTypes import OrganisationType, RoleType
|
from .gqlTypes import OrganisationType, RoleType, TeacherType, ChildType, GroupType
|
||||||
from .models import Organisation, Role
|
from .models import Organisation, Role
|
||||||
|
from graphene import relay
|
||||||
|
|
||||||
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
organisations = graphene.Field(graphene.List(OrganisationType))
|
|
||||||
roles = graphene.Field(graphene.List(RoleType))
|
roles = graphene.Field(graphene.List(RoleType))
|
||||||
|
|
||||||
def resolve_organisations(self, info, **kwargs):
|
organisations = DjangoFilterConnectionField(OrganisationType)
|
||||||
return Organisation.objects.all()
|
organisation = relay.Node.Field(OrganisationType)
|
||||||
|
|
||||||
|
teachers = DjangoFilterConnectionField(TeacherType)
|
||||||
|
teacher = relay.Node.Field(TeacherType)
|
||||||
|
|
||||||
|
children = DjangoFilterConnectionField(ChildType)
|
||||||
|
child = relay.Node.Field(ChildType)
|
||||||
|
|
||||||
|
group = relay.Node.Field(GroupType)
|
||||||
|
groups = DjangoFilterConnectionField(GroupType)
|
||||||
|
|
||||||
|
|
||||||
def resolve_roles(self, info, **kwargs):
|
def resolve_roles(self, info, **kwargs):
|
||||||
return Role.objects.all()
|
return Role.objects.all()
|
BIN
users/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
users/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/admin.cpython-37.pyc
Normal file
BIN
users/__pycache__/admin.cpython-37.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/models.cpython-37.pyc
Normal file
BIN
users/__pycache__/models.cpython-37.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/schema.cpython-37.pyc
Normal file
BIN
users/__pycache__/schema.cpython-37.pyc
Normal file
Binary file not shown.
BIN
users/migrations/__pycache__/0001_initial.cpython-37.pyc
Normal file
BIN
users/migrations/__pycache__/0001_initial.cpython-37.pyc
Normal file
Binary file not shown.
BIN
users/migrations/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
users/migrations/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
|
@ -7,13 +7,29 @@ from django.contrib.auth.models import User
|
||||||
|
|
||||||
from .models import Profile
|
from .models import Profile
|
||||||
|
|
||||||
|
from graphene import relay
|
||||||
|
|
||||||
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
|
|
||||||
class UserType(graphene_django.DjangoObjectType):
|
class UserType(graphene_django.DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
|
pk = graphene.Int()
|
||||||
|
|
||||||
|
def resolve_pk(self, info):
|
||||||
|
return self.pk
|
||||||
|
|
||||||
class ProfileType(graphene_django.DjangoObjectType):
|
class ProfileType(graphene_django.DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Profile
|
model = Profile
|
||||||
|
interfaces = (relay.Node,)
|
||||||
|
filter_fields = {
|
||||||
|
"user__username" : ("exact","contains")
|
||||||
|
}
|
||||||
|
pk = graphene.Int()
|
||||||
|
|
||||||
|
def resolve_pk(self, info):
|
||||||
|
return self.pk
|
||||||
|
|
||||||
class RegisterUserInput(graphene.InputObjectType):
|
class RegisterUserInput(graphene.InputObjectType):
|
||||||
username = graphene.String()
|
username = graphene.String()
|
||||||
|
@ -36,7 +52,8 @@ class Mutation(graphene.ObjectType):
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
hello = graphene.Field(graphene.String, token=graphene.String(required=True))
|
hello = graphene.Field(graphene.String, token=graphene.String(required=True))
|
||||||
user_info = graphene.Field(UserType, token=graphene.String(required=True))
|
user_info = graphene.Field(UserType, token=graphene.String(required=True))
|
||||||
user_profile = graphene.Field(ProfileType, token=graphene.String(required=True))
|
profile = relay.Node.Field(ProfileType)
|
||||||
|
all_profiles = DjangoFilterConnectionField(ProfileType)
|
||||||
|
|
||||||
def resolve_hello(self, info, **kwargs):
|
def resolve_hello(self, info, **kwargs):
|
||||||
print(info.context.user.id)
|
print(info.context.user.id)
|
||||||
|
@ -45,7 +62,4 @@ class Query(graphene.ObjectType):
|
||||||
def resolve_user_info(self, info, **kwargs):
|
def resolve_user_info(self, info, **kwargs):
|
||||||
return info.context.user
|
return info.context.user
|
||||||
|
|
||||||
def resolve_user_profile(self, info, **kwargs):
|
|
||||||
return info.context.user.profile
|
|
||||||
|
|
||||||
schema = graphene.Schema(query=Query, mutation=Mutation)
|
schema = graphene.Schema(query=Query, mutation=Mutation)
|
Loading…
Reference in New Issue
Block a user