Skip to content

Commit

Permalink
AtelierSoude#158 impl currency + ActivityCategory index
Browse files Browse the repository at this point in the history
  • Loading branch information
Skrattoune committed Mar 10, 2022
1 parent 0e06723 commit def1d4f
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 51 deletions.
16 changes: 15 additions & 1 deletion openrepairplatform/event/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import date, datetime, timedelta
import locale

from django.db import models
from django.urls import reverse
Expand Down Expand Up @@ -32,16 +33,25 @@ def get_absolute_url(self):
kwargs={"orga_slug": self.organization.slug},
)

def price_w_currency(self):
return locale.currency(self.price, grouping=True)

def __str__(self):
if self.price > 0:
return f"{self.name} - {self.price}"
return f"{self.name} - {self.price_w_currency}"
return self.name


class ActivityCategory(models.Model):
name = models.CharField(verbose_name=_("Activity type"), max_length=100)
slug = models.SlugField(blank=True)
history = HistoricalRecords()
index = models.PositiveIntegerField(verbose_name='Order',
default=0,
editable=True,
help_text='Order in which the activity types will be displayed')
# The index field must be editable to enable adminsortable2 to work
# for enabling the elements always to be displayed in the right order, even if new ones

def save(self, *args, **kwargs):
self.slug = slugify(self.name)
Expand All @@ -50,6 +60,8 @@ def save(self, *args, **kwargs):
def __str__(self):
return self.name

class Meta:
ordering = ['index', ]

class Activity(models.Model):
name = models.CharField(verbose_name=_("Activity type"), max_length=100)
Expand Down Expand Up @@ -87,6 +99,8 @@ def get_absolute_url(self):
def next_events(self):
return get_future_published_events(self.events)[0:3]

class Meta:
verbose_name_plural = 'Activities'

class Event(models.Model):
WEEKS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h5 class="card-title">{{ condition.name }}</h5>
{{ condition.description | safe }}
<span class="badge badge-pill bg-secondary">
{% if condition.price > 0 %}
{{ condition.price }}
{{ condition.price|currency }}
{% else %}
free
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ <h5><i class="fas fa-info-circle"></i> Informations utiles</h5>
<li class="">
{% if condition.price > 0 %}
<span class="badge badge-pill bg-secondary">
{{ condition.price }}</span>
{{ condition.price|currency }}</span>
{% else %}
{% endif %}
<span>{{ condition.description | safe }}</span>
Expand All @@ -208,21 +208,21 @@ <h5><i class="fas fa-info-circle"></i> Informations utiles</h5>
<small>statut</small>
{% if user_is_member.current_contribution == 0 %}
<small class="text-danger" >Pas à jour</small>
<span class="badge badge-pill bg-danger" >{{user_is_member.current_contribution}}€</span>
<span class="badge badge-pill bg-danger" >{{user_is_member.current_contribution|currency}}</span>
{% elif user_is_member.current_contribution >= organization.advised_fee %}
<small class="text-success" >A jour </small>
<span class="badge badge-pill bg-success" >{{user_is_member.current_contribution}}€</span>
<span class="badge badge-pill bg-success" >{{user_is_member.current_contribution|currency}}</span>
{% else %}
<small class="text-warning" >Incomplet </small>
<span class="badge badge-pill bg-warning" >{{user_is_member.current_contribution}}€</span>
<span class="badge badge-pill bg-warning" >{{user_is_member.current_contribution|currency}}</span>
{% endif %}
{% endif %}
</p>
<p>{{ event.organization.get_membership_system_display }} Elle
{% if event.organization.advised_fee == event.organization.min_fee %}
est de {{event.organization.min_fee}}€
est de {{event.organization.min_fee|currency}}
{% else %}
va de {{event.organization.min_fee}}€ à {{event.organization.advised_fee}}€
va de {{event.organization.min_fee|currency}} à {{event.organization.advised_fee|currency}}
{% endif %}
{% if event.organization.membership_url %}
Vous pouvez
Expand Down Expand Up @@ -303,7 +303,7 @@ <h4 class="text-white" id="book_show" onclick="display_book()"><i class="fas fa
<i class="far fa-check-circle fa-1x text-success"></i>
{% if condition.price > 0 %}
<span class="badge badge-pill bg-secondary">
{{ condition.price }}</span>
{{ condition.price|currency }}</span>
{% endif %}
<span>{{ condition.description | safe }}</span>
</li>
Expand Down Expand Up @@ -339,21 +339,21 @@ <h4 class="text-white" id="book_show" onclick="display_book()"><i class="fas fa
<small>status</small>
{% if user_is_member.current_contribution == 0 %}
<small class="text-danger" >Pas à jour</small>
<span class="badge badge-pill bg-danger" >{{user_is_member.current_contribution}}€</span>
<span class="badge badge-pill bg-danger" >{{user_is_member.current_contribution|currency}}</span>
{% elif user_is_member.current_contribution >= organization.advised_fee %}
<small class="text-success" >A jour </small>
<span class="badge badge-pill bg-success" >{{user_is_member.current_contribution}}€</span>
<span class="badge badge-pill bg-success" >{{user_is_member.current_contribution|currency}}</span>
{% else %}
<small class="text-warning" >Incomplet </small>
<span class="badge badge-pill bg-warning" >{{user_is_member.current_contribution}}€</span>
<span class="badge badge-pill bg-warning" >{{user_is_member.current_contribution|currency}}</span>
{% endif %}
{% endif %}
</p>
<p>{{ event.organization.get_membership_system_display }} Elle
{% if event.organization.advised_fee == event.organization.min_fee %}
est de {{event.organization.min_fee}}€
est de {{event.organization.min_fee|currency}}
{% else %}
va de {{event.organization.min_fee}}€ à {{event.organization.advised_fee}}€ .
va de {{event.organization.min_fee|currency}} à {{event.organization.advised_fee|currency}} .
{% endif %}
{% if event.organization.membership_url %}
<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ <h6 class="card-subtitle mb-2 text-muted">{{ user.email }}</h6>
{% if membership %}
{% if membership.current_contribution == 0 %}
<span class="text-danger" >Pas de cotisation</span>
<span class="badge badge-pill bg-danger" >0€</span>
<span class="badge badge-pill bg-danger" >{{0|currency}}</span>
{% elif membership.current_contribution >= event.organization.advised_fee %}
<span class="text-success" >A jour </span>
<span class="badge badge-pill bg-success" >{{membership.current_contribution}}€/{{event.organization.advised_fee}}€</span>
<span class="badge badge-pill bg-success" >{{membership.current_contribution|currency}}/{{event.organization.advised_fee|currency}}</span>
{% else %}
<span class="text-warning" >Incomplet</span>
<span class="badge badge-pill bg-warning" >{{membership.current_contribution}}€</span>
<span class="badge badge-pill bg-warning" >{{membership.current_contribution|currency}}</span>
{% endif %}
{% else %}
Non membre
Expand All @@ -72,7 +72,7 @@ <h6 class="card-subtitle mb-2 text-muted">{{ user.email }}</h6>
{% if fees %}
{% for fee in fees %}
<span class="badge badge-pill badge-light pe-2 m-2">
{{ fee.amount }}
{{ fee.amount|currency }}
{{ fee.get_payment_display }}
<form class="d-inline" action="{% url 'user:fee_delete' fee.pk %}" method="post">
{% csrf_token %}
Expand All @@ -87,13 +87,13 @@ <h6 class="card-subtitle mb-2 text-muted">{{ user.email }}</h6>
<p><b>Participation</b>
<br>
{% if participation.amount == 0 or not participation.amount %}
<span class="text-danger">0€</span>
<span class="text-danger">{{0|currency}}</span>
{% elif participation.amount >= condition_prices %}
<span class="text-success">{{participation.amount}}€</span>
<span class="text-success">{{participation.amount|currency}}</span>
{% else %}
<span class="text-warning">{{participation.amount}}€</span>
<span class="text-warning">{{participation.amount|currency}}</span>
{% endif %}
/ {{condition_prices }}
/ {{condition_prices|currency }}
</p>
{% if participation %}
<button class="btn btn-light btn-sm" data-toggle="modal" data-target="#participation-{{ user.pk }}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h5 class="text-muted">
<h6 class="text-muted"><i class="fas fa-tools"></i> Cet événement gère les réparations</h6>
{% endif %}
{% if event.booking == True and event.external == False %}
<h3>Total perçus: <b>{{ total_fees }} cotisations {% if event.conditions %} / {{total_participations}}€ participations {% endif %}</b></h3>
<h3>Total perçus: <b>{{ total_fees|currency }} cotisations {% if event.conditions %} / {{total_participations|currency}} participations {% endif %}</b></h3>
{% endif %}
</div>
{% with organizers=event.organizers.all %}
Expand Down
2 changes: 1 addition & 1 deletion openrepairplatform/event/templates/event/mail/book.html
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
<li style="font-size: 14px; line-height: 1.5; mso-line-height-alt: 21px;">
{% if condition.price > 0 %}
<span>
{{ condition.price }}</span>
{{ condition.price|currency }}</span>
{% else %}
{% endif %}
{{ condition.description | safe }}
Expand Down
2 changes: 1 addition & 1 deletion openrepairplatform/event/templates/event/mail/book.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Informations pratiques:

{% for condition in conditions %}
{% if condition.price > 0 %}
{{ condition.price }}
{{ condition.price|currency }}
{% else %}
{% endif %}
{{ condition.description | safe }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
<li style="font-size: 14px; line-height: 1.5; mso-line-height-alt: 21px;">
{% if condition.price > 0 %}
<span>
{{ condition.price }}</span>
{{ condition.price|currency }}</span>
{% else %}
{% endif %}
{{ condition.description | safe }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Informations pratiques:

{% for condition in conditions %}
{% if condition.price > 0 %}
{{ condition.price }}
{{ condition.price|currency }}
{% else %}
{% endif %}
{{ condition.description | safe }}
Expand Down
10 changes: 5 additions & 5 deletions openrepairplatform/event/templates/event/modal_more_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ <h5 class="modal-title">
statut
{% if membership.current_contribution == 0 %}
<span class="text-danger" >Pas à jour</span>
<span class="badge badge-pill bg-danger" >{{membership.current_contribution}}€</span>
<span class="badge badge-pill bg-danger" >{{membership.current_contribution|currency}}</span>
{% elif membership.current_contribution >= event.organization.advised_fee %}
<span class="text-success" >A jour </span>
<span class="badge badge-pill bg-success" >{{membership.current_contribution}}€</span>
<span class="badge badge-pill bg-success" >{{membership.current_contribution|currency}}</span>
{% else %}
<span class="text-warning" >Incomplet </span>
<span class="badge badge-pill bg-warning" >{{membership.current_contribution}}€</span>
<span class="badge badge-pill bg-warning" >{{membership.current_contribution|currency}}</span>
{% endif %}
</p>
{% else %}
Expand All @@ -34,9 +34,9 @@ <h5 class="modal-title">
{% endif %}
<p>{{ event.organization.get_membership_system_display }} Elle
{% if event.organization.advised_fee == event.organization.min_fee %}
est de {{event.organization.min_fee}}€
est de {{event.organization.min_fee|currency}}
{% else %}
va de {{event.organization.min_fee}}€ à {{event.organization.advised_fee}}€
va de {{event.organization.min_fee|currency}} à {{event.organization.advised_fee|currency}}
{% endif %}
</p>
</b>
Expand Down
8 changes: 8 additions & 0 deletions openrepairplatform/event/templatetags/app_filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django import template
from django.core import signing

import locale
# locale.setlocale(locale.LC_ALL, '')

from openrepairplatform.user.models import Fee

register = template.Library()
Expand Down Expand Up @@ -63,3 +66,8 @@ def query_transform(request, **kwargs):
@register.simple_tag
def sum_conditions(conditions):
return sum(condition.price for condition in conditions)


@register.filter()
def currency(value):
return locale.currency(value, grouping=True)
12 changes: 11 additions & 1 deletion openrepairplatform/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = "fr-fr"
COUNTRY = 'FR' #'CH', 'US'
LANGUAGE_CODE = f"fr-{COUNTRY}" # fr_fr, fr_CH

TIME_ZONE = "Europe/Paris"

Expand All @@ -128,6 +129,15 @@
USE_THOUSAND_SEPARATOR = True



CURRENCIES = {
'FR' : ['EUR', '€'],
'CH' : ['CHF', 'CHF'],
'US' : ['USD', '$'],
}
CURRENCY_DISPLAY = CURRENCIES[COUNTRY][1]
CURRENCY_CODE = CURRENCIES[COUNTRY][0]

STATICFILES_DIRS = [join(PROJECT_DIR, "static")]

STATIC_ROOT = join(BASE_DIR, "static")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<h5 class="card-header">{{ condition.fields.name }}</h5>
<div class="card-body">
<p class="card-text ms-2" v-html="condition.fields.description"></p>
<b v-if="condition.price">{{ condition.fields.price }}</b>
<b v-if="condition.price">{{ condition.fields.price|currency }}</b>
</div>
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<h5 class="card-header">{{ condition.name }}</h5>
<div class="card-body">
<p class="card-text ms-2" v-html="condition.description"></p>
<b v-if="condition.price > 0">{{ condition.price }}</b>
<b v-if="condition.price > 0">{{ condition.price|currency }}</b>
</div>
</div>
</section>
Expand Down
6 changes: 3 additions & 3 deletions openrepairplatform/templates/extra_column_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
{% elif column == "membership_status" %}
{% if record.current_contribution == 0 %}
<span class="text-danger" >Pas de cotisation</span>
<span class="badge badge-pill bg-danger" >0€</span>
<span class="badge badge-pill bg-danger" >{{0|currency}}</span>
{% elif record.current_contribution >= record.organization.advised_fee %}
<span class="text-success" >A jour </span>
<span class="badge badge-pill bg-success" >{{record.current_contribution}}€/{{record.organization.advised_fee}}€</span>
<span class="badge badge-pill bg-success" >{{record.current_contribution|currency}}/{{record.organization.advised_fee|currency}}</span>
{% else %}
<span class="text-warning" >Incomplet</span>
<span class="badge badge-pill bg-warning" >{{record.current_contribution}}€</span>
<span class="badge badge-pill bg-warning" >{{record.current_contribution|currency}}</span>
{% endif %}

{% elif column == "member_update" %}
Expand Down
2 changes: 1 addition & 1 deletion openrepairplatform/templates/organization_fees.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h2 class="text-center pt-2">Cotisations</h2>
{% endif %}
</div>
</section>
<h4 class="text-center w-100">Total = {{total_fees}} </h4>
<h4 class="text-center w-100">Total = {{total_fees|currency}} </h4>
<section class="box-shadow mb-5">
<span class="">Télécharger le résultat :
<a class="btn btn-success btn-sm" href="{% querystring '_export'='csv' %}">CSV</a>
Expand Down
2 changes: 1 addition & 1 deletion openrepairplatform/templates/organization_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ <h4 class="mt-2">Informations
{% if organization.min_fee %}
{{ organization.min_fee }} -
{% endif %}
{{ organization.advised_fee }}
{{ organization.advised_fee|currency }}
</span>
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ user }},

<p>
Tu es désormais membre de {{organization}}, depuis le {{date}}. Tu as donné {{paid}}€ pour ta première adhésion.
Tu es désormais membre de {{organization}}, depuis le {{date}}. Tu as donné {{paid|currency}} pour ta première adhésion.
</p>
2 changes: 1 addition & 1 deletion openrepairplatform/user/templates/user/mail/membership.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ user }},

Tu es désormais membre de {{organization}}, depuis le {{date}}. Tu as donné {{paid}}€ pour ta première adhésion.
Tu es désormais membre de {{organization}}, depuis le {{date}}. Tu as donné {{paid|currency}} pour ta première adhésion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ <h5 class="modal-title">
<p>
<b>Note:</b>
La contribution minimale pour cette organisation est de
<span class="badge badge-pill bg-secondary">{{ object.min_fee }}</span>
<span class="badge badge-pill bg-secondary">{{ object.min_fee|currency }}</span>
et la contribution totale conseillée est de
<span class="badge badge-pill bg-success">{{ object.advised_fee }}</span>
<span class="badge badge-pill bg-success">{{ object.advised_fee|currency }}</span>
{% if anonymous_user and anonymous_user.first_name %}
<br>
{% filter_orga queryset=anonymous_user.memberships organization=object as membership %}
{% if membership %}
{{ anonymous_user }} a payé <span class="badge badge-pill bg-primary">{{ membership.current_contribution }}</span> depuis le {{ membership.first_payment|date:"d F Y" }}
{{ anonymous_user }} a payé <span class="badge badge-pill bg-primary">{{ membership.current_contribution|currency }}</span> depuis le {{ membership.first_payment|date:"d F Y" }}
{% else %}
{{ anonymous_user }} n'a pas encore contribué pour <b>{{ object }}</b>
{% endif %}
Expand Down
Loading

0 comments on commit def1d4f

Please sign in to comment.