From 7aa69ab60f61752273347e18a32ec68a1c1eebb4 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 26 Aug 2017 16:04:51 +0200 Subject: [PATCH] Reglages nom du site et emailfrom dans preferences --- machines/models.py | 2 -- .../0012_generaloption_req_expire_hrs.py | 20 +++++++++++++++++++ .../0013_generaloption_site_name.py | 20 +++++++++++++++++++ .../0014_generaloption_email_from.py | 20 +++++++++++++++++++ preferences/models.py | 3 +++ .../preferences/display_preferences.html | 8 ++++++++ re2o/context_processors.py | 5 +++-- re2o/settings_local.example.py | 15 -------------- .../migrations/0023_auto_20170826_1530.py | 20 +++++++++++++++++++ users/models.py | 7 ++++--- users/views.py | 16 ++++++++------- 11 files changed, 107 insertions(+), 29 deletions(-) create mode 100644 preferences/migrations/0012_generaloption_req_expire_hrs.py create mode 100644 preferences/migrations/0013_generaloption_site_name.py create mode 100644 preferences/migrations/0014_generaloption_email_from.py create mode 100644 topologie/migrations/0023_auto_20170826_1530.py diff --git a/machines/models.py b/machines/models.py index 0866d4dc..4c236296 100644 --- a/machines/models.py +++ b/machines/models.py @@ -33,8 +33,6 @@ import re from reversion import revisions as reversion from datetime import timedelta -from re2o.settings import MAIN_EXTENSION - class Machine(models.Model): """ Class définissant une machine, object parent user, objets fils interfaces""" diff --git a/preferences/migrations/0012_generaloption_req_expire_hrs.py b/preferences/migrations/0012_generaloption_req_expire_hrs.py new file mode 100644 index 00000000..e12baf19 --- /dev/null +++ b/preferences/migrations/0012_generaloption_req_expire_hrs.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-08-26 13:30 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0011_auto_20170825_2307'), + ] + + operations = [ + migrations.AddField( + model_name='generaloption', + name='req_expire_hrs', + field=models.IntegerField(default=48), + ), + ] diff --git a/preferences/migrations/0013_generaloption_site_name.py b/preferences/migrations/0013_generaloption_site_name.py new file mode 100644 index 00000000..06a2a5e3 --- /dev/null +++ b/preferences/migrations/0013_generaloption_site_name.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-08-26 13:40 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0012_generaloption_req_expire_hrs'), + ] + + operations = [ + migrations.AddField( + model_name='generaloption', + name='site_name', + field=models.CharField(default='Re2o', max_length=32), + ), + ] diff --git a/preferences/migrations/0014_generaloption_email_from.py b/preferences/migrations/0014_generaloption_email_from.py new file mode 100644 index 00000000..ac109fd5 --- /dev/null +++ b/preferences/migrations/0014_generaloption_email_from.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-08-26 13:58 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0013_generaloption_site_name'), + ] + + operations = [ + migrations.AddField( + model_name='generaloption', + name='email_from', + field=models.EmailField(default='www-data@serveur.net', max_length=254), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index 8c806d93..001b7c27 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -56,6 +56,9 @@ class GeneralOption(models.Model): search_display_page = models.IntegerField(default=15) pagination_number = models.IntegerField(default=25) pagination_large_number = models.IntegerField(default=8) + req_expire_hrs = models.IntegerField(default=48) + site_name = models.CharField(max_length=32, default="Re2o") + email_from = models.EmailField(default="www-data@serveur.net") class Service(models.Model): name = models.CharField(max_length=32) diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 60b11543..96d3a910 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -97,6 +97,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,

+ + + + + + @@ -106,6 +112,8 @@ with this program; if not, write to the Free Software Foundation, Inc., + +
Nom du site web{{ generaloptions.site_name }}Adresse mail d'expedition automatique{{ generaloptions.email_from }}
Affichage de résultats dans le champ de recherche {{ generaloptions.search_display_page }}
Nombre d'items affichés en liste (taille élevée) {{ generaloptions.pagination_large_number }}Temps avant expiration du lien de reinitialisation de mot de passe (en heures){{ generaloptions.req_expire_hrs }}

Données de l'association

diff --git a/re2o/context_processors.py b/re2o/context_processors.py index 8b34425c..0fb8b22b 100644 --- a/re2o/context_processors.py +++ b/re2o/context_processors.py @@ -21,9 +21,10 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from machines.models import Interface, Machine -from .settings import SITE_NAME +from preferences.models import GeneralOption def context_user(request): + general_options, created = GeneralOption.objects.get_or_create() user = request.user if user.is_authenticated(): interfaces = user.user_interfaces() @@ -50,5 +51,5 @@ def context_user(request): 'is_infra': is_infra, 'is_admin' : is_admin, 'interfaces': interfaces, - 'site_name': SITE_NAME, + 'site_name': general_options.site_name, } diff --git a/re2o/settings_local.example.py b/re2o/settings_local.example.py index b5fe323c..0d9ca37d 100644 --- a/re2o/settings_local.example.py +++ b/re2o/settings_local.example.py @@ -59,23 +59,8 @@ CSRF_COOKIE_HTTPONLY = True X_FRAME_OPTIONS = 'DENY' SESSION_COOKIE_AGE = 60 * 60 * 3 -# Association information - -SITE_NAME = "Re2o.rez" - -# Main extension used in asso -MAIN_EXTENSION = ".rez" - LOGO_PATH = "static_files/logo.png" -# Number of hours a token remains valid after having been created. Numeric and string -# versions should have the same meaning. -REQ_EXPIRE_HRS = 48 -REQ_EXPIRE_STR = '48 heures' - -# Email `From` field -EMAIL_FROM = 'www-data@serveur.net' - EMAIL_HOST = 'smtp.example.org' # Reglages pour la bdd ldap diff --git a/topologie/migrations/0023_auto_20170826_1530.py b/topologie/migrations/0023_auto_20170826_1530.py new file mode 100644 index 00000000..594e7e9f --- /dev/null +++ b/topologie/migrations/0023_auto_20170826_1530.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-08-26 13:30 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0022_auto_20161211_1622'), + ] + + operations = [ + migrations.AlterField( + model_name='port', + name='radius', + field=models.CharField(choices=[('NO', 'NO'), ('STRICT', 'STRICT'), ('BLOQ', 'BLOQ'), ('COMMON', 'COMMON'), ('3', '3'), ('7', '7'), ('8', '8'), ('13', '13'), ('20', '20'), ('42', '42'), ('69', '69')], default='NO', max_length=32), + ), + ] diff --git a/users/models.py b/users/models.py index 26619014..dd8a2357 100644 --- a/users/models.py +++ b/users/models.py @@ -33,7 +33,7 @@ from django.db import transaction import ldapdb.models import ldapdb.models.fields -from re2o.settings import RIGHTS_LINK, REQ_EXPIRE_HRS, LDAP, GID_RANGES,UID_RANGES +from re2o.settings import RIGHTS_LINK, LDAP, GID_RANGES,UID_RANGES import re, uuid import datetime @@ -44,7 +44,7 @@ from django.core.validators import MinLengthValidator from topologie.models import Room from cotisations.models import Cotisation, Facture, Paiement, Vente from machines.models import Interface, Machine -from preferences.models import OptionalUser +from preferences.models import GeneralOption, OptionalUser now = timezone.now() @@ -622,8 +622,9 @@ class Request(models.Model): def save(self): if not self.expires_at: + options, created = GeneralOption.objects.get_or_create() self.expires_at = timezone.now() \ - + datetime.timedelta(hours=REQ_EXPIRE_HRS) + + datetime.timedelta(hours=options.req_expire_hrs) if not self.token: self.token = str(uuid.uuid4()).replace('-', '') # remove hyphens super(Request, self).save() diff --git a/users/views.py b/users/views.py index 5f53bd3b..f9ab5d32 100644 --- a/users/views.py +++ b/users/views.py @@ -47,7 +47,6 @@ from users.forms import MassArchiveForm, PassForm, ResetPasswordForm from preferences.models import OptionalUser, AssoOption, GeneralOption from re2o.login import hashNT -from re2o.settings import REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME def form(ctx, template, request): @@ -74,21 +73,23 @@ def password_change_action(u_form, user, request, req=False): def reset_passwd_mail(req, request): """ Prend en argument un request, envoie un mail de réinitialisation de mot de pass """ t = loader.get_template('users/email_passwd_request') - options, created = AssoOption.objects.get_or_create() + options, created = AssoOption.objects.get_or_create() + general_options, created = GeneralOption.objects.get_or_create() c = { 'name': str(req.user.name) + ' ' + str(req.user.surname), 'asso': options.name, 'asso_mail': options.contact, - 'site_name': SITE_NAME, + 'site_name': general_options.site_name, 'url': request.build_absolute_uri( reverse('users:process', kwargs={'token': req.token})), - 'expire_in': REQ_EXPIRE_STR, + 'expire_in': str(general_options.req_expire_hrs) + ' heures', } send_mail('Changement de mot de passe du Rézo Metz / Password renewal for Rézo Metz', t.render(c), - EMAIL_FROM, [req.user.email], fail_silently=False) + general_options.email_from, [req.user.email], fail_silently=False) return def notif_ban(ban): + general_options, created = GeneralOption.objects.get_or_create() """ Prend en argument un objet ban, envoie un mail de notification """ t = loader.get_template('users/email_ban_notif') c = Context({ @@ -97,13 +98,14 @@ def notif_ban(ban): 'date_end': ban.date_end, }) send_mail('Deconnexion disciplinaire', t.render(c), - EMAIL_FROM, [ban.user.email], fail_silently=False) + general_options.email_from, [ban.user.email], fail_silently=False) return def notif_inscription(user): """ Prend en argument un objet user, envoie un mail de bienvenue """ t = loader.get_template('users/email_welcome') options, created = AssoOption.objects.get_or_create() + general_options, created = GeneralOption.objects.get_or_create() c = Context({ 'nom': str(user.name) + ' ' + str(user.surname), 'asso_name': options.name, @@ -111,7 +113,7 @@ def notif_inscription(user): 'pseudo':user.pseudo, }) send_mail('Bienvenue au Rézo / Welcome to Rézo Metz', '', - EMAIL_FROM, [user.email], html_message=t.render(c)) + general_options.email_from, [user.email], html_message=t.render(c)) return