diff --git a/accounts/models.py b/accounts/models.py index 8342f7832..c63256ba4 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -222,6 +222,9 @@ def get_absolute_url(self): def get_user_sounds_in_search_url(self): return f'{reverse("sounds-search")}?f=username:"{ self.user.username }"&s=Date+added+(newest+first)&g=0' + + def get_user_packs_in_search_url(self): + return f'{reverse("sounds-search")}?f=username:"{ self.user.username }"&s=Date+added+(newest+first)&g=1&only_p=1' @staticmethod def locations_static(user_id, has_avatar): diff --git a/accounts/views.py b/accounts/views.py index 86e59a411..2f0e6c50c 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1416,9 +1416,6 @@ def charts(request): def account(request, username): user = request.parameter_user latest_sounds = list(Sound.objects.bulk_sounds_for_user(user.id, settings.SOUNDS_PER_PAGE)) - latest_pack_ids = Pack.objects.select_related().filter(user=user, num_sounds__gt=0).exclude(is_deleted=True) \ - .order_by("-last_updated").values_list('id', flat=True)[0:10 if not using_beastwhoosh(request) else 15] - latest_packs = Pack.objects.ordered_ids(pack_ids=latest_pack_ids) following = follow_utils.get_users_following_qs(user) followers = follow_utils.get_users_followers_qs(user) following_tags = follow_utils.get_tags_following_qs(user) @@ -1452,7 +1449,6 @@ def account(request, username): 'home': request.user == user if using_beastwhoosh(request) else False, 'user': user, 'latest_sounds': latest_sounds, - 'latest_packs': latest_packs, 'follow_user_url': follow_user_url, 'following': following, 'followers': followers, @@ -1472,6 +1468,33 @@ def account(request, username): return render(request, 'accounts/account.html', tvars) +@redirect_if_old_username_or_404 +def account_stats_section(request, username): + if not request.GET.get('ajax'): + raise Http404 # Only accessible via ajax + user = request.parameter_user + tvars = { + 'user': user, + 'user_stats': user.profile.get_stats_for_profile_page(), + } + return render(request, 'accounts/account_stats_section.html', tvars) + + +@redirect_if_old_username_or_404 +def account_latest_packs_section(request, username): + if not request.GET.get('ajax'): + raise Http404 # Only accessible via ajax + user = request.parameter_user + latest_pack_ids = Pack.objects.select_related().filter(user=user, num_sounds__gt=0).exclude(is_deleted=True) \ + .order_by("-last_updated").values_list('id', flat=True)[0:15] + latest_packs = Pack.objects.ordered_ids(pack_ids=latest_pack_ids) + tvars = { + 'user': user, + 'latest_packs': latest_packs, + } + return render(request, 'accounts/account_latest_packs_section.html', tvars) + + def handle_uploaded_file(user_id, f): # Move or copy the uploaded file from the temporary folder created by Django to the /uploads path dest_directory = os.path.join(settings.UPLOADS_PATH, str(user_id)) diff --git a/freesound/static/bw-frontend/src/components/asyncSection.js b/freesound/static/bw-frontend/src/components/asyncSection.js new file mode 100644 index 000000000..8e6d763ae --- /dev/null +++ b/freesound/static/bw-frontend/src/components/asyncSection.js @@ -0,0 +1,39 @@ +import {showToast} from "./toast"; +import {initPlayersInModal} from './modal'; +import {bindSimilarSoundModals} from './similarSoundsModal'; +import {bindBookmarkSoundButtons} from './bookmarkSound'; +import {bindRemixGroupModals} from './remixGroupModal'; + +const asyncSectionPlaceholders = document.getElementsByClassName('async-section'); + +const initPlayersAndPlayerModalsInElement = (element) => { + initPlayersInModal(element); + bindSimilarSoundModals(); + bindBookmarkSoundButtons(); + bindRemixGroupModals(); +} + +asyncSectionPlaceholders.forEach(element => { + const contentUrl = element.dataset.asyncSectionContentUrl; + + const req = new XMLHttpRequest(); + req.open('GET', contentUrl); + req.onload = () => { + if (req.status >= 200 && req.status < 300) { + element.innerHTML = req.responseText; + + // Make sure we initialize sound/pack players inside the async section + initPlayersAndPlayerModalsInElement(element); + } else { + // Unexpected errors happened while processing request: show toast + showToast('Unexpected errors occurred while loading some of the content of this page. Please try again later...') + } + }; + req.onerror = () => { + // Unexpected errors happened while processing request: show toast + showToast('Unexpected errors occurred while loading some of the content of this page. Please try again later...') + }; + + // Send the form + req.send(); +}); \ No newline at end of file diff --git a/freesound/static/bw-frontend/src/components/index.js b/freesound/static/bw-frontend/src/components/index.js index 9e61bcb11..7d57f5a2d 100644 --- a/freesound/static/bw-frontend/src/components/index.js +++ b/freesound/static/bw-frontend/src/components/index.js @@ -8,6 +8,7 @@ import './bookmarkSound'; import './checkbox'; import './commentsModal'; import './cookieConsent'; +import './asyncSection'; import './djangoMessages'; import './downloadersModals'; import './moderationModals'; diff --git a/freesound/static/bw-frontend/src/components/mapsMapbox.js b/freesound/static/bw-frontend/src/components/mapsMapbox.js index 40a6cad7b..a7095771e 100644 --- a/freesound/static/bw-frontend/src/components/mapsMapbox.js +++ b/freesound/static/bw-frontend/src/components/mapsMapbox.js @@ -1,7 +1,4 @@ -import {initPlayersInModal} from './modal'; -import {bindSimilarSoundModals} from './similarSoundsModal'; -import {bindBookmarkSoundButtons} from './bookmarkSound'; -import {bindRemixGroupModals} from './remixGroupModal'; +import {initPlayersAndPlayerModalsInElement} from './asyncSection'; import {stopAllPlayers} from '../components/player/utils' @@ -262,10 +259,7 @@ function makeSoundsMap(geotags_url, map_element_id, on_built_callback, on_bounds zoomLinkElement.onclick = () => {setMaxZoomCenter(zoomLinkElement.dataset.lat, zoomLinkElement.dataset.lon, zoomLinkElement.dataset.zoom)}; // Init sound player inside popup - initPlayersInModal(document.getElementById('infoWindowPlayerWrapper-' + sound_id)); - bindSimilarSoundModals(); - bindBookmarkSoundButtons(); - bindRemixGroupModals(); + initPlayersAndPlayerModalsInElement(document.getElementById('infoWindowPlayerWrapper-' + sound_id)); }); }); diff --git a/freesound/urls.py b/freesound/urls.py index 9e875cfa9..bb52a0e42 100644 --- a/freesound/urls.py +++ b/freesound/urls.py @@ -44,6 +44,8 @@ path('people/', accounts.views.accounts, name="accounts"), path('people//', accounts.views.account, name="account"), + path('people//section/stats/', accounts.views.account_stats_section, name="account-stats-section"), + path('people//section/latest_packs/', accounts.views.account_latest_packs_section, name="account-latest-packs-section"), path('people//sounds/', sounds.views.for_user, name="sounds-for-user"), path('people//flag/', accounts.views.flag_user, name="flag-user"), path('people//clear_flags/', accounts.views.clear_flags_user, name="clear-flags-user"), diff --git a/templates_bw/accounts/account.html b/templates_bw/accounts/account.html index 9c00065fa..baa3240b7 100644 --- a/templates_bw/accounts/account.html +++ b/templates_bw/accounts/account.html @@ -156,23 +156,10 @@
No sounds... 😟
{% endif %}
- {% if latest_packs %} -
- {% for pack in latest_packs %} -
- {% display_pack pack %} -
- {% endfor %} -
- - {% else %} -
-
No packs... 😟
-
Looks like {{ user.username }} has not uploaded any packs yet
-
- {% endif %} +
+ +
downloaded @@ -180,9 +167,10 @@
No packs... 😟