Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: optimize loading of django admin program pages #4537

Merged
merged 4 commits into from
Jan 9, 2025
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
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()
zawan-ila marked this conversation as resolved.
Show resolved Hide resolved
)


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]),
AfaqShuaib09 marked this conversation as resolved.
Show resolved Hide resolved
(['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
zawan-ila marked this conversation as resolved.
Show resolved Hide resolved
Loading