diff --git a/course/cache/menu.py b/course/cache/menu.py index 2673fb272..cac1a47cf 100644 --- a/course/cache/menu.py +++ b/course/cache/menu.py @@ -2,7 +2,6 @@ from lib.cache import CachedAbstract from ..models import StudentGroup, Enrollment, CourseInstance -from ..renders import render_group_info class CachedTopMenu(CachedAbstract): @@ -61,6 +60,10 @@ def _generate_groups(self, profile): if not profile: return {} + # Lazy import to avoid circular import during Django app initialization. + # (menu imports renders only when groups are actually generated.) + from ..renders import render_group_info # pylint: disable=import-outside-toplevel + def group_entry(group): return { 'id': group.id, diff --git a/course/static/course/usertagdropdown.js b/course/static/course/usertagdropdown.js index 38e05ad02..988473d81 100644 --- a/course/static/course/usertagdropdown.js +++ b/course/static/course/usertagdropdown.js @@ -1,46 +1,44 @@ -document.addEventListener('aplus:translation-ready', function() { - document.querySelectorAll('.usertags-container').forEach(function(container) { - const add_text = "Add new tagging"; - const user_id = container.dataset.userId; - const tag_ids = Array.from(container.querySelectorAll('.colortag')).map(function(tag) { - return tag.dataset.tagid; - }); - const get_users = (typeof get_users_for_user === 'function') ? - get_users_for_user(user_id) : - function() { return [user_id]; }; - const add_taggings_id = 'add-taggings-' + user_id; +(function ($) { + $(document).on('aplus:translation-ready', function() { + $('.usertags-container').each(function() { + const $container = $(this); + const add_text = _("Add new tagging"); + const user_id = $container.data('user-id'); + const tag_ids = $container.find('.colortag').map(function() { + return $(this).data('tagid'); + }).get(); + const get_users = (typeof get_users_for_user === 'function') ? + get_users_for_user(user_id) : + function() { return [user_id]; }; + const add_taggings_id = 'add-taggings-' + user_id; - create_tagging_dropdown( - tag_ids, - get_users, - add_text, - add_taggings_id, - function (elem) { - if (elem.querySelectorAll('.colortag').length > 0) - container.appendChild(elem); - }, - function (jqXHRs, tags_xhr) { tags_xhr.then(function (data_tags) { - const tags = data_tags.results; //FIXME course tags might be paginated and this only reads the first page - jqXHRs.forEach(function (jqXHR) { - jqXHR.then(function (data) { - const tag = tags.find(function (tag) { - return tag.id === data.tag.id; }); - // This callback may be called for multiple taggings (because - // the same tag may be added to multiple students at once), hence - // the tag must be added to the right container in the DOM. - const userContainer = document.querySelector('.usertags-container[data-user-id="' + data.user.id + '"]'); - if (userContainer) { - const dropdown = userContainer.querySelector('.dropdown'); - if (dropdown) { - dropdown.insertAdjacentHTML('beforebegin', django_colortag_label(tag) + ' '); + create_tagging_dropdown( + tag_ids, + get_users, + add_text, + add_taggings_id, + function ($elem) { + if ($elem.find('.colortag').length > 0) + $container.append($elem); + }, + function (jqXHRs, tags_xhr) { tags_xhr.done(function (data_tags) { + const tags = data_tags.results; //FIXME course tags might be paginated and this only reads the first page + jqXHRs.forEach(function (jqXHR) { + jqXHR.done(function (data) { + const tag = tags.find(function (tag) { + return tag.id === data.tag.id; }); + // This callback may be called for multiple taggings (because + // the same tag may be added to multiple students at once), hence + // the tag must be added to the right container in the DOM. + $('.usertags-container[data-user-id="' + data.user.id + '"]') + .find('.dropdown').before(django_colortag_label(tag), ' '); + if (typeof extra_click_handler === 'function') { + extra_click_handler(data); } - } - if (typeof extra_click_handler === 'function') { - extra_click_handler(data); - } + }); }); - }); - });} - ); + });} + ); + }); }); -}); +})(jQuery); \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 46dc48685..bc2a030f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,8 @@ djangorestframework-csv ~= 2.1.0 git+https://github.com/apluslms/drf-extensions.git@reimplement_nested_routes_v6#egg=drf_extensions==0.8.0.dev1 git+https://github.com/apluslms/django-essentials.git@1.6.0#egg=django-essentials==1.6.0 git+https://github.com/apluslms/js-jquery-toggle.git@1.1.0#egg=js-jquery-toggle-django==1.1.0&subdirectory=django -git+https://github.com/apluslms/django-colortag.git@2.4.0#egg=django-colortag==2.4.0 +#git+https://github.com/apluslms/django-colortag.git@2.4.0#egg=django-colortag==2.4.0 +git+https://github.com/sayravai/django-colortag.git@bs5#egg=django-colortag feedparser ~= 6.0.2 html5lib ~= 1.1 lxml ~= 5.3.1