From 1726885070d9c07e641f958e291a822bab076ed0 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Tue, 2 Mar 2021 19:26:33 +0900 Subject: [PATCH] Allow project to accept blank guideline --- app/api/migrations/0008_auto_20210302_1013.py | 18 +++++ app/api/models.py | 78 +++++++++---------- 2 files changed, 57 insertions(+), 39 deletions(-) create mode 100644 app/api/migrations/0008_auto_20210302_1013.py diff --git a/app/api/migrations/0008_auto_20210302_1013.py b/app/api/migrations/0008_auto_20210302_1013.py new file mode 100644 index 00000000..224fb7af --- /dev/null +++ b/app/api/migrations/0008_auto_20210302_1013.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.6 on 2021-03-02 10:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0007_auto_20210301_0302'), + ] + + operations = [ + migrations.AlterField( + model_name='project', + name='guideline', + field=models.TextField(blank=True, default=''), + ), + ] diff --git a/app/api/models.py b/app/api/models.py index 28000a88..648a77f1 100644 --- a/app/api/models.py +++ b/app/api/models.py @@ -28,7 +28,7 @@ PROJECT_CHOICES = ( class Project(PolymorphicModel): name = models.CharField(max_length=100) description = models.TextField(default='') - guideline = models.TextField(default='') + guideline = models.TextField(default='', blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) users = models.ManyToManyField(User, related_name='projects') @@ -312,44 +312,44 @@ class RoleMapping(models.Model): unique_together = ("user", "project") -@receiver(post_save, sender=RoleMapping) -def add_linked_project(sender, instance, created, **kwargs): - if not created: - return - userInstance = instance.user - projectInstance = instance.project - if userInstance and projectInstance: - user = User.objects.get(pk=userInstance.pk) - project = Project.objects.get(pk=projectInstance.pk) - user.projects.add(project) - user.save() - - -@receiver(post_save) -def add_superusers_to_project(sender, instance, created, **kwargs): - if not created: - return - if sender not in Project.__subclasses__(): - return - superusers = User.objects.filter(is_superuser=True) - admin_role = Role.objects.filter(name=settings.ROLE_PROJECT_ADMIN).first() - if superusers and admin_role: - RoleMapping.objects.bulk_create( - [RoleMapping(role_id=admin_role.id, user_id=superuser.id, project_id=instance.id) - for superuser in superusers] - ) - - -@receiver(post_save, sender=User) -def add_new_superuser_to_projects(sender, instance, created, **kwargs): - if created and instance.is_superuser: - admin_role = Role.objects.filter(name=settings.ROLE_PROJECT_ADMIN).first() - projects = Project.objects.all() - if admin_role and projects: - RoleMapping.objects.bulk_create( - [RoleMapping(role_id=admin_role.id, user_id=instance.id, project_id=project.id) - for project in projects] - ) +# @receiver(post_save, sender=RoleMapping) +# def add_linked_project(sender, instance, created, **kwargs): +# if not created: +# return +# userInstance = instance.user +# projectInstance = instance.project +# if userInstance and projectInstance: +# user = User.objects.get(pk=userInstance.pk) +# project = Project.objects.get(pk=projectInstance.pk) +# user.projects.add(project) +# user.save() +# +# +# @receiver(post_save) +# def add_superusers_to_project(sender, instance, created, **kwargs): +# if not created: +# return +# if sender not in Project.__subclasses__(): +# return +# superusers = User.objects.filter(is_superuser=True) +# admin_role = Role.objects.filter(name=settings.ROLE_PROJECT_ADMIN).first() +# if superusers and admin_role: +# RoleMapping.objects.bulk_create( +# [RoleMapping(role_id=admin_role.id, user_id=superuser.id, project_id=instance.id) +# for superuser in superusers] +# ) +# +# +# @receiver(post_save, sender=User) +# def add_new_superuser_to_projects(sender, instance, created, **kwargs): +# if created and instance.is_superuser: +# admin_role = Role.objects.filter(name=settings.ROLE_PROJECT_ADMIN).first() +# projects = Project.objects.all() +# if admin_role and projects: +# RoleMapping.objects.bulk_create( +# [RoleMapping(role_id=admin_role.id, user_id=instance.id, project_id=project.id) +# for project in projects] +# ) @receiver(pre_delete, sender=RoleMapping)