From 0cb02074682a51b8d8669ce31d94b2b1f38fdaaf Mon Sep 17 00:00:00 2001 From: muhammad-ammar Date: Fri, 12 Jul 2024 12:41:18 +0500 Subject: [PATCH] feat: add new and missing fields in EnterpriseLearnerEnrollment model --- CHANGELOG.rst | 4 ++ enterprise_data/__init__.py | 2 +- enterprise_data/api/v1/serializers.py | 2 +- .../migrations/0040_auto_20240712_0740.py | 45 +++++++++++++++++++ enterprise_data/models.py | 9 +++- enterprise_data/renderers.py | 2 +- enterprise_data/utils.py | 9 +++- 7 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 enterprise_data/migrations/0040_auto_20240712_0740.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ce816c1e..1de79133 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,10 @@ Unreleased ---------- ========================= +[7.0.0] - 2024-07-12 +--------------------- + * Add new fields in EnterpriseLearnerEnrollment model + [6.2.3] - 2024-07-01 --------------------- * Dependency updates diff --git a/enterprise_data/__init__.py b/enterprise_data/__init__.py index 87ce83fa..4a082724 100644 --- a/enterprise_data/__init__.py +++ b/enterprise_data/__init__.py @@ -2,4 +2,4 @@ Enterprise data api application. This Django app exposes API endpoints used by enterprises. """ -__version__ = "6.2.3" +__version__ = "7.0.0" diff --git a/enterprise_data/api/v1/serializers.py b/enterprise_data/api/v1/serializers.py index 3e035455..c88ef868 100644 --- a/enterprise_data/api/v1/serializers.py +++ b/enterprise_data/api/v1/serializers.py @@ -41,7 +41,7 @@ class Meta: 'letter_grade', 'enterprise_user_id', 'user_email', 'user_account_creation_date', 'user_country_code', 'user_username', 'enterprise_name', 'enterprise_customer_uuid', 'enterprise_sso_uid', 'created', 'course_api_url', 'total_learning_time_hours', 'is_subsidy', - 'course_product_line', 'budget_id' + 'course_product_line', 'budget_id', 'enterprise_group_name', 'enterprise_group_uuid', ) def get_course_api_url(self, obj): diff --git a/enterprise_data/migrations/0040_auto_20240712_0740.py b/enterprise_data/migrations/0040_auto_20240712_0740.py new file mode 100644 index 00000000..a5b6d959 --- /dev/null +++ b/enterprise_data/migrations/0040_auto_20240712_0740.py @@ -0,0 +1,45 @@ +# Generated by Django 3.2.23 on 2024-07-12 07:40 + +from django.db import migrations, models + +import enterprise_data.utils + + +class Migration(migrations.Migration): + + dependencies = [ + ('enterprise_data', '0039_auto_20240212_1403'), + ] + + operations = [ + migrations.AddField( + model_name='enterpriselearnerenrollment', + name='enterprise_group_name', + field=models.CharField(max_length=25, null=True), + ), + migrations.AddField( + model_name='enterpriselearnerenrollment', + name='enterprise_group_uuid', + field=models.UUIDField(null=True), + ), + migrations.AddField( + model_name='enterpriselearnerenrollment', + name='is_included_in_utilization', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='enterpriselearnerenrollment', + name='lpr_unique_id', + field=models.PositiveBigIntegerField(default=enterprise_data.utils.get_unique_id, primary_key=True, serialize=False), + ), + migrations.AddField( + model_name='enterpriselearnerenrollment', + name='subscription_license_uuid', + field=models.UUIDField(null=True), + ), + migrations.AlterField( + model_name='enterpriselearnerenrollment', + name='enterprise_enrollment_id', + field=models.PositiveIntegerField(null=True), + ), + ] diff --git a/enterprise_data/models.py b/enterprise_data/models.py index 342cd184..482c78a3 100644 --- a/enterprise_data/models.py +++ b/enterprise_data/models.py @@ -9,6 +9,8 @@ from django.db import models from django.utils.translation import gettext_lazy as _ +from enterprise_data.utils import get_unique_id + LOGGER = getLogger(__name__) @@ -78,7 +80,7 @@ class Meta: ]), ] - enterprise_enrollment_id = models.PositiveIntegerField(primary_key=True) + enterprise_enrollment_id = models.PositiveIntegerField(null=True) enrollment_id = models.PositiveIntegerField(null=True) is_consent_granted = models.BooleanField(default=False) paid_by = models.CharField(max_length=255, null=True) @@ -133,6 +135,11 @@ class Meta: is_subsidy = models.BooleanField(default=False) course_product_line = models.CharField(max_length=64, null=True) budget_id = models.UUIDField(db_index=True, null=True) + is_included_in_utilization = models.BooleanField(default=False) + lpr_unique_id = models.PositiveBigIntegerField(primary_key=True, default=get_unique_id) + subscription_license_uuid = models.UUIDField(null=True) + enterprise_group_name = models.CharField(max_length=25, null=True) + enterprise_group_uuid = models.UUIDField(null=True) class EnterpriseAdminLearnerProgress(models.Model): diff --git a/enterprise_data/renderers.py b/enterprise_data/renderers.py index 5273a39d..cc5ac82e 100644 --- a/enterprise_data/renderers.py +++ b/enterprise_data/renderers.py @@ -27,5 +27,5 @@ class EnrollmentsCSVRenderer(CSVStreamingRenderer): 'letter_grade', 'enterprise_user_id', 'user_email', 'user_account_creation_date', 'user_country_code', 'user_username', 'enterprise_name', 'enterprise_customer_uuid', 'enterprise_sso_uid', 'created', 'course_api_url', 'total_learning_time_hours', 'is_subsidy', - 'course_product_line', 'budget_id' + 'course_product_line', 'budget_id', 'enterprise_group_name', 'enterprise_group_uuid', ] diff --git a/enterprise_data/utils.py b/enterprise_data/utils.py index 7aa66ec7..1ff3cd74 100644 --- a/enterprise_data/utils.py +++ b/enterprise_data/utils.py @@ -2,8 +2,8 @@ Utility functions for Enterprise Data app. """ - import hashlib +import random def get_cache_key(**kwargs): @@ -28,3 +28,10 @@ def get_cache_key(**kwargs): key = '__'.join([f'{item}:{value}' for item, value in kwargs.items()]) return hashlib.md5(key.encode('utf-8')).hexdigest() + + +def get_unique_id(): + """ + Return a unique 32 bit integer. + """ + return random.getrandbits(32)