From ea3b1e4375a1b7c420694e0789b23ecf91eda153 Mon Sep 17 00:00:00 2001 From: ffont Date: Tue, 27 Feb 2024 14:36:51 +0100 Subject: [PATCH 1/8] Move comments section so it does not move with expanded share section --- templates/sounds/sound.html | 119 ++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 61 deletions(-) diff --git a/templates/sounds/sound.html b/templates/sounds/sound.html index 7193e9529..5afc69ed4 100644 --- a/templates/sounds/sound.html +++ b/templates/sounds/sound.html @@ -172,7 +172,64 @@

+
+
Comments
+
+ {% if request.user.is_authenticated %} +
{% csrf_token %} +
+
+ {{form.as_p}} +
+
+ +
+
+
+ {% else %} + {% if not request.user.is_authenticated and page.object_list %} +
+ Please log in to comment +
+ {% endif %} + {% endif %} +
+ {% if page.object_list %} + {% for comment in page.object_list %} +
+
+ {% display_user_comment comment.user comment.created %} +
+ {% flag_user "SC" comment.user.username comment.id "" comment.user.profile.num_sounds %} + {% if perms.comments.delete_comment or sound.user == request.user or comment.user == request.user %} + {% bw_icon 'trash' %} Delete + {% endif %} +
+
+

{{ comment.comment|replace_img|safe|linebreaks|strip_unnecessary_br }}

+ {% if not forloop.last %} +
+ {% endif %} +
+ {% endfor %} + +
+ {% bw_paginator paginator page current_page request "comments" %} +
+ + {% else %} +
This sound has not been commented on yet, be the first to comment!
+ {% if not request.user.is_authenticated %} +
+ Please log in to comment +
+ {% endif %} + {% endif %} +
+
+
@@ -286,66 +343,6 @@

-
-
-
Comments
-
- {% if request.user.is_authenticated %} -
{% csrf_token %} -
-
- {{form.as_p}} -
-
- -
-
-
- {% else %} - {% if not request.user.is_authenticated and page.object_list %} -
- Please log in to comment -
- {% endif %} - {% endif %} -
- {% if page.object_list %} - {% for comment in page.object_list %} -
-
- {% display_user_comment comment.user comment.created %} -
- {% flag_user "SC" comment.user.username comment.id "" comment.user.profile.num_sounds %} - {% if perms.comments.delete_comment or sound.user == request.user or comment.user == request.user %} - {% bw_icon 'trash' %} Delete - {% endif %} -
-
-

{{ comment.comment|replace_img|safe|linebreaks|strip_unnecessary_br }}

- {% if not forloop.last %} -
- {% endif %} -
- {% endfor %} - -
- {% bw_paginator paginator page current_page request "comments" %} -
- - {% else %} -
This sound has not been commented on yet, be the first to comment!
- {% if not request.user.is_authenticated %} -
- Please log in to comment -
- {% endif %} - {% endif %} -
-
-
-

From 877a12e446093def71953c9963624cbf417396bd Mon Sep 17 00:00:00 2001 From: ffont Date: Tue, 27 Feb 2024 15:36:32 +0100 Subject: [PATCH 2/8] Use sound static URL with alt+click on share link --- freesound/static/bw-frontend/src/pages/sound.js | 16 ++++++++++++---- general/templatetags/absurl.py | 6 ++++++ templates/sounds/sound.html | 4 ++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/freesound/static/bw-frontend/src/pages/sound.js b/freesound/static/bw-frontend/src/pages/sound.js index 71fac49df..53b03bdd4 100644 --- a/freesound/static/bw-frontend/src/pages/sound.js +++ b/freesound/static/bw-frontend/src/pages/sound.js @@ -17,8 +17,15 @@ const urlParams = new URLSearchParams(window.location.search); prepareAfterDownloadSoundModals(); -const copyShareUrlToClipboard = () => { +const copyShareUrlToClipboard = (useFileURL) => { var shareLinkInputElement = shareLinkElement.getElementsByTagName("input")[0]; + console.log(shareLinkElement.dataset.staticFileUrl + , shareLinkElement.dataset.soundPageUrl) + if (useFileURL) { + shareLinkInputElement.value = shareLinkElement.dataset.staticFileUrl; + } else { + shareLinkInputElement.value = shareLinkElement.dataset.soundPageUrl; + } shareLinkInputElement.select(); shareLinkInputElement.setSelectionRange(0, 99999); document.execCommand("copy"); @@ -38,10 +45,11 @@ const toggleEmbedCode = () => { } } -const toggleShareLink = () => { +const toggleShareLink = (evt) => { if (shareLinkElement.style.display === "none") { shareLinkElement.style.display = "block"; - copyShareUrlToClipboard(); + const useFileURL = evt.altKey; + copyShareUrlToClipboard(useFileURL); } else { shareLinkElement.style.display = "none"; } @@ -52,7 +60,7 @@ const toggleShareLink = () => { } toggleEmbedCodeElement.addEventListener('click', toggleEmbedCode); -toggleShareLinkElement.addEventListener('click', toggleShareLink); +toggleShareLinkElement.addEventListener('click', evt => toggleShareLink(evt)); const generateEmbedCode = (size) => { diff --git a/general/templatetags/absurl.py b/general/templatetags/absurl.py index 85f17e43f..aa04b6758 100644 --- a/general/templatetags/absurl.py +++ b/general/templatetags/absurl.py @@ -40,3 +40,9 @@ def absurl(parser, token, node_cls=AbsoluteURLNode): asvar=node_instance.asvar) absurl = register.tag(absurl) + + +@register.filter +def url2absurl(path): + domain = f"https://{Site.objects.get_current().domain}" + return urllib.parse.urljoin(domain, path) diff --git a/templates/sounds/sound.html b/templates/sounds/sound.html index 5afc69ed4..c9b936bcf 100644 --- a/templates/sounds/sound.html +++ b/templates/sounds/sound.html @@ -311,8 +311,8 @@
Comments
-
- +
+ Format: + +
+
- +
{% endblock %} From b564d47fdabc74745df3e563b696c632f6169579 Mon Sep 17 00:00:00 2001 From: ffont Date: Mon, 11 Mar 2024 16:55:01 +0100 Subject: [PATCH 5/8] Attribute sources of sounds as well https://github.com/MTG/freesound/issues/1681 --- sounds/models.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/sounds/models.py b/sounds/models.py index 514d3b661..79792c2c3 100644 --- a/sounds/models.py +++ b/sounds/models.py @@ -932,18 +932,27 @@ def get_license_history(self): @cached_property def attribution_texts(self): - return { - 'plain_text': f'{self.original_filename} by {self.user.username} -- {url2absurl(reverse("short-sound-link", args=[self.id]))} -- License: {self.license.name_with_version}', - 'html': f'{self.original_filename} by {self.user.username} | License: {self.license.name_with_version}', - 'json': json.dumps({ - 'sound_url': url2absurl(self.get_absolute_url()), - 'sound_name': self.original_filename, - 'author_url': url2absurl(reverse("account", args=[self.user.username])), - 'author_name': self.user.username, - 'license_url': self.license.deed_url, - 'license_name': self.license.name_with_version, - }) - } + attribution_texts = { + 'plain_text': f'{self.original_filename} by {self.user.username} -- {url2absurl(reverse("short-sound-link", args=[self.id]))} -- License: {self.license.name_with_version}', + 'html': f'{self.original_filename} by {self.user.username} | License: {self.license.name_with_version}', + 'json': json.dumps({ + 'sound_url': url2absurl(self.get_absolute_url()), + 'sound_name': self.original_filename, + 'author_url': url2absurl(reverse("account", args=[self.user.username])), + 'author_name': self.user.username, + 'license_url': self.license.deed_url, + 'license_name': self.license.name_with_version, + }) + } + if not self.sources.exists(): + return attribution_texts + else: + sources_attribution_texts = [s.attribution_texts for s in self.sources.all()] + attribution_texts['plain_text'] = "\n\n".join([attribution_texts['plain_text']] + [st['plain_text'] for st in sources_attribution_texts]) + attribution_texts['html'] = "
\n".join([attribution_texts['html']] + [st['html'] for st in sources_attribution_texts]) + attribution_texts['json'] = json.dumps([json.loads(attribution_texts['json'])] + [json.loads(st['json']) for st in sources_attribution_texts]) + return attribution_texts + def get_sound_tags(self, limit=None): """ From 59c2adea2b817d3fff3cdf4dc90b47b4006e4a2b Mon Sep 17 00:00:00 2001 From: ffont Date: Fri, 15 Mar 2024 12:37:32 +0100 Subject: [PATCH 6/8] Make error message clearer --- accounts/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/forms.py b/accounts/forms.py index 78647b554..61ff350ae 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -159,7 +159,7 @@ def __init__(self, required=True): max_length=30, validators=[RegexValidator(r'^[\w.+-]+$')], # is the same as Django UsernameValidator except for '@' symbol help_text="30 characters or fewer. Can contain: letters, digits, underscores, dots, dashes and plus signs.", - error_messages={'invalid': "This value must contain only letters, digits, underscores, dots, dashes and " + error_messages={'invalid': "The username field must contain only letters, digits, underscores, dots, dashes and " "plus signs."}, required=required) From 1390ead67a353b005b97f1735147336e9e47b03a Mon Sep 17 00:00:00 2001 From: ffont Date: Fri, 15 Mar 2024 14:49:57 +0100 Subject: [PATCH 7/8] Fix issue coppying sound/attribution url/text --- freesound/static/bw-frontend/src/pages/sound.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freesound/static/bw-frontend/src/pages/sound.js b/freesound/static/bw-frontend/src/pages/sound.js index 282fcfb13..a3cebe1d9 100644 --- a/freesound/static/bw-frontend/src/pages/sound.js +++ b/freesound/static/bw-frontend/src/pages/sound.js @@ -20,8 +20,8 @@ prepareAfterDownloadSoundModals(); const copyFromInputElement = (inputElement) => { inputElement.select(); inputElement.setSelectionRange(0, 99999); - inputElement.execCommand("copy"); - inputElement.getSelection().removeAllRanges(); + document.execCommand("copy"); + document.getSelection().removeAllRanges(); } From 2214bf7c3b1409d8d3d531bf4a05bf0d6d3cadb9 Mon Sep 17 00:00:00 2001 From: ffont Date: Tue, 9 Apr 2024 15:33:24 +0200 Subject: [PATCH 8/8] Avoid new default boldish font on ios --- freesound/static/bw-frontend/styles/layout/global.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freesound/static/bw-frontend/styles/layout/global.scss b/freesound/static/bw-frontend/styles/layout/global.scss index 51caf51b6..935c3f6b4 100644 --- a/freesound/static/bw-frontend/styles/layout/global.scss +++ b/freesound/static/bw-frontend/styles/layout/global.scss @@ -13,7 +13,7 @@ html { } body { - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, + font-family: BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; font-size: $base-size-mobile; line-height: $base-line-height-mobile; @@ -21,7 +21,7 @@ body { background-color: $white; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; - font-weight: 400; /* designer sugegsted overall font weight 500, but we're making it 400 as otherwise it felt too heavy */ + font-weight: 400; /* designer suggested overall font weight 500, but we're making it 400 as otherwise it felt too heavy */ /* disallow avoid horizontal scrolling */ max-width: 100%;