Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def test_get(self):
""" Verify the endpoint returns the details for a single course. """
url = reverse('api:v1:course-detail', kwargs={'key': self.course.key})

with self.assertNumQueries(26, threshold=3):
response = self.client.get(url)
response = self.client.get(url)
assert response.status_code == 200
assert response.data == self.serialize_course(self.course)

Expand Down
6 changes: 3 additions & 3 deletions course_discovery/apps/course_metadata/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ def get_urls(self):

class Media:
js = (
'js/jquery_shim.js',
'bower_components/jquery-ui/ui/minified/jquery-ui.min.js',
'bower_components/jquery/dist/jquery.min.js',
SortableSelectJSPath()
)

Expand Down Expand Up @@ -586,8 +586,8 @@ def save_model(self, request, obj, form, change):

class Media:
js = (
'js/jquery_shim.js',
'bower_components/jquery-ui/ui/minified/jquery-ui.min.js',
'bower_components/jquery/dist/jquery.min.js',
SortableSelectJSPath()
)

Expand Down Expand Up @@ -1080,8 +1080,8 @@ class SearchDefaultResultsConfigurationAdmin(admin.ModelAdmin):

class Media:
js = (
'js/jquery_shim.js',
'bower_components/jquery-ui/ui/minified/jquery-ui.min.js',
'bower_components/jquery/dist/jquery.min.js',
'js/sortable_select.js'
)

Expand Down
5 changes: 5 additions & 0 deletions course_discovery/static/js/jquery_shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Expose django.jQuery as jQuery and $ for jQuery UI compatibility
// This must be loaded BEFORE jQuery UI and AFTER Django admin's jQuery
if (typeof django !== 'undefined' && django.jQuery) {
window.jQuery = window.$ = django.jQuery;
}
80 changes: 41 additions & 39 deletions course_discovery/static/js/sortable_select.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,51 @@
function updateSelect2Data(el){
var i, j,
visibleTitlesLength,
selectOptionsLength,
visibleTitles = [],
selectOptions = [],
items = [],
selectOptionsElement = $(el).find('.select2-hidden-accessible'),
selectChoicesElement = $(el).find('.select2-selection__choice'),
selectOptionElement = $(selectOptionsElement).find('option');
(function($) {
function updateSelect2Data(el){
var i, j,
visibleTitlesLength,
selectOptionsLength,
visibleTitles = [],
selectOptions = [],
items = [],
selectOptionsElement = $(el).find('.select2-hidden-accessible'),
selectChoicesElement = $(el).find('.select2-selection__choice'),
selectOptionElement = $(selectOptionsElement).find('option');

selectChoicesElement.each(function(index, value){
if (value.title){
visibleTitles.push(value.title);
}
});
selectChoicesElement.each(function(index, value){
if (value.title){
visibleTitles.push(value.title);
}
});

selectOptionElement.each(function(index, value){
selectOptions.push({id: value.value, text: value.text});
});
selectOptionElement.each(function(index, value){
selectOptions.push({id: value.value, text: value.text});
});

// Update select2 options with new data
visibleTitlesLength = visibleTitles.length;
selectOptionsLength = selectOptions.length;
for (i = 0; i < visibleTitlesLength; i++) {
for (j = 0; j < selectOptionsLength; j++) {
if (selectOptions[j].text === visibleTitles[i]){
items.push('<option selected="selected" value="' + selectOptions[j].id + '">' +
selectOptions[j].text + '</option>'
);
// Update select2 options with new data
visibleTitlesLength = visibleTitles.length;
selectOptionsLength = selectOptions.length;
for (i = 0; i < visibleTitlesLength; i++) {
for (j = 0; j < selectOptionsLength; j++) {
if (selectOptions[j].text === visibleTitles[i]){
items.push('<option selected="selected" value="' + selectOptions[j].id + '">' +
selectOptions[j].text + '</option>'
);
}
}
}
}

if (items){
selectOptionsElement.html(items.join('\n'));
if (items.length > 0){
selectOptionsElement.html(items.join('\n'));
}
}
}

window.addEventListener('load', function(){
$(function() {
$('.sortable-select').parents('.form-row').each(function(index, el){
$(el).find('ul.select2-selection__rendered').sortable({
containment: 'parent',
update: function(){updateSelect2Data(el);}
window.addEventListener('load', function(){
$(function() {
$('.sortable-select').parents('.form-row').each(function(index, el){
$(el).find('ul.select2-selection__rendered').sortable({
containment: 'parent',
update: function(){updateSelect2Data(el);}
})
})
})
})
});
});
})(django.jQuery);
Loading