mirror of
https://github.com/evgen-app/evg-app-back.git
synced 2024-11-22 00:36:35 +03:00
add postgres
This commit is contained in:
parent
ac3d5338aa
commit
050c7d5ecb
Binary file not shown.
|
@ -103,8 +103,12 @@ WSGI_APPLICATION = 'evgenApp.wsgi.application'
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
'NAME': "EvgenApp",
|
||||||
|
"USER": "postgres",
|
||||||
|
"PASSWORD" : "Ilvas2006",
|
||||||
|
"HOST" : "127.0.1.1",
|
||||||
|
"PORT" : "5432"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -15,16 +15,4 @@ class HyperLink(models.Model):
|
||||||
|
|
||||||
#@receiver(signal=post_save, sender=Organisator)
|
#@receiver(signal=post_save, sender=Organisator)
|
||||||
#def org_recieve(sender, instance, **kwargs):
|
#def org_recieve(sender, instance, **kwargs):
|
||||||
# HyperLink.objects.create(organ=instance)
|
# 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)
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -28,6 +28,7 @@ class AnswerType(graphene_django.DjangoObjectType):
|
||||||
interfaces = (relay.Node,)
|
interfaces = (relay.Node,)
|
||||||
filter_fields = {
|
filter_fields = {
|
||||||
"sheet" : ("exact",),
|
"sheet" : ("exact",),
|
||||||
|
"number" : ("exact",)
|
||||||
}
|
}
|
||||||
pk = graphene.Int()
|
pk = graphene.Int()
|
||||||
|
|
||||||
|
@ -43,13 +44,15 @@ class AnswerSheetType(graphene_django.DjangoObjectType):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TaskType(graphene_django.DjangoObjectType):
|
class TaskType(graphene_django.DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Task
|
model = Task
|
||||||
interfaces = (relay.Node,)
|
interfaces = (relay.Node,)
|
||||||
filter_fields = {
|
filter_fields = {
|
||||||
"test": ("exact",),
|
"test": ("exact",),
|
||||||
"types": ("contains",)
|
"types": ("contains",),
|
||||||
|
"number":("exact",)
|
||||||
}
|
}
|
||||||
pk = graphene.Int()
|
pk = graphene.Int()
|
||||||
|
|
||||||
|
@ -68,6 +71,11 @@ class TestsType(graphene_django.DjangoObjectType):
|
||||||
pk = graphene.Int()
|
pk = graphene.Int()
|
||||||
taskLen = graphene.Int()
|
taskLen = graphene.Int()
|
||||||
|
|
||||||
|
answerLen = graphene.Int()
|
||||||
|
|
||||||
|
def resolve_answerLen(self, info):
|
||||||
|
return len(self.answersheet_set.all())
|
||||||
|
|
||||||
def resolve_pk(self, info):
|
def resolve_pk(self, info):
|
||||||
return self.id
|
return self.id
|
||||||
|
|
||||||
|
@ -153,4 +161,11 @@ class TaskTypeType(graphene_django.DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = taskType
|
model = taskType
|
||||||
interfaces = (relay.Node,)
|
interfaces = (relay.Node,)
|
||||||
|
filter_fields = {}
|
||||||
|
|
||||||
|
|
||||||
|
class AnswerSheetType(graphene_django.DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = AnswerSheet
|
||||||
|
interfaces = (relay.Node,)
|
||||||
filter_fields = {}
|
filter_fields = {}
|
23
lessons/migrations/0009_auto_20210210_2116.py
Normal file
23
lessons/migrations/0009_auto_20210210_2116.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 3.1.5 on 2021-02-10 18:16
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('lessons', '0008_auto_20210205_1858'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='tests',
|
||||||
|
name='is_timing',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='tests',
|
||||||
|
name='time_sec',
|
||||||
|
field=models.IntegerField(default=300),
|
||||||
|
),
|
||||||
|
]
|
Binary file not shown.
|
@ -40,6 +40,8 @@ class Tests(models.Model):
|
||||||
name = models.CharField(max_length=150)
|
name = models.CharField(max_length=150)
|
||||||
deadline = models.DateTimeField()
|
deadline = models.DateTimeField()
|
||||||
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE)
|
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE)
|
||||||
|
is_timing = models.BooleanField(default=False)
|
||||||
|
time_sec = models.IntegerField(default=300)
|
||||||
|
|
||||||
class Type(models.Model):
|
class Type(models.Model):
|
||||||
name = models.TextField(max_length=150)
|
name = models.TextField(max_length=150)
|
||||||
|
@ -48,6 +50,10 @@ class Type(models.Model):
|
||||||
class TaskType(models.Model):
|
class TaskType(models.Model):
|
||||||
name = models.TextField()
|
name = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
|
def __str__(self) :
|
||||||
|
return self.name
|
||||||
|
|
||||||
class Task(models.Model):
|
class Task(models.Model):
|
||||||
theory = models.TextField()
|
theory = models.TextField()
|
||||||
practise = models.TextField()
|
practise = models.TextField()
|
||||||
|
@ -80,18 +86,4 @@ class Answer(models.Model):
|
||||||
content = models.TextField()
|
content = models.TextField()
|
||||||
number = models.IntegerField()
|
number = models.IntegerField()
|
||||||
completed = models.BooleanField(default=False)
|
completed = models.BooleanField(default=False)
|
||||||
score = models.IntegerField(default=0)
|
score = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Tests)
|
|
||||||
def _post_save_receiver_(sender, instance, created, **kwargs):
|
|
||||||
print(created, instance, instance.lesson.type_lesson.group.child_set.all())
|
|
||||||
if created:
|
|
||||||
for child in instance.lesson.type_lesson.group.child_set.all():
|
|
||||||
AnswerSheet.objects.create(child=child, completed=False, test=instance)
|
|
||||||
|
|
||||||
'''@receiver(post_save, sender=Task)
|
|
||||||
def _post_save_receiver(sender, instance, created, **kwargs):
|
|
||||||
if created:
|
|
||||||
for child in instance.test.lesson.type_lesson.group.child_set.all():
|
|
||||||
Answer.objects.create(number=instance.number, sheet=child.answersheet_set.all().filter(test=instance.test)[0], content="")'''
|
|
|
@ -17,6 +17,45 @@ from .gqlTypes import *
|
||||||
|
|
||||||
from graphql_relay.node.node import from_global_id
|
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 CreateLesson(graphene.Mutation):
|
||||||
class Arguments:
|
class Arguments:
|
||||||
name = graphene.String()
|
name = graphene.String()
|
||||||
|
@ -27,6 +66,7 @@ class CreateLesson(graphene.Mutation):
|
||||||
lesson = graphene.Field(LessonType)
|
lesson = graphene.Field(LessonType)
|
||||||
|
|
||||||
def mutate(self, info, name, descr, subject):
|
def mutate(self, info, name, descr, subject):
|
||||||
|
print(from_global_id(subject), subject)
|
||||||
lesson = Lesson.objects.create(name=name, descr=descr, type_lesson=
|
lesson = Lesson.objects.create(name=name, descr=descr, type_lesson=
|
||||||
SubjectClassLocal.objects.get(id=from_global_id(subject)[1]))
|
SubjectClassLocal.objects.get(id=from_global_id(subject)[1]))
|
||||||
return CreateLesson(ok=True, lesson=lesson)
|
return CreateLesson(ok=True, lesson=lesson)
|
||||||
|
@ -57,7 +97,7 @@ class DeleteLesson(graphene.Mutation):
|
||||||
ok = graphene.Boolean()
|
ok = graphene.Boolean()
|
||||||
|
|
||||||
def mutate(self, info, id):
|
def mutate(self, info, id):
|
||||||
lesson = Lesson.objects.get(id=id)
|
lesson = Lesson.objects.get(id=from_global_id(id)[1])
|
||||||
if lesson == None: return DeleteLesson(ok=False)
|
if lesson == None: return DeleteLesson(ok=False)
|
||||||
lesson.delete()
|
lesson.delete()
|
||||||
return DeleteLesson(ok=True)
|
return DeleteLesson(ok=True)
|
||||||
|
@ -137,7 +177,7 @@ class createTask(graphene.Mutation):
|
||||||
|
|
||||||
def mutate(self, info, test_id, theory, practise, number, max_score, Type):
|
def mutate(self, info, test_id, theory, practise, number, max_score, Type):
|
||||||
task = Tests.objects.get(id=from_global_id(test_id)[1])
|
task = Tests.objects.get(id=from_global_id(test_id)[1])
|
||||||
print(task)
|
print(from_global_id(Type))
|
||||||
m = createModel(model=Task, fields = {
|
m = createModel(model=Task, fields = {
|
||||||
"theory": theory,
|
"theory": theory,
|
||||||
"practise": practise,
|
"practise": practise,
|
||||||
|
@ -170,16 +210,31 @@ class updateTask(graphene.Mutation):
|
||||||
m = updateModel(Task, task, {
|
m = updateModel(Task, task, {
|
||||||
"theory": [theory, task.theory],
|
"theory": [theory, task.theory],
|
||||||
"practise": [practise, task.practise],
|
"practise": [practise, task.practise],
|
||||||
"number": [number, task.number],
|
|
||||||
"max_score": [max_score, task.max_score],
|
"max_score": [max_score, task.max_score],
|
||||||
"Type": [taskType(from_global_id(Type)[1]), task.Type],
|
"Type": [taskType(from_global_id(Type)[1]), task.Type],
|
||||||
"is_autoCheck": [autoCheck, task.is_autoCheck],
|
"is_autoCheck": [autoCheck, task.is_autoCheck],
|
||||||
"autoCheckData": [autoCheckData, task.autoCheckData],
|
"autoCheckData": [autoCheckData, task.autoCheckData],
|
||||||
"is_timing": [is_time, task.is_timing],
|
"is_timing": [is_time, task.is_timing],
|
||||||
"time" : [time, task.time]
|
"time" : [time, task.time],
|
||||||
})
|
})
|
||||||
return updateTask(task=m)
|
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 deleteTask(graphene.Mutation):
|
||||||
class Arguments:
|
class Arguments:
|
||||||
|
@ -427,6 +482,14 @@ class Mutation(graphene.ObjectType):
|
||||||
deleteMaterial = DeleteMaterial.Field()
|
deleteMaterial = DeleteMaterial.Field()
|
||||||
changeMaterial = ChangeMaterail.Field()
|
changeMaterial = ChangeMaterail.Field()
|
||||||
|
|
||||||
|
|
||||||
|
create_anwer_sheet = CreateAnwerSheet.Field()
|
||||||
|
|
||||||
|
create_answer = CreateAnswer.Field()
|
||||||
|
|
||||||
|
|
||||||
|
scoring_tasks = ScoringTasks.Field()
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
|
|
||||||
all_test = DjangoFilterConnectionField(TestsType)
|
all_test = DjangoFilterConnectionField(TestsType)
|
||||||
|
@ -460,5 +523,7 @@ class Query(graphene.ObjectType):
|
||||||
tasks = DjangoFilterConnectionField(TaskType)
|
tasks = DjangoFilterConnectionField(TaskType)
|
||||||
task = relay.Node.Field(TaskType)
|
task = relay.Node.Field(TaskType)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
schema = graphene.Schema(query=Query)
|
schema = graphene.Schema(query=Query)
|
Loading…
Reference in New Issue
Block a user