You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2022/05/10 21:30:44 UTC

[airavata-django-portal] 02/04: AIRAVATA-3565 Adding required column to ExtendedUserProfileField

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch AIRAVATA-3562
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git

commit 9a68c8082042d03062e0eccfddd48e1b86e3f5e6
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue May 10 16:19:56 2022 -0400

    AIRAVATA-3565 Adding required column to ExtendedUserProfileField
---
 .../0016_extendeduserprofilefield_required.py          | 18 ++++++++++++++++++
 django_airavata/apps/auth/models.py                    |  1 +
 django_airavata/apps/auth/serializers.py               |  3 ++-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/django_airavata/apps/auth/migrations/0016_extendeduserprofilefield_required.py b/django_airavata/apps/auth/migrations/0016_extendeduserprofilefield_required.py
new file mode 100644
index 00000000..4c6dd6f1
--- /dev/null
+++ b/django_airavata/apps/auth/migrations/0016_extendeduserprofilefield_required.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.11 on 2022-05-10 20:14
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('django_airavata_auth', '0015_auto_20220329_1708'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='extendeduserprofilefield',
+            name='required',
+            field=models.BooleanField(default=True),
+        ),
+    ]
diff --git a/django_airavata/apps/auth/models.py b/django_airavata/apps/auth/models.py
index b465fd4e..8d7cbb41 100644
--- a/django_airavata/apps/auth/models.py
+++ b/django_airavata/apps/auth/models.py
@@ -158,6 +158,7 @@ class ExtendedUserProfileField(models.Model):
     created_date = models.DateTimeField(auto_now_add=True)
     updated_date = models.DateTimeField(auto_now=True)
     deleted = models.BooleanField(default=False)
+    required = models.BooleanField(default=True)
 
     def __str__(self) -> str:
         return f"{self.name} ({self.id})"
diff --git a/django_airavata/apps/auth/serializers.py b/django_airavata/apps/auth/serializers.py
index 7d3a61dc..1b752362 100644
--- a/django_airavata/apps/auth/serializers.py
+++ b/django_airavata/apps/auth/serializers.py
@@ -125,7 +125,7 @@ class ExtendedUserProfileFieldSerializer(serializers.ModelSerializer):
     class Meta:
         model = models.ExtendedUserProfileField
         fields = ['id', 'name', 'help_text', 'order', 'created_date',
-                  'updated_date', 'field_type', 'other', 'choices', 'checkbox_label', 'links']
+                  'updated_date', 'field_type', 'other', 'choices', 'checkbox_label', 'links', 'required']
         read_only_fields = ('created_date', 'updated_date')
 
     def to_representation(self, instance):
@@ -175,6 +175,7 @@ class ExtendedUserProfileFieldSerializer(serializers.ModelSerializer):
         instance.name = validated_data['name']
         instance.help_text = validated_data['help_text']
         instance.order = validated_data['order']
+        instance.required = validated_data.get('required', instance.required)
         # logger.debug(f"instance.field_type={instance.field_type}, validated_data={validated_data}")
         if instance.field_type == 'single_choice':
             instance.single_choice.other = validated_data.get('other', instance.single_choice.other)