Skip to content
Merged
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
16 changes: 16 additions & 0 deletions DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ that were made, and allow feedback if necessary

## Specific notes

### Template tag optional arguments

Optional arguments in template tags must always be keyword-only:
Comment thread
alastair marked this conversation as resolved.

```py
@register.inclusion_tag("atoms/avatar.html")
def bw_user_avatar(avatar_url, username, *, size=40, extra_class=""):
```

and templates need to specify the keywords in order to change the default:

```html
{% bw_user_avatar url username size=32 %}
```


### Custom Django permissions

If there is a need for defining custom permissions we should define them in the corresponding model's `Meta` class
Expand Down
2 changes: 1 addition & 1 deletion accounts/templatetags/display_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def display_user_comment(context, user, comment_created):


@register.inclusion_tag("accounts/display_user_selectable.html", takes_context=True)
def display_user_small_selectable(context, user, selected=False):
def display_user_small_selectable(context, user, *, selected=False):
context = context.get("original_context", context)
tvars = display_user(context, user, size="basic")
tvars.update(
Expand Down
2 changes: 1 addition & 1 deletion accounts/templatetags/filefunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@


@register.inclusion_tag("accounts/recursive_file.html")
def show_file(file_structure, non_recursive=False):
def show_file(file_structure, *, non_recursive=False):
return {"file": file_structure, "non_recursive": non_recursive}
2 changes: 1 addition & 1 deletion accounts/templatetags/flag_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


@register.inclusion_tag("accounts/flag_user.html", takes_context=True)
def flag_user(context, flag_type, username, content_id, text=None, user_sounds=None):
def flag_user(context, flag_type, username, content_id, *, text=None, user_sounds=None):
no_show = False
link_text = "Report spam/offensive"

Expand Down
10 changes: 6 additions & 4 deletions general/templatetags/bw_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def bw_icon(name, class_name=""):


@register.inclusion_tag("atoms/tag.html")
def bw_tag(tag_name, size=1, class_name="", url=None, weight=None):
def bw_tag(tag_name, *, size=1, class_name="", url=None, weight=None):
"""
Displays a BW tag with the given name
"""
Expand All @@ -66,7 +66,7 @@ def bw_tag(tag_name, size=1, class_name="", url=None, weight=None):


@register.inclusion_tag("atoms/avatar.html")
def bw_user_avatar(avatar_url, username, size=40, extra_class=""):
def bw_user_avatar(avatar_url, username, *, size=40, extra_class=""):
"""
Displays a BW user avatar or no avatar if user has none
We check if user has custom avatar by checking if the given avatar URL contains the filename of the default
Expand All @@ -91,7 +91,9 @@ def bw_user_avatar(avatar_url, username, size=40, extra_class=""):


@register.inclusion_tag("atoms/stars.html", takes_context=True)
def bw_sound_stars(context, sound, allow_rating=True, use_request_user_rating=False, show_added_rating_on_save=False):
def bw_sound_stars(
context, sound, *, allow_rating=True, use_request_user_rating=False, show_added_rating_on_save=False
):
if isinstance(sound, dict):
sound_user = sound["username"]
sound_avg_rating = sound["avg_rating"]
Expand Down Expand Up @@ -179,7 +181,7 @@ def bw_generic_stars(context, rating_0_10):


@register.inclusion_tag("molecules/paginator.html", takes_context=True)
def bw_paginator(context, page, request, anchor="", non_grouped_number_of_results=-1, max_pages=None):
def bw_paginator(context, page, request, *, anchor="", non_grouped_number_of_results=-1, max_pages=None):
"""
Adds pagination context variables for use in displaying first, adjacent and
last page links in addition to those created by the object_list generic
Expand Down
2 changes: 1 addition & 1 deletion general/templatetags/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
def _render(num_pages, current_page, max_pages_expr):
page = Paginator(range(num_pages * 15), 15).page(current_page)
request = RequestFactory().get("/search/?q=wind")
tpl = Template("{% load bw_templatetags %}{% bw_paginator page request 'sound' -1 " + max_pages_expr + " %}")
tpl = Template("{% load bw_templatetags %}{% bw_paginator page request anchor='sound' " + max_pages_expr + " %}")
return tpl.render(Context({"page": page, "request": request}))


Expand Down
2 changes: 1 addition & 1 deletion search/templatetags/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def display_facet_beta(context, facet_name, facet_title=None):


@register.inclusion_tag("search/search_option.html", takes_context=True)
def display_search_option(context, option_name, widget=None):
def display_search_option(context, option_name, *, widget=None):
sqp = context["sqp"]
option = sqp.options[option_name]
if widget is None:
Expand Down
2 changes: 1 addition & 1 deletion sounds/templatetags/display_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def display_pack_big(context, pack):


@register.inclusion_tag("sounds/display_pack_selectable.html", takes_context=True)
def display_pack_small_selectable(context, pack, selected=False):
def display_pack_small_selectable(context, pack, *, selected=False):
context = context.get("original_context", context) # This is to allow passing context in nested inclusion tags
tvars = display_pack(context, pack, size="small")
tvars.update(
Expand Down
4 changes: 2 additions & 2 deletions sounds/templatetags/display_sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def display_sound_small_no_sound_object_no_bookmark(context, file_data):


@register.inclusion_tag("sounds/display_sound_selectable.html", takes_context=True)
def display_sound_small_selectable(context, sound, selected=False):
def display_sound_small_selectable(context, sound, *, selected=False):
context = context.get("original_context", context) # This is to allow passing context in nested inclusion tags
tvars = display_sound_small_no_bookmark_no_ratings(context, sound)
tvars.update(
Expand All @@ -367,7 +367,7 @@ def display_sound_small_selectable(context, sound, selected=False):


@register.inclusion_tag("sounds/display_sound_with_actions.html", takes_context=True)
def display_sound_small_with_actions(context, sound, is_featured=False):
def display_sound_small_with_actions(context, sound, *, is_featured=False):
"""Display sound with featured and remove action toggles below it."""
context = context.get("original_context", context) # This is to allow passing context in nested inclusion tags
tvars = display_sound_small_no_bookmark_no_ratings(context, sound)
Expand Down
6 changes: 3 additions & 3 deletions templates/accounts/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="container">
<div class="row navbar-space-filler v-spacing-top-6 v-spacing-2 bw-profile__hero">
<div>
{% bw_user_avatar user.profile.locations.avatar.XL.url user.username 100 %}
{% bw_user_avatar user.profile.locations.avatar.XL.url user.username size=100 %}
</div>
<div class="bw-profile__username v-spacing-top-2 {% if user.profile.is_anonymized_user %}v-spacing-3{% endif %}">
<h1>{{ user.username }}</h1>
Expand Down Expand Up @@ -207,11 +207,11 @@ <h5 class="padding-bottom-3">Latest geotags</h5>
<section class="v-spacing-top-4 v-spacing-4">
<h5 class="padding-bottom-3">Most used tags</h5>
{% for tag in tags|add_sizes:"count:0.1:1.0" %}
{% bw_tag tag.name 1 '' tag.browse_url tag.size %}
{% bw_tag tag.name size=1 class_name='' url=tag.browse_url weight=tag.size %}
{% endfor %}
</section>
{% endif %}
{% endwith%}
{% endwith %}
{% endcache %}
</aside>
</div>
Expand Down
14 changes: 7 additions & 7 deletions templates/accounts/account_settings_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ <h1>Account settings</h1>
<aside class="col-md-4 col-extra-left-padding-large-md v-spacing-3 order-md-last">
<ul class="navbar-profile bw-sticky-top padding-0">
<li class="nav-item">
<a class="nav-link {% if activePage == 'profile'%} active {% endif %}" href="{% url 'accounts-edit' %}">Edit profile</a>
<a class="nav-link {% if activePage == 'profile' %} active {% endif %}" href="{% url 'accounts-edit' %}">Edit profile</a>
</li>
<li class="nav-item">
<a class="nav-link {% if activePage == 'email'%} active {% endif %}" href="{% url "accounts-email-reset" %}">Change email</a>
<a class="nav-link {% if activePage == 'email' %} active {% endif %}" href="{% url "accounts-email-reset" %}">Change email</a>
</li>
<li class="nav-item">
<a class="nav-link {% if activePage == 'password'%} active {% endif %}" href="{% url "password_change" %}">Change password</a>
<a class="nav-link {% if activePage == 'password' %} active {% endif %}" href="{% url "password_change" %}">Change password</a>
</li>
<li class="nav-item">
<a class="nav-link {% if activePage == 'notifications'%} active {% endif %}" href="{% url "accounts-email-settings" %}">Email notifications</a>
<a class="nav-link {% if activePage == 'notifications' %} active {% endif %}" href="{% url "accounts-email-settings" %}">Email notifications</a>
</li>
<li class="nav-item">
<a class="nav-link {% if activePage == 'ai_preferences'%} active {% endif %}" href="{% url "accounts-ai-preferences" %}">Gen AI preferences</a>
<a class="nav-link {% if activePage == 'ai_preferences' %} active {% endif %}" href="{% url "accounts-ai-preferences" %}">Gen AI preferences</a>
</li>
<li class="nav-item">
<a class="nav-link {% if activePage == 'api'%} active {% endif %}" href="{% url "access-tokens" %}">Manage API permissions</a>
<a class="nav-link {% if activePage == 'api' %} active {% endif %}" href="{% url "access-tokens" %}">Manage API permissions</a>
</li>
<li class="nav-item">
<a class="nav-link {% if activePage == 'account'%} active {% endif %}" href="{% url "accounts-delete" %}">Delete account</a>
<a class="nav-link {% if activePage == 'account' %} active {% endif %}" href="{% url "accounts-delete" %}">Delete account</a>
</li>
{% if user.profile.has_sounds_with_old_cc_licenses %}
<li class="nav-item text-grey padding-top-4">
Expand Down
4 changes: 2 additions & 2 deletions templates/accounts/admin_delete_confirmation.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% endblock %}

{% block content %}
{% for user_info in users_to_delete%}
{% for user_info in users_to_delete %}
<p>The user "{{user_info.profile.user.username}}" will be
{% if type == 'delete_preserve_sounds' %}
deleted but <b>the sounds will still be available</b>.
Expand Down Expand Up @@ -52,7 +52,7 @@
{% if to_field %}<input type="hidden" name="{{ to_field_var }}" value="{{ to_field }}" />{% endif %}
<input type="hidden" name="confirmation" value="1" />
<input type="submit" value="{% trans "Yes, I'm sure" %}" />
{% for param, value in params %}
{% for param, value in params %}
<input type="hidden" value="{{value}}" name='{{param}}'/>
{% endfor %}
<a href="#" onclick="window.history.back(); return false;" class="button cancel-link">{% trans "No, take me back" %}</a>
Expand Down
10 changes: 5 additions & 5 deletions templates/accounts/attribution.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ <h4 class="v-spacing-top-4">Downloaded on {{group.grouper}}</h4>
<ul>
{% for download_item in group.list %}
{% if download_item.download_type == 'sound' %}
<li>S: <a href="{% absurl 'sound' download_item.sound__user__username download_item.sound_id %}">{{download_item.sound__original_filename }}</a> by <a href="{% absurl 'account' download_item.sound__user__username %}">{{download_item.sound__user__username }}</a> | <span class="text-grey">License: </span>{% if download_item.license__name %}<a class="bw-link--black" href="{{ download_item.license__deed_url }}">{{ download_item.license__name|license_with_version:download_item.license__deed_url}}{% else %}<a class="bw-link--black" href="{{ download_item.sound__license__deed_url }}">{{ download_item.sound__license__name|license_with_version:download_item.sound__license__deed_url }}</a>{% endif %}</li>
<li>S: <a href="{% absurl 'sound' download_item.sound__user__username download_item.sound_id %}">{{download_item.sound__original_filename }}</a> by <a href="{% absurl 'account' download_item.sound__user__username %}">{{download_item.sound__user__username }}</a> | <span class="text-grey">License: </span>{% if download_item.license__name %}<a class="bw-link--black" href="{{ download_item.license__deed_url }}">{{ download_item.license__name|license_with_version:download_item.license__deed_url}}{% else %}<a class="bw-link--black" href="{{ download_item.sound__license__deed_url }}">{{ download_item.sound__license__name|license_with_version:download_item.sound__license__deed_url }}</a>{% endif %}</li>
{% else %}
{% comment %}NOTE: in the line below, even though we're displaying information about a pack download, we use download_item.X where X takes the same names as in the line above when we were displaying
information about sound download. This is beacuse after doing the uninon of the two QuerySets (see accounts.views.attribution) the names of the columns are "unified" and taken from the main QuerySet{% endcomment %}
<li>P: <a href="{% absurl 'pack' download_item.sound__user__username download_item.sound_id %}">{{download_item.sound__original_filename}}</a> by <a href="{% absurl 'account' download_item.sound__user__username %}">{{download_item.sound__user__username}}</a></li>
<li>P: <a href="{% absurl 'pack' download_item.sound__user__username download_item.sound_id %}">{{download_item.sound__original_filename}}</a> by <a href="{% absurl 'account' download_item.sound__user__username %}">{{download_item.sound__user__username}}</a></li>
{% endif %}
{% endfor %}
</ul>
Expand All @@ -45,11 +45,11 @@ <h4 class="v-spacing-top-4">Downloaded on {{group.grouper}}</h4>
{% for download_item in group.list %}
&nbsp;&nbsp;&nbsp;&nbsp;{% filter force_escape %}
{% if download_item.download_type == 'sound' %}
<li>S: <a href="{% absurl 'sound' download_item.sound__user__username download_item.sound_id %}">{{download_item.sound__original_filename }}</a> by <a href="{% absurl 'account' download_item.sound__user__username %}">{{download_item.sound__user__username }}</a> | License: {% if download_item.license__name %}<a href="{{ download_item.license__deed_url }}">{{ download_item.license__name|license_with_version:download_item.license__deed_url}}</a>{% else %}<a href="{{ download_item.sound__license__deed_url }}">{{ download_item.sound__license__name|license_with_version:download_item.sound__license__deed_url }}</a>{% endif %}</li>
<li>S: <a href="{% absurl 'sound' download_item.sound__user__username download_item.sound_id %}">{{download_item.sound__original_filename }}</a> by <a href="{% absurl 'account' download_item.sound__user__username %}">{{download_item.sound__user__username }}</a> | License: {% if download_item.license__name %}<a href="{{ download_item.license__deed_url }}">{{ download_item.license__name|license_with_version:download_item.license__deed_url}}</a>{% else %}<a href="{{ download_item.sound__license__deed_url }}">{{ download_item.sound__license__name|license_with_version:download_item.sound__license__deed_url }}</a>{% endif %}</li>
{% else %}
{% comment %}NOTE: in the line below, even though we're displaying information about a pack download, we use download_item.X where X takes the same names as in the line above when we were displaying
information about sound download. This is beacuse after doing the uninon of the two QuerySets (see accounts.views.attribution) the names of the columns are "unified" and taken from the main QuerySet{% endcomment %}
<li>P: <a href="{% absurl 'pack' download_item.sound__user__username download_item.sound_id %}">{{download_item.sound__name}}</a> by <a href="{% absurl 'account' download_item.sound__user__username %}">{{download_item.sound__user__username}}</a></li>
<li>P: <a href="{% absurl 'pack' download_item.sound__user__username download_item.sound_id %}">{{download_item.sound__name}}</a> by <a href="{% absurl 'account' download_item.sound__user__username %}">{{download_item.sound__user__username}}</a></li>
{% endif %}
{% endfilter %}<br />
{% endfor %}
Expand Down Expand Up @@ -78,6 +78,6 @@ <h4 class="v-spacing-top-4">Downloaded on {{group.grouper}}</h4>

</div>

{% bw_paginator page request "download" %}
{% bw_paginator page request anchor="download" %}

{% endblock %}
12 changes: 6 additions & 6 deletions templates/accounts/charts.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="col-lg-5 offset-lg-1 v-spacing-top-6">
<h5>Most active users in the last weeks</h5>
<div class="v-spacing-top-3">
{% for user_data in recent_most_active_users %}
{% for user_data in recent_most_active_users %}
<div class="row middle">
<div class="col-1 text-grey font-weight-bold">#{{ forloop.counter }}</div>
<div class="col-11">
Expand All @@ -36,7 +36,7 @@ <h5>Most active users in the last weeks</h5>
<div class="col-lg-5 offset-lg-1 v-spacing-top-6">
<h5>Most active new users</h5>
<div class="v-spacing-top-3">
{% for user_data in new_active_users %}
{% for user_data in new_active_users %}
<div class="row middle">
<div class="col-1 text-grey font-weight-bold">#{{ forloop.counter }}</div>
<div class="col-11">
Expand Down Expand Up @@ -65,7 +65,7 @@ <h5>Most active new users</h5>
<div class="col-lg-5 offset-lg-1 v-spacing-top-6">
<h5>Top recent uploaders (by number of sounds)</h5>
<div class="v-spacing-top-3">
{% for user_avatar_url, username, count in top_recent_uploaders_by_count %}
{% for user_avatar_url, username, count in top_recent_uploaders_by_count %}
<div class="row middle">
<div class="col-1 text-grey font-weight-bold">#{{ forloop.counter }}</div>
<div class="col-11">
Expand All @@ -91,7 +91,7 @@ <h5>Top recent uploaders (by number of sounds)</h5>
<div class="col-lg-5 offset-lg-1 v-spacing-top-6">
<h5>Top recent uploaders (by sound length)</h5>
<div class="v-spacing-top-3">
{% for user_avatar_url, username, length in top_recent_uploaders_by_length %}
{% for user_avatar_url, username, length in top_recent_uploaders_by_length %}
<div class="row middle">
<div class="col-1 text-grey font-weight-bold">#{{ forloop.counter }}</div>
<div class="col-11">
Expand Down Expand Up @@ -120,7 +120,7 @@ <h5>Top recent uploaders (by sound length)</h5>
<div class="col-lg-5 offset-lg-1 v-spacing-top-6">
<h5>All time top uploaders (by number of sounds)</h5>
<div class="v-spacing-top-3">
{% for user_avatar_url, username, count in all_time_top_uploaders_by_count %}
{% for user_avatar_url, username, count in all_time_top_uploaders_by_count %}
<div class="row middle">
<div class="col-1 text-grey font-weight-bold">#{{ forloop.counter }}</div>
<div class="col-11">
Expand All @@ -146,7 +146,7 @@ <h5>All time top uploaders (by number of sounds)</h5>
<div class="col-lg-5 offset-lg-1 v-spacing-top-6">
<h5>All time top uploaders (by sound length)</h5>
<div class="v-spacing-top-3">
{% for user_avatar_url, username, length in all_time_top_uploaders_by_length %}
{% for user_avatar_url, username, length in all_time_top_uploaders_by_length %}
<div class="row middle">
<div class="col-1 text-grey font-weight-bold">#{{ forloop.counter }}</div>
<div class="col-11">
Expand Down
Loading
Loading