Skip to content
Closed
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
5 changes: 4 additions & 1 deletion course/cache/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from lib.cache import CachedAbstract
from ..models import StudentGroup, Enrollment, CourseInstance
from ..renders import render_group_info


class CachedTopMenu(CachedAbstract):
Expand Down Expand Up @@ -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,
Expand Down
82 changes: 40 additions & 42 deletions course/static/course/usertagdropdown.js
Original file line number Diff line number Diff line change
@@ -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);
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading