add postgres

This commit is contained in:
Vasilenko Ilia 2021-02-26 13:59:01 +03:00
parent ac3d5338aa
commit 050c7d5ecb
12 changed files with 122 additions and 35 deletions

View File

@ -103,8 +103,12 @@ WSGI_APPLICATION = 'evgenApp.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': "EvgenApp",
"USER": "postgres",
"PASSWORD" : "Ilvas2006",
"HOST" : "127.0.1.1",
"PORT" : "5432"
}
}

View File

@ -16,15 +16,3 @@ class HyperLink(models.Model):
#@receiver(signal=post_save, sender=Organisator)
#def org_recieve(sender, instance, **kwargs):
# HyperLink.objects.create(organ=instance)
@receiver(signal=post_save, sender=Child)
def child_recieve(sender, instance, **kwargs):
HyperLink.objects.create(child=instance)
@receiver(signal=post_save, sender=Teacher)
def teacher_recieve(sender, instance, **kwargs):
HyperLink.objects.create(teacher=instance)

View File

@ -28,6 +28,7 @@ class AnswerType(graphene_django.DjangoObjectType):
interfaces = (relay.Node,)
filter_fields = {
"sheet" : ("exact",),
"number" : ("exact",)
}
pk = graphene.Int()
@ -43,13 +44,15 @@ class AnswerSheetType(graphene_django.DjangoObjectType):
}
class TaskType(graphene_django.DjangoObjectType):
class Meta:
model = Task
interfaces = (relay.Node,)
filter_fields = {
"test": ("exact",),
"types": ("contains",)
"types": ("contains",),
"number":("exact",)
}
pk = graphene.Int()
@ -68,6 +71,11 @@ class TestsType(graphene_django.DjangoObjectType):
pk = graphene.Int()
taskLen = graphene.Int()
answerLen = graphene.Int()
def resolve_answerLen(self, info):
return len(self.answersheet_set.all())
def resolve_pk(self, info):
return self.id
@ -154,3 +162,10 @@ class TaskTypeType(graphene_django.DjangoObjectType):
model = taskType
interfaces = (relay.Node,)
filter_fields = {}
class AnswerSheetType(graphene_django.DjangoObjectType):
class Meta:
model = AnswerSheet
interfaces = (relay.Node,)
filter_fields = {}

View 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),
),
]

View File

@ -40,6 +40,8 @@ class Tests(models.Model):
name = models.CharField(max_length=150)
deadline = models.DateTimeField()
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE)
is_timing = models.BooleanField(default=False)
time_sec = models.IntegerField(default=300)
class Type(models.Model):
name = models.TextField(max_length=150)
@ -48,6 +50,10 @@ class Type(models.Model):
class TaskType(models.Model):
name = models.TextField()
def __str__(self) :
return self.name
class Task(models.Model):
theory = models.TextField()
practise = models.TextField()
@ -81,17 +87,3 @@ class Answer(models.Model):
number = models.IntegerField()
completed = models.BooleanField(default=False)
score = models.IntegerField(default=0)
@receiver(post_save, sender=Tests)
def _post_save_receiver_(sender, instance, created, **kwargs):
print(created, instance, instance.lesson.type_lesson.group.child_set.all())
if created:
for child in instance.lesson.type_lesson.group.child_set.all():
AnswerSheet.objects.create(child=child, completed=False, test=instance)
'''@receiver(post_save, sender=Task)
def _post_save_receiver(sender, instance, created, **kwargs):
if created:
for child in instance.test.lesson.type_lesson.group.child_set.all():
Answer.objects.create(number=instance.number, sheet=child.answersheet_set.all().filter(test=instance.test)[0], content="")'''

View File

@ -17,6 +17,45 @@ from .gqlTypes import *
from graphql_relay.node.node import from_global_id
class CreateAnwerSheet(graphene.Mutation):
class Arguments:
child = graphene.ID()
test = graphene.ID()
answer = graphene.Field(AnswerSheetType)
def mutate(self, info, child, test):
answerSheet = AnswerSheet.objects.create(
test=Tests.objects.get(id=from_global_id(test)[1]),
child=Child.objects.get(id=from_global_id(child)[1]),
completed=False
)
return CreateAnwerSheet(answer=answerSheet)
class CreateAnswer(graphene.Mutation):
class Arguments:
sheet = graphene.ID()
data = graphene.String()
number = graphene.Int()
answer = graphene.Field(AnswerType)
def mutate(self, info, sheet, data, number):
print(number,sheet, "number")
sheet = AnswerSheet.objects.get(id=from_global_id(sheet)[1])
candidate = Answer.objects.filter(sheet__id=sheet.id, number=number)
print(candidate)
if len(candidate):
candidate.all().delete()
answer = Answer.objects.create(
sheet = sheet,
content = data,
number = number,
)
return CreateAnswer(answer=answer)
class CreateLesson(graphene.Mutation):
class Arguments:
name = graphene.String()
@ -27,6 +66,7 @@ class CreateLesson(graphene.Mutation):
lesson = graphene.Field(LessonType)
def mutate(self, info, name, descr, subject):
print(from_global_id(subject), subject)
lesson = Lesson.objects.create(name=name, descr=descr, type_lesson=
SubjectClassLocal.objects.get(id=from_global_id(subject)[1]))
return CreateLesson(ok=True, lesson=lesson)
@ -57,7 +97,7 @@ class DeleteLesson(graphene.Mutation):
ok = graphene.Boolean()
def mutate(self, info, id):
lesson = Lesson.objects.get(id=id)
lesson = Lesson.objects.get(id=from_global_id(id)[1])
if lesson == None: return DeleteLesson(ok=False)
lesson.delete()
return DeleteLesson(ok=True)
@ -137,7 +177,7 @@ class createTask(graphene.Mutation):
def mutate(self, info, test_id, theory, practise, number, max_score, Type):
task = Tests.objects.get(id=from_global_id(test_id)[1])
print(task)
print(from_global_id(Type))
m = createModel(model=Task, fields = {
"theory": theory,
"practise": practise,
@ -170,16 +210,31 @@ class updateTask(graphene.Mutation):
m = updateModel(Task, task, {
"theory": [theory, task.theory],
"practise": [practise, task.practise],
"number": [number, task.number],
"max_score": [max_score, task.max_score],
"Type": [taskType(from_global_id(Type)[1]), task.Type],
"is_autoCheck": [autoCheck, task.is_autoCheck],
"autoCheckData": [autoCheckData, task.autoCheckData],
"is_timing": [is_time, task.is_timing],
"time" : [time, task.time]
"time" : [time, task.time],
})
return updateTask(task=m)
class ScoringTasks(graphene.Mutation):
class Arguments:
answerSheetId = graphene.ID()
score = graphene.Int()
number = graphene.Int()
answer = graphene.Field(AnswerType)
def mutate(self, info, answerSheetId, score=0, number=0):
answer = AnswerSheet.objects.get(id=from_global_id(answerSheetId)[1]).answer_set.all().filter(number=number)[0]
answer.score = score
answer.completed = True
answer.save()
return ScoringTasks(answer=answer)
class deleteTask(graphene.Mutation):
class Arguments:
@ -427,6 +482,14 @@ class Mutation(graphene.ObjectType):
deleteMaterial = DeleteMaterial.Field()
changeMaterial = ChangeMaterail.Field()
create_anwer_sheet = CreateAnwerSheet.Field()
create_answer = CreateAnswer.Field()
scoring_tasks = ScoringTasks.Field()
class Query(graphene.ObjectType):
all_test = DjangoFilterConnectionField(TestsType)
@ -461,4 +524,6 @@ class Query(graphene.ObjectType):
task = relay.Node.Field(TaskType)
schema = graphene.Schema(query=Query)