Skip to content

Commit

Permalink
Merge pull request #275 from VSEScala/mhvis-patch-20231228-locale
Browse files Browse the repository at this point in the history
Change locale formatting in preparation for Django 5.0
  • Loading branch information
mhvis authored Dec 31, 2023
2 parents 08cc428 + 55173d2 commit e8fe22e
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion assets/templates/accounts/user_history_claimed.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% for entry in object_list %}
<tr>
<td>
{{ entry.date }}
{{ entry.date|date:"SHORT_DATE_FORMAT" }}
</td>
<td>
{{ entry.dish }}
Expand Down
2 changes: 1 addition & 1 deletion assets/templates/accounts/user_history_joined.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{% for entry in object_list %}
<tr>
<td>
{{ entry.dining_list.date }}
{{ entry.dining_list.date|date:"SHORT_DATE_FORMAT" }}
</td>
<td>
{{ entry.dining_list.dish }}
Expand Down
2 changes: 1 addition & 1 deletion assets/templates/credit_management/transaction_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<tbody>
{% for tx in object_list %}
<tr>
<td>{{ tx.moment }}</td>
<td>{{ tx.moment|date:"SHORT_DATE_FORMAT" }}</td>
<td>
{% if tx.source == account_self %}
{{ tx.target }}
Expand Down
2 changes: 1 addition & 1 deletion assets/templates/dining_lists/dining_day.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<div class="col-lg-4 mt-3 mt-lg-0 d-flex flex-column justify-content-center align-items-center">
{# During weekend, next Monday is bold. If we don't want that, use 'today' instead of 'upcoming' here #}
<h4 class="my-0 {% if date.upcoming == date %}font-weight-bold{% endif %}">
{{ date|date|capfirst }}
{{ date|date:"l j F"|capfirst }}
</h4>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion assets/templates/dining_lists/dining_slot.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="fixed-bottom bg-light">
<div class="container text-center">
<p class="lead">
{{ dining_list.association }} - {{ dining_list.date }}
{{ dining_list.association }} - {{ dining_list.date|date:"l j F" }}
</p>
<div class="row">
<div class="col px-1">
Expand Down
6 changes: 2 additions & 4 deletions creditmanagement/templatetags/credit_tags.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from django import template
from django.utils.safestring import mark_safe
from django.utils.formats import localize

register = template.Library()


@register.filter
def euro(value):
"""Format for euro values."""
amount = "{:.2f}".format(abs(value))
v = "{}€{}".format("-" if value < 0 else "", amount)
return mark_safe(v)
return f"-€{localize(-value)}" if value < 0 else f"€{localize(value)}"


@register.filter
Expand Down
Empty file added scaladining/formats/__init__.py
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions scaladining/formats/en/formats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Use Dutch style formatting for the English locale."""

# noinspection PyUnresolvedReferences
from django.conf.locale.nl.formats import *
13 changes: 4 additions & 9 deletions scaladining/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,13 @@ def file_parser(value):
# Internationalization

TIME_ZONE = "Europe/Amsterdam"

# Automatic Dutch localization with English language is difficult,
# so we'll set the date formats manually to Dutch style.
DATE_FORMAT = "l j F" # Default: N j, Y
SHORT_DATE_FORMAT = "d-m-Y" # Default: m/d/Y
DATETIME_FORMAT = "N j, Y, G:i" # Default: N j, Y, P
SHORT_DATETIME_FORMAT = "d-m-Y G:i" # Default: m/d/Y P
LANGUAGE_CODE = "en-us"
FORMAT_MODULE_PATH = "scaladining.formats"

USE_I18N = False
USE_L10N = False
USE_TZ = True
USE_THOUSAND_SEPARATOR = True
# USE_TZ is True by default from Django 5.0
USE_TZ = True

AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
Expand Down

0 comments on commit e8fe22e

Please sign in to comment.