Merge branch 'thubrecht/traduction' into 'master'

Thubrecht/traduction

See merge request klub-dev-ens/annuaire!14
This commit is contained in:
Martin Pepin 2021-02-04 21:17:45 +01:00
commit 976fb86c0a
15 changed files with 463 additions and 77 deletions

View file

@ -63,6 +63,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
@ -131,6 +132,13 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = "fr-fr"
LANGUAGES = [
("fr", "Français"),
("en", "English"),
]
LOCALE_PATHS = [os.path.join(BASE_DIR, "locale")]
TIME_ZONE = "UTC"
USE_I18N = True

View file

@ -21,12 +21,11 @@ from fiches.views import BirthdayView, HomeView
import django_cas_ng.views as cas_views
urlpatterns = [
path('admin/', admin.site.urls),
path('fiche/', include('fiches.urls')),
path('', HomeView.as_view(), name='home'),
path('birthday', BirthdayView.as_view(), name='birthday'),
path('accounts/login/', cas_views.LoginView.as_view(), name='cas_ng_login'),
path('logout', cas_views.LogoutView.as_view(), name='cas_ng_logout'),
path("", include("fiches.urls")),
path("admin/", admin.site.urls),
path("accounts/login/", cas_views.LoginView.as_view(), name="cas_ng_login"),
path("logout", cas_views.LogoutView.as_view(), name="cas_ng_logout"),
path("i18n/", include("django.conf.urls.i18n")),
]
if settings.DEBUG:

View file

@ -1,6 +1,8 @@
from django import forms
from django.forms.models import inlineformset_factory
from fiches.models import Profile, Department, Phone, Social, Mail, Address
from django.utils.translation import gettext_lazy as _
from fiches.models import Address, Department, Mail, Phone, Profile, Social
class ProfileForm(forms.ModelForm):
@ -10,8 +12,8 @@ class ProfileForm(forms.ModelForm):
class SearchForm(forms.Form):
name = forms.CharField(label="Nom/Surnom", max_length=1023, required=False)
year = forms.IntegerField(label="Promotion", required=False)
name = forms.CharField(label=_("Nom/Surnom"), max_length=1023, required=False)
year = forms.IntegerField(label=_("Promotion"), required=False)
department = forms.ModelMultipleChoiceField(
queryset=Department.objects.all(), required=False
)
@ -23,7 +25,7 @@ class SearchForm(forms.Form):
and not cleaned_data["year"]
and not cleaned_data["department"]
):
raise forms.ValidationError(("Tous les champs sont vides"), code="invalid")
raise forms.ValidationError(_("Tous les champs sont vides"), code="invalid")
PhoneFormSet = inlineformset_factory(Profile, Phone, exclude=[])

View file

@ -1,7 +1,7 @@
from django.db import models
from django.core.validators import MinValueValidator
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.core.validators import MinValueValidator
from django.db import models
from django.utils.translation import gettext_lazy as _
class Profile(models.Model):

View file

@ -147,11 +147,16 @@ body {
text-align: center;
}
#language_switch .language {
margin: 0;
padding: 0;
display: inline-block;
background: none;
border: none;
color: #DFDFDF;
}
#language_switch .language:hover {
color: #FFDC00;
cursor: pointer;
}
#language_switch .language::after,
#language_switch .current-language::after {
@ -523,3 +528,5 @@ body {
display: block;
text-align: center;
}
/*# sourceMappingURL=annuaire.css.map */

View file

@ -46,7 +46,7 @@ body {
#header {
margin: 0;
}
#main {
margin: 0;
}

View file

@ -81,13 +81,18 @@ $account-area-height: 120px;
text-align: center;
.language {
margin: 0;
padding: 0;
display: inline-block;
background: none;
border: none;
// text-decoration: underline;
color: colors.$page-text-secondary;
}
.language:hover {
color: colors.$main-menu-link;
cursor: pointer;
}
.language::after,
@ -161,4 +166,4 @@ $account-area-height: 120px;
.clipper {
font-family: fonts.$monospace-fonts;
}
}
}

View file

@ -1,4 +1,4 @@
@use "common";
@use "header";
@use "content";
@use "footer";
@use "footer";

View file

@ -17,13 +17,17 @@
<div id="aside">
<div id="menu">
<div id="language_switch">
<a class="language french {% if get_current_language == "fr" %}current-language{% endif %}" href="/fr{{ request.get_full_path|slice:'3:' }}">Français</a>
<a class="language english {% if get_current_language == "en" %}current-language{% endif %}" href="/en{{ request.get_full_path|slice:'3:' }}">English</a>
<form action="{% url 'set_language' %}" method="post">
{% csrf_token %}
{% get_current_language as lang %}
<input name="next" type="hidden" value="{{ request.get_full_path }}">
<button class="language {% if lang == "fr" %}current-language{% endif %}" name="language" value="fr">Français</button><button class="language {% if lang == "en" %}current-language{% endif %}" name="language" value="en">English</button>
</form>
</div>
<form id="search-area" method="post" action='{% url "home" %}'>
{% csrf_token %}
<input id="id_name" name="name" type="search" placeholder="Recherche Rapide">
<input id="id_name" name="name" type="search" placeholder="{% trans "Recherche Rapide" %}">
<button type="submit">{% trans "Rechercher" %}</button>
</form>
@ -75,4 +79,5 @@
</div>
</body>
{% block extra_js %}{% endblock %}
</html>

View file

@ -63,39 +63,23 @@
<label for="id_thurne">{% trans "Thurne :" %}</label>
{{ form.thurne }}
</div>
<div
class="form-entry multi-entry"
data-type-placeholder="{% trans "Personnel" %}"
data-value-placeholder="{% trans "0612345678" %}"
>
<label for="id_phone">{% trans "Numéro(s) de téléphone :" %}</label>
<div class="form-entry multi-entry" data-type-placeholder="{% trans "Personnel" %}" data-value-placeholder="{% trans "0612345678" %}">
<label for="id_phone">{% trans "Numéro(s) de téléphone :" %}</label>
{% trans "Ajouter un numéro" as add_number %}
{% include "fiches/multientry.html" with formset=phone_form new_entry_text=add_number %}
</div>
<div
class="form-entry multi-entry"
data-type-placeholder="{% trans "InstaTok" %}"
data-value-placeholder="{% trans "mon_profil_instatok" %}"
>
<div class="form-entry multi-entry" data-type-placeholder="{% trans "InstaTok" %}" data-value-placeholder="{% trans "mon_profil_instatok" %}">
<label for="id_social">{% trans "Réseaux sociaux :" %}</label>
{% trans "Ajouter un réseau social" as add_social %}
{% include "fiches/multientry.html" with formset=social_form new_entry_text=add_social %}
</div>
<div
class="form-entry multi-entry"
data-type-placeholder="{% trans "Professionelle" %}"
data-value-placeholder="{% trans "moi@ens.fr" %}"
>
<label for="id_mail">{% trans "Mail(s):" %}</label>
<div class="form-entry multi-entry" data-type-placeholder="{% trans "Professionelle" %}" data-value-placeholder="{% trans "moi@ens.fr" %}">
<label for="id_mail">{% trans "Mail(s) :" %}</label>
{% trans "Ajouter un email" as add_mail %}
{% include "fiches/multientry.html" with formset=mail_form new_entry_text=add_mail %}
</div>
<div
class="form-entry multi-entry"
data-type-placeholder="{% trans "Bureau" %}"
data-value-placeholder="{% trans "45 rue d'Ulm" %}"
>
<label for="id_address">{% trans "Adresse(s):" %}</label>
<div class="form-entry multi-entry" data-type-placeholder="{% trans "Bureau" %}" data-value-placeholder="{% trans "45 rue d'Ulm" %}">
<label for="id_address">{% trans "Adresse(s) :" %}</label>
{% trans "Ajouter une adresse" as add_address %}
{% include "fiches/multientry.html" with formset=address_form new_entry_text=add_address %}
</div>
@ -120,5 +104,5 @@
{% endblock %}
{% block extra_js %}
<script type="text/javascript" src="{% static "fiches/js/forms.js" %}"></script>
<script type="text/javascript" src="{% static "fiches/js/forms.js" %}"></script>
{% endblock %}

View file

@ -14,7 +14,7 @@
<label for="id_year">{% trans "Promotion :" %}</label>
{{ form.year }}
<label for="id_department">{% trans "Department :" %}</label>
<label for="id_department">{% trans "Départment :" %}</label>
{{ form.department }}
<input type="submit" value="{% trans "Recherche" %}">
</form>

View file

@ -2,6 +2,8 @@ from django.urls import path
from . import views
urlpatterns = [
path("edit", views.EditView.as_view(), name="fiche_modif"),
path("<user>", views.FicheView.as_view(), name="fiche"),
path("", views.HomeView.as_view(), name="home"),
path("fiche/edit", views.EditView.as_view(), name="fiche_modif"),
path("fiche/<user>", views.FicheView.as_view(), name="fiche"),
path("birthday", views.BirthdayView.as_view(), name="birthday"),
]

View file

@ -2,7 +2,14 @@ from django.shortcuts import render
from django.shortcuts import get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from fiches.models import Profile, Phone, Social, Mail, Address
from fiches.forms import ProfileForm, SearchForm, PhoneFormSet, SocialFormSet, MailFormSet, AddressFormSet
from fiches.forms import (
ProfileForm,
SearchForm,
PhoneFormSet,
SocialFormSet,
MailFormSet,
AddressFormSet,
)
from django.forms import formset_factory
from django.forms.models import model_to_dict
from django.urls import reverse
@ -42,11 +49,14 @@ class EditView(UpdateView):
mail_form = MailFormSet(instance=self.object)
address_form = AddressFormSet(instance=self.object)
return self.render_to_response(
self.get_context_data(form=form,
phone_form=phone_form,
social_form=social_form,
mail_form=mail_form,
address_form=address_form))
self.get_context_data(
form=form,
phone_form=phone_form,
social_form=social_form,
mail_form=mail_form,
address_form=address_form,
)
)
def post(self, request, *args, **kwargs):
self.object = self.get_object()
@ -56,12 +66,21 @@ class EditView(UpdateView):
social_form = SocialFormSet(self.request.POST, instance=self.object)
mail_form = MailFormSet(self.request.POST, instance=self.object)
address_form = AddressFormSet(self.request.POST, instance=self.object)
if (form.is_valid() and phone_form.is_valid() and social_form.is_valid()
and mail_form.is_valid() and address_form.is_valid()):
return self.form_valid(form, phone_form, social_form, mail_form, address_form)
if (
form.is_valid()
and phone_form.is_valid()
and social_form.is_valid()
and mail_form.is_valid()
and address_form.is_valid()
):
return self.form_valid(
form, phone_form, social_form, mail_form, address_form
)
else:
return self.form_invalid(form, phone_form, social_form, mail_form, address_form)
return self.form_invalid(
form, phone_form, social_form, mail_form, address_form
)
def form_valid(self, form, phone_form, social_form, mail_form, address_form):
self.object = form.save()
phone_form.save()
@ -69,21 +88,26 @@ class EditView(UpdateView):
mail_form.save()
address_form.save()
send_mail(
"Fiche annuaire modifée",
render_to_string("fiches/mail/mail_modif.txt", {"profile": self.get_object()}),
"klub-dev@ens.psl.eu",
["{}@clipper.ens.psl.eu".format(self.get_object().user.username)],
fail_silently=False,
)
"Fiche annuaire modifée",
render_to_string(
"fiches/mail/mail_modif.txt", {"profile": self.get_object()}
),
"klub-dev@ens.psl.eu",
["{}@clipper.ens.psl.eu".format(self.get_object().user.username)],
fail_silently=False,
)
return HttpResponseRedirect(self.get_success_url())
def form_invalid(self, form, phone_form, social_form, mail_form, address_form):
return self.render_to_response(
self.get_context_data(form=form,
phone_form=phone_form,
social_form=social_form,
mail_form=mail_form,
address_form=address_form))
self.get_context_data(
form=form,
phone_form=phone_form,
social_form=social_form,
mail_form=mail_form,
address_form=address_form,
)
)
def get_object(self):
return self.request.user.profile
@ -100,9 +124,9 @@ class HomeView(FormView):
def form_valid(self, form):
result = Profile.objects.filter(
Q(full_name__icontains=form.cleaned_data["name"])
| Q(nickname__icontains=form.cleaned_data["name"])
)
Q(full_name__icontains=form.cleaned_data["name"])
| Q(nickname__icontains=form.cleaned_data["name"])
)
return self.render_to_response(self.get_context_data(result=result))
@ -111,19 +135,19 @@ class BirthdayView(ListView):
model = Profile
template_name = "fiches/birthday.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
today = timezone.now()
context['result'] = list(
Profile.objects.filter(birth_date__day=today.day, birth_date__month=today.month)
context["result"] = list(
Profile.objects.filter(
birth_date__day=today.day, birth_date__month=today.month
)
)
for i in range(1, 7):
today = today + timedelta(days=1)
context['result'] += list(
context["result"] += list(
Profile.objects.filter(
birth_date__day=today.day, birth_date__month=today.month
)
)
return context
return context

Binary file not shown.

View file

@ -0,0 +1,350 @@
# Annuaire translations
# Copyright (C) 2021 Klub Dev ENS
# This file is distributed under the same license as the annuaire package.
# Klub Dev ENS <klub-dev@ens.fr>, 2021.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-28 00:03+0000\n"
"PO-Revision-Date: 2021-02-04 21:15+0100\n"
"Last-Translator: Tom Hubrecht <tom.hubrecht@ens.fr>\n"
"Language-Team: \n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.4.1\n"
#: fiches/forms.py:15
msgid "Nom/Surnom"
msgstr "Name/Nickname"
#: fiches/forms.py:16
msgid "Promotion"
msgstr "Entry year"
#: fiches/forms.py:28
msgid "Tous les champs sont vides"
msgstr "All fields are empty"
#: fiches/models.py:11
msgid "utilisateur"
msgstr "user"
#: fiches/models.py:14
msgid "nom"
msgstr "name"
#: fiches/models.py:15
msgid "surnom"
msgstr "nickname"
#: fiches/models.py:17
msgid "pronom(s) utilisé(s)"
msgstr "pronoun(s)"
#: fiches/models.py:20
msgid "photo"
msgstr "photo"
#: fiches/models.py:22
msgid "département"
msgstr "department"
#: fiches/models.py:24
msgid "promotion"
msgstr "entry year"
#: fiches/models.py:27
msgid "date de naissance"
msgstr "birth date"
#: fiches/models.py:29
msgid "thurne"
msgstr "room"
#: fiches/models.py:30
msgid "champ libre"
msgstr "free space"
#: fiches/models.py:32
msgid "apparaître sur l'annuaire papier ?"
msgstr "appear on the paper directory?"
#: fiches/models.py:35
msgid "conserver la fiche annuaire ?"
msgstr "keep the directory record?"
#: fiches/models.py:47
msgid "nom du département"
msgstr "department name"
#: fiches/models.py:56 fiches/models.py:67 fiches/models.py:78
#: fiches/models.py:89
msgid "profil"
msgstr "profile"
#: fiches/models.py:58 fiches/models.py:69 fiches/models.py:80
#: fiches/models.py:91
msgid "type"
msgstr "type"
#: fiches/models.py:59
msgid "numéro"
msgstr "number"
#: fiches/models.py:70
msgid "contenu"
msgstr "content"
#: fiches/models.py:81
msgid "adresse mail"
msgstr "e-mail"
#: fiches/models.py:92
msgid "adresse"
msgstr "address"
#: fiches/templates/fiches/base.html:10 fiches/templates/fiches/base.html:35
msgid "Annuaire des élèves de l'ENS"
msgstr "ENS student directory"
#: fiches/templates/fiches/base.html:30
msgid "Recherche Rapide"
msgstr "Quick Search"
#: fiches/templates/fiches/base.html:31
msgid "Rechercher"
msgstr "Search"
#: fiches/templates/fiches/base.html:41
msgid "Accueil"
msgstr "Home"
#: fiches/templates/fiches/base.html:42
msgid "Modifier sa fiche d'annuaire"
msgstr "Edit your directory record"
#: fiches/templates/fiches/base.html:44
msgid "Consulter sa fiche d'annuaire"
msgstr "View your directory record"
#: fiches/templates/fiches/base.html:46
msgid "Anniversaires à venir"
msgstr "Upcoming birthdays"
#: fiches/templates/fiches/base.html:52
#, python-format
msgid "Connecté en tant que <span class=\"clipper\">%(user)s</span>"
msgstr "Connected as <span class=\"clipper\">%(user)s</span>"
#: fiches/templates/fiches/base.html:53
msgid "Se déconnecter"
msgstr "Log out"
#: fiches/templates/fiches/base.html:55
msgid "Se connecter"
msgstr "Log in"
#: fiches/templates/fiches/base.html:71
msgid "Crée par KDENS &middot; Propulsé par Django"
msgstr "Created by KDENS &middot; Powered by Django"
#: fiches/templates/fiches/base.html:75
msgid "Page des élèves"
msgstr "Students' page"
#: fiches/templates/fiches/base.html:76
msgid "Contacter l'équipe annuaire"
msgstr "Contact the directory team"
#: fiches/templates/fiches/birthday.html:8
msgid "Anniversaires"
msgstr "Birthdays"
#: fiches/templates/fiches/birthday.html:15
msgid "ans"
msgstr "years"
#: fiches/templates/fiches/fiche.html:25
msgid "Pronom(s) utilisé(s)"
msgstr "Pronoun(s)"
#: fiches/templates/fiches/fiche.html:32
msgid "Département"
msgstr "Department"
#: fiches/templates/fiches/fiche.html:39
msgid "Date de naissance"
msgstr "Birth date"
#: fiches/templates/fiches/fiche.html:46
msgid "Thurne"
msgstr "Room"
#: fiches/templates/fiches/fiche.html:53
msgid "Téléphone"
msgstr "Phone number"
#: fiches/templates/fiches/fiche.html:64
msgid "Réseau social,Réseaux sociaux"
msgstr "Social network,Social networks"
#: fiches/templates/fiches/fiche.html:75
msgid "Mail,Mails"
msgstr "E-mail,E-mails"
#: fiches/templates/fiches/fiche.html:86
msgid "Adresse,Adresses"
msgstr "Address,Addresses"
#: fiches/templates/fiches/fiche.html:99
msgid "Champ libre"
msgstr "Free space"
#: fiches/templates/fiches/fiches_modif.html:8
msgid "Modifier ma page d'annuaire"
msgstr "Edit my directory record"
#: fiches/templates/fiches/fiches_modif.html:13
msgid "Nom :"
msgstr "Name:"
#: fiches/templates/fiches/fiches_modif.html:17
msgid "Surnom :"
msgstr "Nickname:"
#: fiches/templates/fiches/fiches_modif.html:21
msgid "Pronom(s) utilisé(s) :"
msgstr "Pronoun(s):"
#: fiches/templates/fiches/fiches_modif.html:25
msgid "Photo :"
msgstr "Photo:"
#: fiches/templates/fiches/fiches_modif.html:39
msgid "Effacer (cochez la case) :"
msgstr "Delete (check the box):"
#: fiches/templates/fiches/fiches_modif.html:44
msgid "Nouvelle photo :"
msgstr "New photo:"
#: fiches/templates/fiches/fiches_modif.html:51
msgid "Département :"
msgstr "Department:"
#: fiches/templates/fiches/fiches_modif.html:55
#: fiches/templates/fiches/home.html:14
msgid "Promotion :"
msgstr "Entry year:"
#: fiches/templates/fiches/fiches_modif.html:59
msgid "Date de naissance :"
msgstr "Birth date:"
#: fiches/templates/fiches/fiches_modif.html:63
msgid "Thurne :"
msgstr "Room :"
#: fiches/templates/fiches/fiches_modif.html:66
msgid "Personnel"
msgstr "Private"
#: fiches/templates/fiches/fiches_modif.html:66
msgid "0612345678"
msgstr "0612345678"
#: fiches/templates/fiches/fiches_modif.html:67
msgid "Numéro(s) de téléphone :"
msgstr "Phone number(s):"
#: fiches/templates/fiches/fiches_modif.html:68
msgid "Ajouter un numéro"
msgstr "Add a phone number"
#: fiches/templates/fiches/fiches_modif.html:71
msgid "InstaTok"
msgstr "InstaTok"
#: fiches/templates/fiches/fiches_modif.html:71
msgid "mon_profil_instatok"
msgstr "my_instatok_profile"
#: fiches/templates/fiches/fiches_modif.html:72
msgid "Réseaux sociaux :"
msgstr "Social networks:"
#: fiches/templates/fiches/fiches_modif.html:73
msgid "Ajouter un réseau social"
msgstr "Add a social network"
#: fiches/templates/fiches/fiches_modif.html:76
msgid "Professionelle"
msgstr "Professional"
#: fiches/templates/fiches/fiches_modif.html:76
msgid "moi@ens.fr"
msgstr "me@ens.fr"
#: fiches/templates/fiches/fiches_modif.html:77
msgid "Mail(s) :"
msgstr "E-mail(s):"
#: fiches/templates/fiches/fiches_modif.html:78
msgid "Ajouter un email"
msgstr "Add an e-mail"
#: fiches/templates/fiches/fiches_modif.html:81
msgid "Bureau"
msgstr "Office"
#: fiches/templates/fiches/fiches_modif.html:81
msgid "45 rue d'Ulm"
msgstr "45 rue d'Ulm"
#: fiches/templates/fiches/fiches_modif.html:82
msgid "Adresse(s) :"
msgstr "Address(es):"
#: fiches/templates/fiches/fiches_modif.html:83
msgid "Ajouter une adresse"
msgstr "Add an address"
#: fiches/templates/fiches/fiches_modif.html:87
msgid "Champ libre :"
msgstr "Free space:"
#: fiches/templates/fiches/fiches_modif.html:93
msgid "Apparaître sur l'annuaire papier ?"
msgstr "Appear on the paper directory?"
#: fiches/templates/fiches/fiches_modif.html:97
msgid "Conserver la fiche annuaire ?"
msgstr "Keep the directory record?"
#: fiches/templates/fiches/fiches_modif.html:100
msgid "Enregistrer"
msgstr "Save"
#: fiches/templates/fiches/home.html:8
msgid "Chercher quelqu'un·e dans l'annuaire"
msgstr "Search for someone in the directory"
#: fiches/templates/fiches/home.html:11
msgid "Nom/Surnom :"
msgstr "Name/Nickname:"
#: fiches/templates/fiches/home.html:17
msgid "Départment :"
msgstr "Department:"
#: fiches/templates/fiches/home.html:19
msgid "Recherche"
msgstr "Search"
#~ msgid "Department :"
#~ msgstr "Department:"