Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions credentials/apps/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class SiteConfigurationAdmin(admin.ModelAdmin):
{
"fields": (
"site",
"edx_org_short_name",
"platform_name",
"company_name",
"segment_key",
Expand Down Expand Up @@ -178,4 +179,9 @@ class SiteConfigurationAdmin(admin.ModelAdmin):
)
},
),
(_('Edly Settings'), {
'fields': (
'edly_client_branding_and_django_settings',
)
}),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.20 on 2025-09-16 11:47

from django.db import migrations
import jsonfield.fields


class Migration(migrations.Migration):

dependencies = [
('core', '0023_add_core_user_indices'),
]

operations = [
migrations.AddField(
model_name='siteconfiguration',
name='edly_client_branding_and_django_settings',
field=jsonfield.fields.JSONField(default={}, help_text='JSON string containing edly client theme branding & Django settings.', verbose_name='Edly client theme branding & Django settings'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.20 on 2025-10-08 06:04

from django.db import migrations, models
import jsonfield.fields


class Migration(migrations.Migration):

dependencies = [
('core', '0024_siteconfiguration_edly_client_branding_and_django_settings'),
]

operations = [
migrations.AddField(
model_name='siteconfiguration',
name='edx_org_short_name',
field=models.CharField(help_text='Unique, short string identifier for organization, same as LMS. Please do not use spaces or special characters. Only allowed special characters are period (.), hyphen (-) and underscore (_).', max_length=255, null=True, unique=True, verbose_name='Organization short name'),
),
migrations.AlterField(
model_name='siteconfiguration',
name='edly_client_branding_and_django_settings',
field=jsonfield.fields.JSONField(default=dict, help_text='JSON string containing edly client theme branding & Django settings.', verbose_name='Edly client theme branding & Django settings'),
),
]
36 changes: 36 additions & 0 deletions credentials/apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import hashlib
from urllib.parse import urljoin
import logging

from django.conf import settings
from django.contrib.auth.models import AbstractUser
Expand All @@ -10,7 +11,9 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from edx_rest_api_client.client import OAuthAPIClient
from jsonfield.fields import JSONField

log = logging.getLogger(__name__)

class SiteConfiguration(models.Model):
"""
Expand All @@ -20,6 +23,17 @@ class SiteConfiguration(models.Model):
"""

site = models.OneToOneField(Site, null=False, blank=False, on_delete=models.CASCADE)
edx_org_short_name = models.CharField(
max_length=255,
unique=True,
verbose_name=u'Organization short name',
help_text=_(
'Unique, short string identifier for organization, same as LMS. '
'Please do not use spaces or special characters. '
'Only allowed special characters are period (.), hyphen (-) and underscore (_).'
),
null=True,
)
platform_name = models.CharField(
verbose_name=_("Platform Name"),
help_text=_("Name of your Open edX platform"),
Expand Down Expand Up @@ -124,6 +138,12 @@ class SiteConfiguration(models.Model):
enable_twitter_sharing = models.BooleanField(
verbose_name=_("Enable Twitter sharing"), help_text=_("Enable sharing via Twitter"), default=True
)
edly_client_branding_and_django_settings = JSONField(
verbose_name=_('Edly client theme branding & Django settings'),
help_text=_('JSON string containing edly client theme branding & Django settings.'),
null=False,
default=dict
)

def __str__(self):
return self.site.name
Expand Down Expand Up @@ -188,6 +208,22 @@ def get_user_api_data(self, username):

return user_data

def get_edly_configuration_value(self, name, default=None):
"""
Return Configuration value for the key specified as name argument.
Function logs a message if there is an error retrieving a key.
Arguments:
name (str): Name of the key for which to return configuration value.
default: default value to return if key is not found in the configuration
Returns:
Configuration value for the given key or returns `None` if default is not available.
"""
try:
return self.edly_client_branding_and_django_settings.get(name, default)
except AttributeError as error:
log.exception('Invalid JSON data. \n [%s]', error)

return default

class User(AbstractUser):
"""
Expand Down
5 changes: 3 additions & 2 deletions credentials/apps/credentials/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def filter_visible(qs: "QuerySet") -> "QuerySet":
Filters a UserCredentials queryset by excluding credentials that aren't
supposed to be visible yet.
"""
visible_course_certs = _filter_visible_course_certificates(qs.filter(course_credentials__isnull=False))
# EDLYCUSTOM: we do not save course cert in credentials service, so removing this filter for now
visible_course_certs = _filter_visible_course_certificates(qs)
visible_program_certs = _filter_visible_program_certificates(qs.filter(program_credentials__isnull=False))
visible_certs = visible_course_certs | visible_program_certs

Expand Down Expand Up @@ -121,7 +122,7 @@ def _get_program_certificate_visible_date(user_program_credential: UserCredentia
(DateTime or None): The date on which the program credential should be
visible. (It shouldn’t return None but is technically possible.)
"""
last_date = None # type: Optional[datetime.datetime]
last_date = user_program_credential.created
for course_run in user_program_credential.credential.program.course_runs.all():
# Does the user have a course cert for this course run?
course_run_cert = UserCredential.objects.filter(
Expand Down
3 changes: 2 additions & 1 deletion credentials/apps/records/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ def get_user_program_data(
allowed_statuses.append(ProgramStatus.RETIRED.value)

# Get a list of programs
programs = get_filtered_programs(request_site, allowed_statuses, **course_filters)
# EDLYCUSTOM: we do not save course cert in credentials service, so removing this filter for now
programs = get_filtered_programs(request_site, allowed_statuses)

# Get the completed programs and a UUID set using the program_credentials
program_credential_ids = [program_credential.credential_id for program_credential in program_credentials]
Expand Down
Loading