Skip to content

Commit

Permalink
perf: optimize loading of django admin program pages (#4537)
Browse files Browse the repository at this point in the history
  • Loading branch information
zawan-ila authored Jan 9, 2025
1 parent 8275032 commit 8bf269c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
15 changes: 12 additions & 3 deletions course_discovery/apps/course_metadata/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from django.db.utils import IntegrityError
from django.forms import CheckboxSelectMultiple, ModelForm
from django.http import HttpResponseRedirect
from django.templatetags.static import static
from django.urls import re_path, reverse
from django.utils.html import format_html
from django.utils.html import format_html, html_safe
from django.utils.translation import gettext_lazy as _
from django_object_actions import DjangoObjectActions
from parler.admin import TranslatableAdmin
Expand Down Expand Up @@ -53,6 +54,13 @@ class Meta:
}


@html_safe
class SortableSelectJSPath:
def __str__(self):
abs_path = static('js/sortable_select.js')
return f'<script src="{abs_path}" defer></script>'


class ProgramEligibilityFilter(admin.SimpleListFilter):
title = _('eligible for one-click purchase')
parameter_name = 'eligible_for_one_click_purchase'
Expand Down Expand Up @@ -125,6 +133,7 @@ class ProductValueAdmin(admin.ModelAdmin):
list_display = [
'id', 'per_click_usa', 'per_click_international', 'per_lead_usa', 'per_lead_international'
]
search_fields = ('id',)


@admin.register(Course)
Expand Down Expand Up @@ -390,7 +399,7 @@ class ProgramAdmin(DjangoObjectActions, SimpleHistoryAdmin):
raw_id_fields = ('video',)
autocomplete_fields = (
'corporate_endorsements', 'faq', 'individual_endorsements', 'job_outlook_items',
'expected_learning_items',
'expected_learning_items', 'in_year_value'
)
search_fields = ('uuid', 'title', 'marketing_slug')
exclude = ('card_image_url',)
Expand Down Expand Up @@ -523,7 +532,7 @@ class Media:
js = (
'bower_components/jquery-ui/ui/minified/jquery-ui.min.js',
'bower_components/jquery/dist/jquery.min.js',
'js/sortable_select.js'
SortableSelectJSPath()
)


Expand Down
6 changes: 3 additions & 3 deletions course_discovery/apps/course_metadata/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
@ddt.ddt
class SortedModelSelect2MultipleTests(TestCase):
@ddt.data(
(['1', '2'], [1, 2, 3]),
(['2', '1'], [2, 1, 3]),
(['3'], [3, 1, 2]),
(['1', '2'], [1, 2]),
(['2', '1'], [2, 1]),
(['3'], [3,]),
)
@ddt.unpack
def test_optgroups_are_sorted(self, value, result_order):
Expand Down
2 changes: 1 addition & 1 deletion course_discovery/apps/course_metadata/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def optgroups(self, name, value, attrs=None):
ordered.append(item)
break

return ordered + unselected
return ordered

0 comments on commit 8bf269c

Please sign in to comment.