From b4edd7f4dcef4f757098e93ec8eb6cdf2fe1a04f Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 22 Apr 2020 18:12:37 +0200 Subject: [PATCH] Create preferences models and edition template --- preferences/locale/fr/LC_MESSAGES/django.po | 346 ++++++++++---------- preferences/models.py | 26 +- preferences/urls.py | 19 +- preferences/utils/__init__.py | 0 preferences/utils/models.py | 55 ++++ preferences/utils/views.py | 68 ++++ preferences/views.py | 28 +- 7 files changed, 310 insertions(+), 232 deletions(-) create mode 100644 preferences/utils/__init__.py create mode 100644 preferences/utils/models.py create mode 100644 preferences/utils/views.py diff --git a/preferences/locale/fr/LC_MESSAGES/django.po b/preferences/locale/fr/LC_MESSAGES/django.po index c655e7a3..d034ac9b 100644 --- a/preferences/locale/fr/LC_MESSAGES/django.po +++ b/preferences/locale/fr/LC_MESSAGES/django.po @@ -256,57 +256,57 @@ msgstr "Modèles de document actuels" msgid "Current attributes" msgstr "Attributs actuels" -#: preferences/models.py:78 +#: preferences/models.py:56 msgid "Users can't select their room" msgstr "Les utilisateurs ne peuvent pas modifier leur chambre" -#: preferences/models.py:79 +#: preferences/models.py:57 msgid "" "Users can only select a room occupied by a user with a disabled connection." msgstr "" "Les utilisateurs peuvent sélectionner la chambre d'un adhérent dont la " "connexion est désactivée." -#: preferences/models.py:80 +#: preferences/models.py:58 msgid "Users can select all rooms" msgstr "Les utilisateurs peuvent choisir toutes les chambres" -#: preferences/models.py:86 +#: preferences/models.py:64 msgid "Users can create a club." msgstr "Les utilisateurs peuvent créer un club." -#: preferences/models.py:89 +#: preferences/models.py:67 msgid "Users can create a member." msgstr "Les utilisateurs peuvent créer un adhérent." -#: preferences/models.py:95 +#: preferences/models.py:73 msgid "Users can edit their shell." msgstr "Les utilisateurs peuvent modifier leur interface en ligne de commande." -#: preferences/models.py:101 +#: preferences/models.py:79 msgid "Policy on self users room edition" msgstr "Autorisation d'édtion du champ chambre par les utilisateurs" -#: preferences/models.py:104 +#: preferences/models.py:82 msgid "Enable local email accounts for users." msgstr "Activer les comptes mail locaux pour les utilisateurs." -#: preferences/models.py:109 +#: preferences/models.py:87 msgid "Domain to use for local email accounts." msgstr "Domaine à utiliser pour les comptes mail locaux." -#: preferences/models.py:113 +#: preferences/models.py:91 msgid "Maximum number of local email addresses for a standard user." msgstr "" "Nombre maximum d'adresses mail locales autorisé pour un utilisateur standard." -#: preferences/models.py:118 +#: preferences/models.py:96 msgid "Not yet active users will be deleted after this number of days." msgstr "" "Les utilisateurs n'ayant jamais adhéré seront supprimés après ce nombre de " "jours." -#: preferences/models.py:124 +#: preferences/models.py:102 msgid "" "Users with an email address not yet confirmed will be disabled after this " "number of days." @@ -314,11 +314,11 @@ msgstr "" "Les utilisateurs n'ayant pas confirmé leur addresse mail seront désactivés " "après ce nombre de jours" -#: preferences/models.py:128 +#: preferences/models.py:106 msgid "A new user can create their account on Re2o." msgstr "Un nouvel utilisateur peut créer son compte sur Re2o." -#: preferences/models.py:133 +#: preferences/models.py:111 msgid "" "If True, all new created and connected users are active. If False, only when " "a valid registration has been paid." @@ -326,7 +326,7 @@ msgstr "" "Si True, tous les nouveaux utilisations créés et connectés sont actifs. Si " "False, seulement quand une inscription validée a été payée." -#: preferences/models.py:140 +#: preferences/models.py:118 msgid "" "If True, users have the choice to receive an email containing a link to " "reset their password during creation, or to directly set their password in " @@ -337,172 +337,172 @@ msgstr "" "de choisir leur mot de passe immédiatement. Si False, un mail est toujours " "envoyé." -#: preferences/models.py:147 +#: preferences/models.py:125 msgid "If True, archived users are allowed to connect." msgstr "Si True, les utilisateurs archivés sont autorisés à se connecter." -#: preferences/models.py:151 +#: preferences/models.py:129 msgid "Can view the user preferences" msgstr "Peut voir les préférences d'utilisateur" -#: preferences/models.py:152 +#: preferences/models.py:130 msgid "user preferences" msgstr "Préférences d'utilisateur" -#: preferences/models.py:159 +#: preferences/models.py:137 msgid "Email domain must begin with @." msgstr "Un domaine mail doit commencer par @." -#: preferences/models.py:177 +#: preferences/models.py:155 msgid "Automatic configuration by RA" msgstr "Configuration automatique par RA" -#: preferences/models.py:178 +#: preferences/models.py:156 msgid "IP addresses assignment by DHCPv6" msgstr "Attribution d'adresses IP par DHCPv6" -#: preferences/models.py:179 +#: preferences/models.py:157 msgid "Disabled" msgstr "Désactivé" -#: preferences/models.py:188 +#: preferences/models.py:166 msgid "default Time To Live (TTL) for CNAME, A and AAAA records" msgstr "" "Temps de vie (TTL) par défault pour des enregistrements CNAME, A et AAAA" -#: preferences/models.py:198 +#: preferences/models.py:176 msgid "Can view the machine preferences" msgstr "Peut voir les préférences de machine" -#: preferences/models.py:199 +#: preferences/models.py:177 msgid "machine preferences" msgstr "Préférences de machine" -#: preferences/models.py:219 preferences/models.py:677 +#: preferences/models.py:197 preferences/models.py:655 msgid "On the IP range's VLAN of the machine" msgstr "Sur le VLAN de la plage d'IP de la machine" -#: preferences/models.py:220 preferences/models.py:678 +#: preferences/models.py:198 preferences/models.py:656 msgid "Preset in \"VLAN for machines accepted by RADIUS\"" msgstr "Prédéfinie dans « VLAN pour les machines acceptées par RADIUS »" -#: preferences/models.py:226 +#: preferences/models.py:204 msgid "Web management, activated in case of automatic provision." msgstr "Gestion web, activée en cas de provision automatique." -#: preferences/models.py:231 +#: preferences/models.py:209 msgid "" "SSL web management, make sure that a certificate is installed on the switch." msgstr "" "Gestion web SSL, vérifiez qu'un certificat est installé sur le commutateur " "réseau." -#: preferences/models.py:237 +#: preferences/models.py:215 msgid "REST management, activated in case of automatic provision." msgstr "Gestion REST, activée en cas de provision automatique." -#: preferences/models.py:244 +#: preferences/models.py:222 msgid "IP range for the management of switches." msgstr "Plage d'IP pour la gestion des commutateurs réseau." -#: preferences/models.py:250 +#: preferences/models.py:228 msgid "Provision of configuration mode for switches." msgstr "Mode de provision de configuration pour les commutateurs réseau." -#: preferences/models.py:253 +#: preferences/models.py:231 msgid "SFTP login for switches." msgstr "Identifiant SFTP pour les commutateurs réseau." -#: preferences/models.py:256 +#: preferences/models.py:234 msgid "SFTP password." msgstr "Mot de passe SFTP." -#: preferences/models.py:360 +#: preferences/models.py:338 msgid "Can view the topology preferences" msgstr "Peut voir les préférences de topologie" -#: preferences/models.py:361 +#: preferences/models.py:339 msgid "topology preferences" msgstr "préférences de topologie" -#: preferences/models.py:374 +#: preferences/models.py:352 msgid "RADIUS key." msgstr "Clé RADIUS." -#: preferences/models.py:376 +#: preferences/models.py:354 msgid "Comment for this key." msgstr "Commentaire pour cette clé." -#: preferences/models.py:379 +#: preferences/models.py:357 msgid "Default key for switches." msgstr "Clé par défaut pour les commutateurs réseau." -#: preferences/models.py:383 +#: preferences/models.py:361 msgid "Can view a RADIUS key object" msgstr "Peut voir un objet clé RADIUS" -#: preferences/models.py:384 preferences/views.py:331 +#: preferences/models.py:362 preferences/views.py:307 msgid "RADIUS key" msgstr "Clé RADIUS" -#: preferences/models.py:385 +#: preferences/models.py:363 #: preferences/templates/preferences/display_preferences.html:221 msgid "RADIUS keys" msgstr "clés RADIUS" -#: preferences/models.py:392 +#: preferences/models.py:370 msgid "Default RADIUS key for switches already exists." msgstr "Clé par défaut pour les commutateurs réseau." -#: preferences/models.py:395 +#: preferences/models.py:373 msgid "RADIUS key " msgstr "clé RADIUS " -#: preferences/models.py:401 +#: preferences/models.py:379 msgid "Switch login." msgstr "Identifiant du commutateur réseau." -#: preferences/models.py:402 +#: preferences/models.py:380 msgid "Password." msgstr "Mot de passe." -#: preferences/models.py:404 +#: preferences/models.py:382 msgid "Default credentials for switches." msgstr "Identifiants par défaut pour les commutateurs réseau." -#: preferences/models.py:411 +#: preferences/models.py:389 msgid "Can view a switch management credentials object" msgstr "Peut voir un objet identifiants de gestion de commutateur réseau" -#: preferences/models.py:414 preferences/views.py:394 +#: preferences/models.py:392 preferences/views.py:370 msgid "switch management credentials" msgstr "identifiants de gestion de commutateur réseau" -#: preferences/models.py:417 +#: preferences/models.py:395 msgid "Switch login " msgstr "Identifiant du commutateur réseau " -#: preferences/models.py:429 +#: preferences/models.py:407 msgid "Delay between the email and the membership's end." msgstr "Délai entre le mail et la fin d'adhésion." -#: preferences/models.py:435 +#: preferences/models.py:413 msgid "Message displayed specifically for this reminder." msgstr "Message affiché spécifiquement pour ce rappel." -#: preferences/models.py:439 +#: preferences/models.py:417 msgid "Can view a reminder object" msgstr "Peut voir un objet rappel" -#: preferences/models.py:440 preferences/views.py:276 +#: preferences/models.py:418 preferences/views.py:252 msgid "reminder" msgstr "rappel" -#: preferences/models.py:441 +#: preferences/models.py:419 msgid "reminders" msgstr "rappels" -#: preferences/models.py:462 +#: preferences/models.py:440 msgid "" "General message displayed on the French version of the website (e.g. in case " "of maintenance)." @@ -510,7 +510,7 @@ msgstr "" "Message général affiché sur la version française du site (ex : en cas de " "maintenance)." -#: preferences/models.py:470 +#: preferences/models.py:448 msgid "" "General message displayed on the English version of the website (e.g. in " "case of maintenance)." @@ -518,75 +518,75 @@ msgstr "" "Message général affiché sur la version anglaise du site (ex : en cas de " "maintenance)." -#: preferences/models.py:485 +#: preferences/models.py:463 msgid "Can view the general preferences" msgstr "Peut voir les préférences générales" -#: preferences/models.py:486 +#: preferences/models.py:464 msgid "general preferences" msgstr "préférences générales" -#: preferences/models.py:506 +#: preferences/models.py:484 msgid "Can view the service preferences" msgstr "Peut voir les préférences de service" -#: preferences/models.py:507 preferences/views.py:227 +#: preferences/models.py:485 preferences/views.py:203 msgid "service" msgstr "service" -#: preferences/models.py:508 +#: preferences/models.py:486 msgid "services" msgstr "services" -#: preferences/models.py:518 +#: preferences/models.py:496 msgid "Contact email address." msgstr "Adresse mail de contact." -#: preferences/models.py:524 +#: preferences/models.py:502 msgid "Description of the associated email address." msgstr "Description de l'adresse mail associée." -#: preferences/models.py:534 +#: preferences/models.py:512 msgid "Can view a contact email address object" msgstr "Peut voir un objet adresse mail de contact" -#: preferences/models.py:536 +#: preferences/models.py:514 msgid "contact email address" msgstr "adresse mail de contact" -#: preferences/models.py:537 +#: preferences/models.py:515 msgid "contact email addresses" msgstr "adresses mail de contact" -#: preferences/models.py:545 preferences/views.py:634 +#: preferences/models.py:523 preferences/views.py:610 msgid "mandate" msgstr "mandat" -#: preferences/models.py:546 +#: preferences/models.py:524 msgid "mandates" msgstr "mandats" -#: preferences/models.py:547 +#: preferences/models.py:525 msgid "Can view a mandate object" msgstr "Peut voir un objet mandat" -#: preferences/models.py:554 +#: preferences/models.py:532 msgid "president of the association" msgstr "président de l'association" -#: preferences/models.py:555 +#: preferences/models.py:533 msgid "Displayed on subscription vouchers." msgstr "Affiché sur les reçus de cotisation." -#: preferences/models.py:557 +#: preferences/models.py:535 msgid "start date" msgstr "date de début" -#: preferences/models.py:558 +#: preferences/models.py:536 msgid "end date" msgstr "date de fin" -#: preferences/models.py:571 +#: preferences/models.py:549 msgid "" "No mandates have been created. Please go to the preferences page to create " "one." @@ -594,140 +594,140 @@ msgstr "" "Aucun mandat n'a été créé. Veuillez vous rendre sur la page de préférences " "pour en créer un." -#: preferences/models.py:586 +#: preferences/models.py:564 msgid "Networking organisation school Something" msgstr "Association de réseau de l'école Machin" -#: preferences/models.py:589 +#: preferences/models.py:567 msgid "Threadneedle Street" msgstr "1 rue de la Vrillière" -#: preferences/models.py:590 +#: preferences/models.py:568 msgid "London EC2R 8AH" msgstr "75001 Paris" -#: preferences/models.py:593 +#: preferences/models.py:571 msgid "Organisation" msgstr "Association" -#: preferences/models.py:600 +#: preferences/models.py:578 msgid "Can view the organisation preferences" msgstr "Peut voir les préférences d'association" -#: preferences/models.py:601 +#: preferences/models.py:579 msgid "organisation preferences" msgstr "préférences d'association" -#: preferences/models.py:619 +#: preferences/models.py:597 msgid "Can view the homepage preferences" msgstr "Peut voir les préférences de page d'accueil" -#: preferences/models.py:620 +#: preferences/models.py:598 msgid "homepage preferences" msgstr "Préférences de page d'accueil" -#: preferences/models.py:634 +#: preferences/models.py:612 msgid "Welcome email in French." msgstr "Mail de bienvenue en français." -#: preferences/models.py:637 +#: preferences/models.py:615 msgid "Welcome email in English." msgstr "Mail de bienvenue en anglais." -#: preferences/models.py:642 +#: preferences/models.py:620 msgid "Can view the email message preferences" msgstr "Peut voir les préférences de message pour les mails" -#: preferences/models.py:644 +#: preferences/models.py:622 msgid "email message preferences" msgstr "préférences de messages pour les mails" -#: preferences/models.py:649 +#: preferences/models.py:627 msgid "RADIUS attribute" msgstr "attribut RADIUS" -#: preferences/models.py:650 +#: preferences/models.py:628 msgid "RADIUS attributes" msgstr "attributs RADIUS" -#: preferences/models.py:654 preferences/views.py:587 +#: preferences/models.py:632 preferences/views.py:563 msgid "attribute" msgstr "attribut" -#: preferences/models.py:655 +#: preferences/models.py:633 msgid "See https://freeradius.org/rfc/attributes.html." msgstr "Voir https://freeradius.org/rfc/attributes.html." -#: preferences/models.py:657 +#: preferences/models.py:635 msgid "value" msgstr "valeur" -#: preferences/models.py:659 +#: preferences/models.py:637 msgid "comment" msgstr "commentaire" -#: preferences/models.py:660 +#: preferences/models.py:638 msgid "Use this field to document this attribute." msgstr "Utilisez ce champ pour documenter cet attribut." -#: preferences/models.py:671 +#: preferences/models.py:649 msgid "RADIUS policy" msgstr "politique de RADIUS" -#: preferences/models.py:672 +#: preferences/models.py:650 #: preferences/templates/preferences/display_preferences.html:299 msgid "RADIUS policies" msgstr "politiques de RADIUS" -#: preferences/models.py:683 +#: preferences/models.py:661 msgid "Reject the machine" msgstr "Rejeter la machine" -#: preferences/models.py:684 +#: preferences/models.py:662 msgid "Place the machine on the VLAN" msgstr "Placer la machine sur le VLAN" -#: preferences/models.py:693 +#: preferences/models.py:671 msgid "policy for unknown machines" msgstr "politique pour les machines inconnues" -#: preferences/models.py:701 +#: preferences/models.py:679 msgid "unknown machines VLAN" msgstr "VLAN pour les machines inconnues" -#: preferences/models.py:702 +#: preferences/models.py:680 msgid "VLAN for unknown machines if not rejected." msgstr "VLAN pour les machines inconnues si non rejeté." -#: preferences/models.py:708 +#: preferences/models.py:686 msgid "unknown machines attributes" msgstr "attributs pour les machines inconnues" -#: preferences/models.py:709 +#: preferences/models.py:687 msgid "Answer attributes for unknown machines." msgstr "Attributs de réponse pour les machines inconnues." -#: preferences/models.py:715 +#: preferences/models.py:693 msgid "policy for unknown ports" msgstr "politique pour les ports inconnus" -#: preferences/models.py:723 +#: preferences/models.py:701 msgid "unknown ports VLAN" msgstr "VLAN pour les ports inconnus" -#: preferences/models.py:724 +#: preferences/models.py:702 msgid "VLAN for unknown ports if not rejected." msgstr "VLAN pour les ports inconnus si non rejeté." -#: preferences/models.py:730 +#: preferences/models.py:708 msgid "unknown ports attributes" msgstr "attributs pour les ports inconnus" -#: preferences/models.py:731 +#: preferences/models.py:709 msgid "Answer attributes for unknown ports." msgstr "Attributs de réponse pour les ports inconnus." -#: preferences/models.py:738 +#: preferences/models.py:716 msgid "" "Policy for machines connecting from unregistered rooms (relevant on ports " "with STRICT RADIUS mode)" @@ -735,87 +735,87 @@ msgstr "" "Politique pour les machines se connectant depuis des chambre non " "enregistrées (pertinent pour les ports avec le mode de RADIUS STRICT)" -#: preferences/models.py:748 +#: preferences/models.py:726 msgid "unknown rooms VLAN" msgstr "VLAN pour les chambres inconnues" -#: preferences/models.py:749 +#: preferences/models.py:727 msgid "VLAN for unknown rooms if not rejected." msgstr "VLAN pour les chambres inconnues si non rejeté." -#: preferences/models.py:755 +#: preferences/models.py:733 msgid "unknown rooms attributes" msgstr "attributs pour les chambres inconnues" -#: preferences/models.py:756 +#: preferences/models.py:734 msgid "Answer attributes for unknown rooms." msgstr "Attributs de réponse pour les chambres inconnues." -#: preferences/models.py:762 +#: preferences/models.py:740 msgid "policy for non members" msgstr "politique pour les non adhérents" -#: preferences/models.py:770 +#: preferences/models.py:748 msgid "non members VLAN" msgstr "VLAN pour les non adhérents" -#: preferences/models.py:771 +#: preferences/models.py:749 msgid "VLAN for non members if not rejected." msgstr "VLAN pour les non adhérents si non rejeté." -#: preferences/models.py:777 +#: preferences/models.py:755 msgid "non members attributes" msgstr "attributs pour les non adhérents" -#: preferences/models.py:778 +#: preferences/models.py:756 msgid "Answer attributes for non members." msgstr "Attributs de réponse pour les non adhérents." -#: preferences/models.py:784 +#: preferences/models.py:762 msgid "policy for banned users" msgstr "politique pour les utilisateurs bannis" -#: preferences/models.py:792 +#: preferences/models.py:770 msgid "banned users VLAN" msgstr "VLAN pour les utilisateurs bannis" -#: preferences/models.py:793 +#: preferences/models.py:771 msgid "VLAN for banned users if not rejected." msgstr "VLAN pour les utilisateurs bannis si non rejeté." -#: preferences/models.py:799 +#: preferences/models.py:777 msgid "banned users attributes" msgstr "attributs pour les utilisateurs bannis" -#: preferences/models.py:800 +#: preferences/models.py:778 msgid "Answer attributes for banned users." msgstr "Attributs de réponse pour les utilisateurs bannis." -#: preferences/models.py:813 +#: preferences/models.py:791 msgid "accepted users attributes" msgstr "attributs pour les utilisateurs acceptés" -#: preferences/models.py:814 +#: preferences/models.py:792 msgid "Answer attributes for accepted users." msgstr "Attributs de réponse pour les utilisateurs acceptés." -#: preferences/models.py:841 +#: preferences/models.py:819 msgid "subscription preferences" msgstr "préférences de cotisation" -#: preferences/models.py:845 +#: preferences/models.py:823 msgid "template for invoices" msgstr "modèle pour les factures" -#: preferences/models.py:852 +#: preferences/models.py:830 msgid "template for subscription vouchers" msgstr "modèle pour les reçus de cotisation" -#: preferences/models.py:858 +#: preferences/models.py:836 msgid "send voucher by email when the invoice is controlled" msgstr "envoyer le reçu par mail quand la facture est contrôlée" -#: preferences/models.py:860 +#: preferences/models.py:838 msgid "" "Be careful, if no mandate is defined on the preferences page, errors will be " "triggered when generating vouchers." @@ -823,19 +823,19 @@ msgstr "" "Faites attention, si aucun mandat n'est défini sur la page de préférences, " "des erreurs seront déclenchées en générant des reçus." -#: preferences/models.py:872 +#: preferences/models.py:850 msgid "template" msgstr "modèle" -#: preferences/models.py:873 +#: preferences/models.py:851 msgid "name" msgstr "nom" -#: preferences/models.py:876 +#: preferences/models.py:854 msgid "document template" msgstr "modèle de document" -#: preferences/models.py:877 +#: preferences/models.py:855 msgid "document templates" msgstr "modèles de document" @@ -1035,9 +1035,9 @@ msgstr "Préférences générales" #: preferences/templates/preferences/display_preferences.html:417 #: preferences/templates/preferences/display_preferences.html:495 #: preferences/templates/preferences/edit_preferences.html:46 -#: preferences/views.py:212 preferences/views.py:261 preferences/views.py:307 -#: preferences/views.py:367 preferences/views.py:431 preferences/views.py:496 -#: preferences/views.py:572 preferences/views.py:619 +#: preferences/views.py:188 preferences/views.py:237 preferences/views.py:283 +#: preferences/views.py:343 preferences/views.py:407 preferences/views.py:472 +#: preferences/views.py:548 preferences/views.py:595 msgid "Edit" msgstr "Modifier" @@ -1359,75 +1359,75 @@ msgstr "URL du compte Facebook" msgid "Editing of preferences" msgstr "Modification des préférences" -#: preferences/views.py:160 +#: preferences/utils/views.py:45 msgid "Unknown object." msgstr "Objet inconnu." -#: preferences/views.py:179 +#: preferences/utils/views.py:64 msgid "The preferences were edited." msgstr "Les préférences ont été modifiées." -#: preferences/views.py:191 +#: preferences/views.py:167 msgid "The service was added." msgstr "Le service a été ajouté." -#: preferences/views.py:194 preferences/views.py:243 preferences/views.py:292 -#: preferences/views.py:349 preferences/views.py:412 preferences/views.py:471 -#: preferences/views.py:554 preferences/views.py:603 +#: preferences/views.py:170 preferences/views.py:219 preferences/views.py:268 +#: preferences/views.py:325 preferences/views.py:388 preferences/views.py:447 +#: preferences/views.py:530 preferences/views.py:579 msgid "Add" msgstr "Ajouter" -#: preferences/views.py:209 +#: preferences/views.py:185 msgid "The service was edited." msgstr "Le service a été modifié." -#: preferences/views.py:224 +#: preferences/views.py:200 msgid "The service was deleted." msgstr "Le service a été supprimé." -#: preferences/views.py:240 +#: preferences/views.py:216 msgid "The reminder was added." msgstr "Le rappel a été ajouté." -#: preferences/views.py:258 +#: preferences/views.py:234 msgid "The reminder was edited." msgstr "Le rappel a été modifié." -#: preferences/views.py:273 +#: preferences/views.py:249 msgid "The reminder was deleted." msgstr "Le rappel a été supprimé." -#: preferences/views.py:289 +#: preferences/views.py:265 msgid "The RADIUS key was added." msgstr "La clé RADIUS a été ajoutée." -#: preferences/views.py:304 +#: preferences/views.py:280 msgid "The RADIUS key was edited." msgstr "La clé RADIUS a été modifiée." -#: preferences/views.py:320 +#: preferences/views.py:296 msgid "The RADIUS key was deleted." msgstr "La clé RADIUS a été supprimée." -#: preferences/views.py:325 +#: preferences/views.py:301 msgid "The RADIUS key is assigned to at least one switch, you can't delete it." msgstr "" "La clé RADIUS est assignée a au moins un commutateur réseau, vous ne pouvez " "pas la supprimer." -#: preferences/views.py:344 +#: preferences/views.py:320 msgid "The switch management credentials were added." msgstr "Les identifiants de gestion de commutateur réseay ont été ajoutés." -#: preferences/views.py:364 +#: preferences/views.py:340 msgid "The switch management credentials were edited." msgstr "Les identifiants de gestion de commutateur réseau ont été modifiés." -#: preferences/views.py:381 +#: preferences/views.py:357 msgid "The switch management credentials were deleted." msgstr "Les identifiants de gestion de commutateur réseau ont été supprimés." -#: preferences/views.py:387 +#: preferences/views.py:363 msgid "" "The switch management credentials are assigned to at least one switch, you " "can't delete them." @@ -1435,44 +1435,44 @@ msgstr "" "Les identifiants de gestion de commutateur réseau sont assignés à au moins " "un commutateur réseau , vous ne pouvez pas les supprimer." -#: preferences/views.py:407 +#: preferences/views.py:383 msgid "The contact email address was created." msgstr "L'adresse mail de contact a été supprimée." -#: preferences/views.py:428 +#: preferences/views.py:404 msgid "The contact email address was edited." msgstr "L'adresse mail de contact a été modifiée." -#: preferences/views.py:446 +#: preferences/views.py:422 msgid "The contact email adress was deleted." msgstr "L'adresse mail de contact a été supprimée." -#: preferences/views.py:449 preferences/views.py:536 +#: preferences/views.py:425 preferences/views.py:512 msgid "Delete" msgstr "Supprimer" -#: preferences/views.py:466 +#: preferences/views.py:442 msgid "The document template was created." msgstr "Le modèle de document a été créé." -#: preferences/views.py:472 +#: preferences/views.py:448 msgid "New document template" msgstr "Nouveau modèle de document" -#: preferences/views.py:491 +#: preferences/views.py:467 msgid "The document template was edited." msgstr "Le modèle de document a été édité." -#: preferences/views.py:497 +#: preferences/views.py:473 msgid "Edit document template" msgstr "Modifier le modèle de document" -#: preferences/views.py:520 +#: preferences/views.py:496 #, python-format msgid "The document template %(document_template)s was deleted." msgstr "Le modèle de document %(document_template)s a été supprimé." -#: preferences/views.py:527 +#: preferences/views.py:503 #, python-format msgid "" "The document template %(document_template)s can't be deleted because it is " @@ -1481,31 +1481,31 @@ msgstr "" "Le modèle de document %(document_template)s ne peut pas être supprimé car il " "est actuellement utilisé." -#: preferences/views.py:537 +#: preferences/views.py:513 msgid "Delete document template" msgstr "Supprimer le modèle de document" -#: preferences/views.py:551 +#: preferences/views.py:527 msgid "The attribute was added." msgstr "L'attribut a été ajouté." -#: preferences/views.py:569 +#: preferences/views.py:545 msgid "The attribute was edited." msgstr "L'attribut a été modifié." -#: preferences/views.py:584 +#: preferences/views.py:560 msgid "The attribute was deleted." msgstr "L'attribut a été supprimé." -#: preferences/views.py:600 +#: preferences/views.py:576 msgid "The mandate was added." msgstr "Le mandat a été ajouté." -#: preferences/views.py:616 +#: preferences/views.py:592 msgid "The mandate was edited." msgstr "Le mandat a été modifié." -#: preferences/views.py:631 +#: preferences/views.py:607 msgid "The mandate was deleted." msgstr "Le mandat été supprimé." diff --git a/preferences/models.py b/preferences/models.py index 66a72f46..b52a5f07 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -37,36 +37,14 @@ from django.utils.translation import ugettext_lazy as _ import machines.models +from .utils.models import PreferencesModel + from re2o.mixins import AclMixin, RevMixin from re2o.aes_field import AESEncryptedField from datetime import timedelta -class PreferencesModel(models.Model): - """ Base object for the Preferences objects - Defines methods to handle the cache of the settings (they should - not change a lot) """ - - @classmethod - def set_in_cache(cls): - """ Save the preferences in a server-side cache """ - instance, _created = cls.objects.get_or_create() - cache.set(cls().__class__.__name__.lower(), instance, None) - return instance - - @classmethod - def get_cached_value(cls, key): - """ Get the preferences from the server-side cache """ - instance = cache.get(cls().__class__.__name__.lower()) - if instance is None: - instance = cls.set_in_cache() - return getattr(instance, key) - - class Meta: - abstract = True - - class OptionalUser(AclMixin, PreferencesModel): """Options pour l'user : obligation ou nom du telephone, activation ou non du solde, autorisation du negatif, fingerprint etc""" diff --git a/preferences/urls.py b/preferences/urls.py index 4e5b1bcf..82780cb8 100644 --- a/preferences/urls.py +++ b/preferences/urls.py @@ -28,52 +28,53 @@ from __future__ import unicode_literals from django.conf.urls import url from . import views +from .views import edit_options urlpatterns = [ url( r"^edit_options/(?P
OptionalUser)$", - views.edit_options, + edit_options, name="edit-options", ), url( r"^edit_options/(?P
OptionalMachine)$", - views.edit_options, + edit_options, name="edit-options", ), url( r"^edit_options/(?P
OptionalTopologie)$", - views.edit_options, + edit_options, name="edit-options", ), url( r"^edit_options/(?P
GeneralOption)$", - views.edit_options, + edit_options, name="edit-options", ), url( r"^edit_options/(?P
AssoOption)$", - views.edit_options, + edit_options, name="edit-options", ), url( r"^edit_options/(?P
HomeOption)$", - views.edit_options, + edit_options, name="edit-options", ), url( r"^edit_options/(?P
MailMessageOption)$", - views.edit_options, + edit_options, name="edit-options", ), url( r"^edit_options/(?P
RadiusOption)$", - views.edit_options, + edit_options, name="edit-options", ), url( r"^edit_options/(?P
CotisationsOption)$", - views.edit_options, + edit_options, name="edit-options", ), url(r"^add_service/$", views.add_service, name="add-service"), diff --git a/preferences/utils/__init__.py b/preferences/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/preferences/utils/models.py b/preferences/utils/models.py new file mode 100644 index 00000000..5ade54e1 --- /dev/null +++ b/preferences/utils/models.py @@ -0,0 +1,55 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2020 Gabriel Détraz +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# App de gestion des machines pour re2o +# Gabriel Détraz, Augustin Lemesle +# Gplv2 +""" +Utils for preferences +""" + +from __future__ import unicode_literals + +from django.core.cache import cache +from django.db import models + + +class PreferencesModel(models.Model): + """ Base object for the Preferences objects + Defines methods to handle the cache of the settings (they should + not change a lot) """ + + @classmethod + def set_in_cache(cls): + """ Save the preferences in a server-side cache """ + instance, _created = cls.objects.get_or_create() + cache.set(cls().__class__.__name__.lower(), instance, None) + return instance + + @classmethod + def get_cached_value(cls, key): + """ Get the preferences from the server-side cache """ + instance = cache.get(cls().__class__.__name__.lower()) + if instance is None: + instance = cls.set_in_cache() + return getattr(instance, key) + + class Meta: + abstract = True diff --git a/preferences/utils/views.py b/preferences/utils/views.py new file mode 100644 index 00000000..978b9b98 --- /dev/null +++ b/preferences/utils/views.py @@ -0,0 +1,68 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2020 Gabriel Détraz +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# App de gestion des machines pour re2o +# Gabriel Détraz, Augustin Lemesle +# Gplv2 +""" +Utils for preferences +""" + +from __future__ import unicode_literals +from django.urls import reverse +from django.shortcuts import redirect +from django.contrib import messages +from django.db.models import ProtectedError +from django.db import transaction +from django.utils.translation import ugettext as _ + +from reversion import revisions as reversion + +from re2o.views import form + +def edit_options_template_function(request, section, forms, models): + """ Edition des préférences générales""" + model = getattr(models, section, None) + form_instance = getattr(forms, "Edit" + section + "Form", None) + if not (model or form_instance): + messages.error(request, _("Unknown object.")) + return redirect(reverse("preferences:display-options")) + + options_instance, _created = model.objects.get_or_create() + can, msg, permissions = options_instance.can_edit(request.user) + if not can: + messages.error(request, acl_error_message(msg, permissions)) + return redirect(reverse("index")) + options = form_instance( + request.POST or None, request.FILES or None, instance=options_instance + ) + if options.is_valid(): + with transaction.atomic(), reversion.create_revision(): + options.save() + reversion.set_user(request.user) + reversion.set_comment( + "Field(s) edited: %s" + % ", ".join(field for field in options.changed_data) + ) + messages.success(request, _("The preferences were edited.")) + return redirect(reverse("preferences:display-options")) + return form({"options": options}, "preferences/edit_preferences.html", request) + + diff --git a/preferences/views.py b/preferences/views.py index a7df9cef..06d9871e 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -86,6 +86,7 @@ from .models import ( from . import models from . import forms +from .utils.views import edit_options_template_function @login_required @can_view_all( @@ -153,32 +154,7 @@ def display_options(request): @login_required def edit_options(request, section): - """ Edition des préférences générales""" - model = getattr(models, section, None) - form_instance = getattr(forms, "Edit" + section + "Form", None) - if not (model or form_instance): - messages.error(request, _("Unknown object.")) - return redirect(reverse("preferences:display-options")) - - options_instance, _created = model.objects.get_or_create() - can, msg, permissions = options_instance.can_edit(request.user) - if not can: - messages.error(request, acl_error_message(msg, permissions)) - return redirect(reverse("index")) - options = form_instance( - request.POST or None, request.FILES or None, instance=options_instance - ) - if options.is_valid(): - with transaction.atomic(), reversion.create_revision(): - options.save() - reversion.set_user(request.user) - reversion.set_comment( - "Field(s) edited: %s" - % ", ".join(field for field in options.changed_data) - ) - messages.success(request, _("The preferences were edited.")) - return redirect(reverse("preferences:display-options")) - return form({"options": options}, "preferences/edit_preferences.html", request) + return edit_options_template_function(request, section, forms, models) @login_required