Skip to content

Commit

Permalink
Merge pull request #312 from openedx/iahmad/ENT-5804
Browse files Browse the repository at this point in the history
feat: Added total_learning_time_seconds field in EnterpriseLearnerEnrollment
  • Loading branch information
irfanuddinahmad committed Jun 13, 2022
2 parents 356275b + 94e72a2 commit 1c5d9a2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Unreleased
----------

=========================
[4.2.6] - 2022-06-09
---------------------
* Add `total_learning_time_seconds` field in EnterpriseLearnerEnrollment

[4.2.5] - 2022-04-22
---------------------
* Rename base class to a more appropriate name
Expand Down
2 changes: 1 addition & 1 deletion enterprise_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Enterprise data api application. This Django app exposes API endpoints used by enterprises.
"""

__version__ = "4.2.5"
__version__ = "4.2.6"

default_app_config = "enterprise_data.apps.EnterpriseDataAppConfig" # pylint: disable=invalid-name
8 changes: 6 additions & 2 deletions enterprise_data/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Serializers for enterprise api v1.
"""


from rest_framework import serializers

from enterprise_data.models import EnterpriseLearner, EnterpriseLearnerEnrollment
Expand All @@ -14,6 +13,7 @@ class EnterpriseLearnerEnrollmentSerializer(serializers.ModelSerializer):
"""
course_api_url = serializers.SerializerMethodField()
enterprise_user_id = serializers.SerializerMethodField()
total_learning_time_hours = serializers.SerializerMethodField()

class Meta:
model = EnterpriseLearnerEnrollment
Expand All @@ -32,7 +32,7 @@ class Meta:
'last_activity_date', 'progress_status', 'passed_date', 'current_grade',
'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',
'enterprise_sso_uid', 'created', 'course_api_url', 'total_learning_time_hours',
)

def get_course_api_url(self, obj):
Expand All @@ -45,6 +45,10 @@ def get_enterprise_user_id(self, obj):
"""Returns enterprise user id of a learner's enrollment"""
return obj.enterprise_user_id

def get_total_learning_time_hours(self, obj):
"""Returns the learners total learning time in hours"""
return round(obj.total_learning_time_seconds/3600.0, 2)


class EnterpriseLearnerSerializer(serializers.ModelSerializer):
"""
Expand Down
2 changes: 1 addition & 1 deletion enterprise_data/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class EnterpriseLearnerEnrollmentViewSet(EnterpriseViewSetMixin, viewsets.ReadOn
'last_activity_date', 'progress_status', 'passed_date', 'current_grade',
'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',
'enterprise_sso_uid', 'created', 'course_api_url', 'total_learning_time_hours',
]

def get_renderer_context(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2022-06-09 10:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('enterprise_data', '0026_auto_20210916_0414'),
]

operations = [
migrations.AddField(
model_name='enterpriselearnerenrollment',
name='total_learning_time_seconds',
field=models.PositiveIntegerField(default=0),
),
]
1 change: 1 addition & 0 deletions enterprise_data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Meta:
course_primary_subject = models.CharField(max_length=255, null=True)
has_passed = models.BooleanField(default=False)
last_activity_date = models.DateField(null=True, db_index=True)
total_learning_time_seconds = models.PositiveIntegerField(default=0)
progress_status = models.CharField(max_length=255, null=True)
passed_date = models.DateField(null=True)
current_grade = models.FloatField(null=True)
Expand Down

0 comments on commit 1c5d9a2

Please sign in to comment.