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
16 changes: 15 additions & 1 deletion partner_catalog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class PartnerCatalogAdmin(admin.ModelAdmin, CourseKeysMixin):
"add_learner",
"add_course",
"add_manager",
"image_thumb",
]
list_filter = [
"partner",
Expand All @@ -233,7 +234,7 @@ class PartnerCatalogAdmin(admin.ModelAdmin, CourseKeysMixin):
readonly_fields = ["course_keys", "slug"]

fieldsets = (
("Basic Information", {"fields": ("name", "partner", "slug")}),
("Basic Information", {"fields": ("name", "partner", "slug", "image")}),
(
"Enrollment Settings",
{
Expand Down Expand Up @@ -287,6 +288,19 @@ def learner_count(self, obj):

learner_count.short_description = "Learners"

def image_thumb(self, obj):
"""Display a thumbnail preview of the catalog image if available."""
if obj.image:
return format_html(
'<img src="{}" width="64" height="36" style="object-fit:cover;border-radius:4px;" />',
obj.image.url,
)
return format_html(
'<span style="color: #999; font-style: italic;">No image</span>'
)

image_thumb.short_description = "Image"

def add_learner(self, obj):
"""Generate a link to add a new learner to this catalog."""
learner_model = CatalogLearner
Expand Down
18 changes: 18 additions & 0 deletions partner_catalog/migrations/0006_partnercatalog_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.20 on 2025-11-26 15:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('partner_catalog', '0005_create_base_catalog_instance'),
]

operations = [
migrations.AddField(
model_name='partnercatalog',
name='image',
field=models.ImageField(blank=True, null=True, upload_to='partner_catalog_images/'),
),
]
7 changes: 6 additions & 1 deletion partner_catalog/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Models for managing course catalogs and access for corporate partners."""

from importlib import import_module

import regex
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
Expand All @@ -11,7 +13,6 @@
from flex_catalog.models import FlexibleCatalogModel
from partner_catalog.edxapp_wrapper.course_module import course_overview
from partner_catalog.helpers.current_user import safe_get_current_user
from partner_catalog.services.allowed_courses import CatalogAllowedCoursesService


class BaseCatalog(FlexibleCatalogModel):
Expand Down Expand Up @@ -144,6 +145,7 @@ class PartnerCatalog(FlexibleCatalogModel):
available_start_date = models.DateTimeField()
available_end_date = models.DateTimeField()
authorization_message = models.TextField(blank=True, null=True)
image = models.ImageField(upload_to="partner_catalog_images/", blank=True, null=True)
support_email = models.EmailField(blank=True, null=True)
alternative_link = models.URLField(blank=True, null=True)

Expand Down Expand Up @@ -187,6 +189,9 @@ def active(self):

def get_course_runs(self):
"""Return all catalog course runs associated with this instance."""
allowed_courses_module = import_module('partner_catalog.services.allowed_courses')
CatalogAllowedCoursesService = allowed_courses_module.CatalogAllowedCoursesService

user = safe_get_current_user()
return CatalogAllowedCoursesService.course_runs_for_user(
catalog=self, user=user
Expand Down