From d73246146fda7fc912c6ea803bdbd4a2442a7e7d Mon Sep 17 00:00:00 2001 From: Diederik Boeren Date: Sun, 17 Dec 2023 04:35:10 +0000 Subject: [PATCH] Fixed solo attribute being on project instead of projectuser --- ...10_remove_project_solo_projectuser_solo.py | 22 +++++++++++++++++++ backend/portfolio42_api/models.py | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 backend/portfolio42_api/migrations/0010_remove_project_solo_projectuser_solo.py diff --git a/backend/portfolio42_api/migrations/0010_remove_project_solo_projectuser_solo.py b/backend/portfolio42_api/migrations/0010_remove_project_solo_projectuser_solo.py new file mode 100644 index 0000000..1f39204 --- /dev/null +++ b/backend/portfolio42_api/migrations/0010_remove_project_solo_projectuser_solo.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.7 on 2023-12-17 04:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('portfolio42_api', '0009_remove_user_intra_username'), + ] + + operations = [ + migrations.RemoveField( + model_name='project', + name='solo', + ), + migrations.AddField( + model_name='projectuser', + name='solo', + field=models.BooleanField(default=True), + ), + ] diff --git a/backend/portfolio42_api/models.py b/backend/portfolio42_api/models.py index 866ddd7..c0929ff 100644 --- a/backend/portfolio42_api/models.py +++ b/backend/portfolio42_api/models.py @@ -90,7 +90,6 @@ class Project(IntraBaseModel): name = models.CharField(max_length=50) description = models.TextField(max_length=2000) exam = models.BooleanField(default=False) - solo = models.BooleanField(default=True) users = models.ManyToManyField('User', through='ProjectUser', related_name='projects') cursus = models.ManyToManyField('cursus', through='ProjectCursus', related_name='projects') @@ -110,7 +109,6 @@ def update(project): p.description = project['slug'] p.exam = project['exam'] - p.solo = False # todo: REMOVE THIS p.save() log_update(p, created) @@ -146,6 +144,7 @@ class ProjectUser(IntraBaseModel): grade = models.IntegerField() finished = models.BooleanField(default=False) finished_at = models.DateTimeField() + solo = models.BooleanField(default=True) def __str__(self): return f"(user: {self.id_user}, project: {self.id_project})" @@ -164,6 +163,7 @@ def update(user, projectuser): 'grade': 0}) pu.finished = projectuser['validated?'] if projectuser['validated?'] is not None else False + pu.solo = True if len(projectuser['teams'][0]['users']) == 1 else False if pu.finished: d = timezone.make_aware(datetime.strptime(projectuser['updated_at'], '%Y-%m-%dT%H:%M:%S.%fZ'), timezone.utc) pu.finished_at = d