mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 15:12:25 +00:00
Merge branch 'optimisations' into 'master'
Optimisations See merge request federez/re2o!71
This commit is contained in:
commit
54d1172eff
17 changed files with 216 additions and 140 deletions
|
@ -296,9 +296,8 @@ class RechargeForm(Form):
|
||||||
|
|
||||||
def clean_value(self):
|
def clean_value(self):
|
||||||
value = self.cleaned_data['value']
|
value = self.cleaned_data['value']
|
||||||
options, _created = OptionalUser.objects.get_or_create()
|
if value < OptionalUser.get_cached_value('min_online_payment'):
|
||||||
if value < options.min_online_payment:
|
raise forms.ValidationError("Montant inférieur au montant minimal de paiement en ligne (%s) €" % OptionalUser.get_cached_value('min_online_payment'))
|
||||||
raise forms.ValidationError("Montant inférieur au montant minimal de paiement en ligne (%s) €" % options.min_online_payment)
|
if value + self.user.solde > OptionalUser.get_cached_value('max_solde'):
|
||||||
if value + self.user.solde > options.max_solde:
|
raise forms.ValidationError("Le solde ne peux excéder %s " % OptionalUser.get_cached_value('max_solde'))
|
||||||
raise forms.ValidationError("Le solde ne peux excéder %s " % options.max_solde)
|
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -38,7 +38,6 @@ def refuse_payment(request):
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def ipn(request):
|
def ipn(request):
|
||||||
option, _created = AssoOption.objects.get_or_create()
|
|
||||||
p = ComnpayPayment()
|
p = ComnpayPayment()
|
||||||
order = ('idTpe', 'idTransaction', 'montant', 'result', 'sec', )
|
order = ('idTpe', 'idTransaction', 'montant', 'result', 'sec', )
|
||||||
try:
|
try:
|
||||||
|
@ -46,7 +45,7 @@ def ipn(request):
|
||||||
except MultiValueDictKeyError:
|
except MultiValueDictKeyError:
|
||||||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
||||||
|
|
||||||
if not p.validSec(data, option.payment_pass):
|
if not p.validSec(data, AssoOption.get_cached_value('payment_pass')):
|
||||||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
||||||
|
|
||||||
result = True if (request.POST['result'] == 'OK') else False
|
result = True if (request.POST['result'] == 'OK') else False
|
||||||
|
@ -54,7 +53,7 @@ def ipn(request):
|
||||||
idTransaction = request.POST['idTransaction']
|
idTransaction = request.POST['idTransaction']
|
||||||
|
|
||||||
# On vérifie que le paiement nous est destiné
|
# On vérifie que le paiement nous est destiné
|
||||||
if not idTpe == option.payment_id:
|
if not idTpe == AssoOption.get_cached_value('payment_id'):
|
||||||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -81,10 +80,9 @@ def ipn(request):
|
||||||
|
|
||||||
def comnpay(facture, request):
|
def comnpay(facture, request):
|
||||||
host = request.get_host()
|
host = request.get_host()
|
||||||
option, _created = AssoOption.objects.get_or_create()
|
|
||||||
p = ComnpayPayment(
|
p = ComnpayPayment(
|
||||||
str(option.payment_id),
|
str(AssoOption.get_cached_value('payment_id')),
|
||||||
str(option.payment_pass),
|
str(AssoOption.get_cached_value('payment_pass')),
|
||||||
'https://' + host + reverse(
|
'https://' + host + reverse(
|
||||||
'cotisations:accept_payment',
|
'cotisations:accept_payment',
|
||||||
kwargs={'factureid':facture.id}
|
kwargs={'factureid':facture.id}
|
||||||
|
|
|
@ -106,9 +106,8 @@ def new_facture(request, user, userid):
|
||||||
articles = article_formset
|
articles = article_formset
|
||||||
# Si au moins un article est rempli
|
# Si au moins un article est rempli
|
||||||
if any(art.cleaned_data for art in articles):
|
if any(art.cleaned_data for art in articles):
|
||||||
options, _created = OptionalUser.objects.get_or_create()
|
user_solde = OptionalUser.get_cached_value('user_solde')
|
||||||
user_solde = options.user_solde
|
solde_negatif = OptionalUser.get_cached_value('solde_negatif')
|
||||||
solde_negatif = options.solde_negatif
|
|
||||||
# Si on paye par solde, que l'option est activée,
|
# Si on paye par solde, que l'option est activée,
|
||||||
# on vérifie que le négatif n'est pas atteint
|
# on vérifie que le négatif n'est pas atteint
|
||||||
if user_solde:
|
if user_solde:
|
||||||
|
@ -181,7 +180,6 @@ def new_facture_pdf(request):
|
||||||
Vente ou Facture correspondant en bdd"""
|
Vente ou Facture correspondant en bdd"""
|
||||||
facture_form = NewFactureFormPdf(request.POST or None)
|
facture_form = NewFactureFormPdf(request.POST or None)
|
||||||
if facture_form.is_valid():
|
if facture_form.is_valid():
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
|
||||||
tbl = []
|
tbl = []
|
||||||
article = facture_form.cleaned_data['article']
|
article = facture_form.cleaned_data['article']
|
||||||
quantite = facture_form.cleaned_data['number']
|
quantite = facture_form.cleaned_data['number']
|
||||||
|
@ -200,12 +198,12 @@ def new_facture_pdf(request):
|
||||||
'article': tbl,
|
'article': tbl,
|
||||||
'total': prix_total,
|
'total': prix_total,
|
||||||
'paid': paid,
|
'paid': paid,
|
||||||
'asso_name': options.name,
|
'asso_name': AssoOption.get_cached_value('name'),
|
||||||
'line1': options.adresse1,
|
'line1': AssoOption.get_cached_value('adresse1'),
|
||||||
'line2': options.adresse2,
|
'line2': AssoOption.get_cached_value('adresse2'),
|
||||||
'siret': options.siret,
|
'siret': AssoOption.get_cached_value('siret'),
|
||||||
'email': options.contact,
|
'email': AssoOption.get_cached_value('contact'),
|
||||||
'phone': options.telephone,
|
'phone': AssoOption.get_cached_value('telephone'),
|
||||||
'tpl_path': os.path.join(settings.BASE_DIR, LOGO_PATH)
|
'tpl_path': os.path.join(settings.BASE_DIR, LOGO_PATH)
|
||||||
})
|
})
|
||||||
return form({
|
return form({
|
||||||
|
@ -223,7 +221,6 @@ def facture_pdf(request, facture, factureid):
|
||||||
|
|
||||||
ventes_objects = Vente.objects.all().filter(facture=facture)
|
ventes_objects = Vente.objects.all().filter(facture=facture)
|
||||||
ventes = []
|
ventes = []
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
|
||||||
for vente in ventes_objects:
|
for vente in ventes_objects:
|
||||||
ventes.append([vente, vente.number, vente.prix_total])
|
ventes.append([vente, vente.number, vente.prix_total])
|
||||||
return render_invoice(request, {
|
return render_invoice(request, {
|
||||||
|
@ -233,12 +230,12 @@ def facture_pdf(request, facture, factureid):
|
||||||
'dest': facture.user,
|
'dest': facture.user,
|
||||||
'article': ventes,
|
'article': ventes,
|
||||||
'total': facture.prix_total(),
|
'total': facture.prix_total(),
|
||||||
'asso_name': options.name,
|
'asso_name': AssoOption.get_cached_value('name'),
|
||||||
'line1': options.adresse1,
|
'line1': AssoOption.get_cached_value('adresse1'),
|
||||||
'line2': options.adresse2,
|
'line2': AssoOption.get_cached_value('adresse2'),
|
||||||
'siret': options.siret,
|
'siret': AssoOption.get_cached_value('siret'),
|
||||||
'email': options.contact,
|
'email': AssoOption.get_cached_value('contact'),
|
||||||
'phone': options.telephone,
|
'phone': AssoOption.get_cached_value('telephone'),
|
||||||
'tpl_path': os.path.join(settings.BASE_DIR, LOGO_PATH)
|
'tpl_path': os.path.join(settings.BASE_DIR, LOGO_PATH)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -498,8 +495,7 @@ def del_banque(request, instances):
|
||||||
def control(request):
|
def control(request):
|
||||||
"""Pour le trésorier, vue pour controler en masse les
|
"""Pour le trésorier, vue pour controler en masse les
|
||||||
factures.Case à cocher, pratique"""
|
factures.Case à cocher, pratique"""
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
facture_list = Facture.objects.select_related('user').select_related('paiement')
|
facture_list = Facture.objects.select_related('user').select_related('paiement')
|
||||||
facture_list = SortTable.sort(
|
facture_list = SortTable.sort(
|
||||||
facture_list,
|
facture_list,
|
||||||
|
@ -567,8 +563,7 @@ def index_banque(request):
|
||||||
@can_view_all(Facture)
|
@can_view_all(Facture)
|
||||||
def index(request):
|
def index(request):
|
||||||
"""Affiche l'ensemble des factures, pour les cableurs et +"""
|
"""Affiche l'ensemble des factures, pour les cableurs et +"""
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
facture_list = Facture.objects.select_related('user')\
|
facture_list = Facture.objects.select_related('user')\
|
||||||
.select_related('paiement').prefetch_related('vente_set')
|
.select_related('paiement').prefetch_related('vente_set')
|
||||||
facture_list = SortTable.sort(
|
facture_list = SortTable.sort(
|
||||||
|
@ -617,9 +612,8 @@ def new_facture_solde(request, userid):
|
||||||
articles = article_formset
|
articles = article_formset
|
||||||
# Si au moins un article est rempli
|
# Si au moins un article est rempli
|
||||||
if any(art.cleaned_data for art in articles):
|
if any(art.cleaned_data for art in articles):
|
||||||
options, _created = OptionalUser.objects.get_or_create()
|
user_solde = OptionalUser.get_cached_value('user_solde')
|
||||||
user_solde = options.user_solde
|
solde_negatif = OptionalUser.get_cached_value('solde_negatif')
|
||||||
solde_negatif = options.solde_negatif
|
|
||||||
# Si on paye par solde, que l'option est activée,
|
# Si on paye par solde, que l'option est activée,
|
||||||
# on vérifie que le négatif n'est pas atteint
|
# on vérifie que le négatif n'est pas atteint
|
||||||
if user_solde:
|
if user_solde:
|
||||||
|
@ -687,8 +681,7 @@ def new_facture_solde(request, userid):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def recharge(request):
|
def recharge(request):
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
if AssoOption.get_cached_value('payment') == 'NONE':
|
||||||
if options.payment == 'NONE':
|
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
"Le paiement en ligne est désactivé."
|
"Le paiement en ligne est désactivé."
|
||||||
|
@ -711,6 +704,6 @@ def recharge(request):
|
||||||
number=1,
|
number=1,
|
||||||
)
|
)
|
||||||
v.save()
|
v.save()
|
||||||
content = payment.PAYMENT_SYSTEM[options.payment](facture, request)
|
content = payment.PAYMENT_SYSTEM[AssoOption.get_cached_value('payment')](facture, request)
|
||||||
return render(request, 'cotisations/payment.html', content)
|
return render(request, 'cotisations/payment.html', content)
|
||||||
return form({'rechargeform':f}, 'cotisations/recharge.html', request)
|
return form({'rechargeform':f}, 'cotisations/recharge.html', request)
|
||||||
|
|
|
@ -121,8 +121,7 @@ STATS_DICT = {
|
||||||
def index(request):
|
def index(request):
|
||||||
"""Affiche les logs affinés, date reformatées, selectionne
|
"""Affiche les logs affinés, date reformatées, selectionne
|
||||||
les event importants (ajout de droits, ajout de ban/whitelist)"""
|
les event importants (ajout de droits, ajout de ban/whitelist)"""
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
# The types of content kept for display
|
# The types of content kept for display
|
||||||
content_type_filter = ['ban', 'whitelist', 'vente', 'interface', 'user']
|
content_type_filter = ['ban', 'whitelist', 'vente', 'interface', 'user']
|
||||||
# Select only wanted versions
|
# Select only wanted versions
|
||||||
|
@ -180,8 +179,7 @@ def index(request):
|
||||||
def stats_logs(request):
|
def stats_logs(request):
|
||||||
"""Affiche l'ensemble des logs et des modifications sur les objets,
|
"""Affiche l'ensemble des logs et des modifications sur les objets,
|
||||||
classés par date croissante, en vrac"""
|
classés par date croissante, en vrac"""
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
revisions = Revision.objects.all().select_related('user')\
|
revisions = Revision.objects.all().select_related('user')\
|
||||||
.prefetch_related('version_set__object')
|
.prefetch_related('version_set__object')
|
||||||
revisions = SortTable.sort(
|
revisions = SortTable.sort(
|
||||||
|
|
21
machines/migrations/0076_auto_20180130_1623.py
Normal file
21
machines/migrations/0076_auto_20180130_1623.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-01-30 15:23
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('machines', '0075_auto_20180130_0052'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='ipv6list',
|
||||||
|
name='interface',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ipv6list', to='machines.Interface'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -94,8 +94,7 @@ class Machine(FieldPermissionModelMixin, models.Model):
|
||||||
user = users.models.User.objects.get(pk=userid)
|
user = users.models.User.objects.get(pk=userid)
|
||||||
except users.models.User.DoesNotExist:
|
except users.models.User.DoesNotExist:
|
||||||
return False, u"Utilisateur inexistant"
|
return False, u"Utilisateur inexistant"
|
||||||
options, created = preferences.models.OptionalMachine.objects.get_or_create()
|
max_lambdauser_interfaces = preferences.models.OptionalMachine.get_cached_value('max_lambdauser_interfaces')
|
||||||
max_lambdauser_interfaces = options.max_lambdauser_interfaces
|
|
||||||
if not user_request.has_perm('machines.add_machine'):
|
if not user_request.has_perm('machines.add_machine'):
|
||||||
if user != user_request:
|
if user != user_request:
|
||||||
return False, u"Vous ne pouvez pas ajouter une machine à un\
|
return False, u"Vous ne pouvez pas ajouter une machine à un\
|
||||||
|
@ -1244,10 +1243,9 @@ class Interface(FieldPermissionModelMixin,models.Model):
|
||||||
|
|
||||||
def sync_ipv6(self):
|
def sync_ipv6(self):
|
||||||
"""Cree et met à jour l'ensemble des ipv6 en fonction du mode choisi"""
|
"""Cree et met à jour l'ensemble des ipv6 en fonction du mode choisi"""
|
||||||
machine_options, _created = preferences.models.OptionalMachine.objects.get_or_create()
|
if preferences.models.OptionalMachine.get_cached_value('ipv6_mode') == 'SLAAC':
|
||||||
if machine_options.ipv6_mode == 'SLAAC':
|
|
||||||
self.sync_ipv6_slaac()
|
self.sync_ipv6_slaac()
|
||||||
elif machine_options.ipv6_mode == 'DHCPV6':
|
elif preferences.models.OptionalMachine.get_cached_value('ipv6_mode') == 'DHCPV6':
|
||||||
self.sync_ipv6_dhcpv6()
|
self.sync_ipv6_dhcpv6()
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
@ -1255,11 +1253,10 @@ class Interface(FieldPermissionModelMixin,models.Model):
|
||||||
def ipv6(self):
|
def ipv6(self):
|
||||||
""" Renvoie le queryset de la liste des ipv6
|
""" Renvoie le queryset de la liste des ipv6
|
||||||
On renvoie l'ipv6 slaac que si le mode slaac est activé (et non dhcpv6)"""
|
On renvoie l'ipv6 slaac que si le mode slaac est activé (et non dhcpv6)"""
|
||||||
machine_options, _created = preferences.models.OptionalMachine.objects.get_or_create()
|
if preferences.models.OptionalMachine.get_cached_value('ipv6_mode') == 'SLAAC':
|
||||||
if machine_options.ipv6_mode == 'SLAAC':
|
return self.ipv6list.all()
|
||||||
return Ipv6List.objects.filter(interface=self)
|
elif preferences.models.OptionalMachine.get_cached_value('ipv6_mode') == 'DHCPV6':
|
||||||
elif machine_options.ipv6_mode == 'DHCPV6':
|
return self.ipv6list.filter(slaac_ip=False)
|
||||||
return Ipv6List.objects.filter(interface=self, slaac_ip=False)
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -1338,8 +1335,7 @@ class Interface(FieldPermissionModelMixin,models.Model):
|
||||||
except Machine.DoesNotExist:
|
except Machine.DoesNotExist:
|
||||||
return False, u"Machine inexistante"
|
return False, u"Machine inexistante"
|
||||||
if not user_request.has_perm('machines.add_interface'):
|
if not user_request.has_perm('machines.add_interface'):
|
||||||
options, created = preferences.models.OptionalMachine.objects.get_or_create()
|
max_lambdauser_interfaces = preferences.models.OptionalMachine.get_cached_value('max_lambdauser_interfaces')
|
||||||
max_lambdauser_interfaces = options.max_lambdauser_interfaces
|
|
||||||
if machine.user != user_request:
|
if machine.user != user_request:
|
||||||
return False, u"Vous ne pouvez pas ajouter une interface à une\
|
return False, u"Vous ne pouvez pas ajouter une interface à une\
|
||||||
machine d'un autre user que vous sans droit"
|
machine d'un autre user que vous sans droit"
|
||||||
|
@ -1432,7 +1428,7 @@ class Ipv6List(FieldPermissionModelMixin, models.Model):
|
||||||
protocol='IPv6',
|
protocol='IPv6',
|
||||||
unique=True
|
unique=True
|
||||||
)
|
)
|
||||||
interface = models.ForeignKey('Interface', on_delete=models.CASCADE)
|
interface = models.ForeignKey('Interface', on_delete=models.CASCADE, related_name='ipv6list')
|
||||||
slaac_ip = models.BooleanField(default=False)
|
slaac_ip = models.BooleanField(default=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1655,8 +1651,7 @@ class Domain(models.Model):
|
||||||
except Interface.DoesNotExist:
|
except Interface.DoesNotExist:
|
||||||
return False, u"Interface inexistante"
|
return False, u"Interface inexistante"
|
||||||
if not user_request.has_perm('machines.add_domain'):
|
if not user_request.has_perm('machines.add_domain'):
|
||||||
options, created = preferences.models.OptionalMachine.objects.get_or_create()
|
max_lambdauser_aliases = preferences.models.OptionalMachine.get_cached_value('max_lambdauser_aliases')
|
||||||
max_lambdauser_aliases = options.max_lambdauser_aliases
|
|
||||||
if interface.machine.user != user_request:
|
if interface.machine.user != user_request:
|
||||||
return False, u"Vous ne pouvez pas ajouter un alias à une\
|
return False, u"Vous ne pouvez pas ajouter un alias à une\
|
||||||
machine d'un autre user que vous sans droit"
|
machine d'un autre user que vous sans droit"
|
||||||
|
|
|
@ -981,9 +981,8 @@ def del_nas(request, instances):
|
||||||
@login_required
|
@login_required
|
||||||
@can_view_all(Machine)
|
@can_view_all(Machine)
|
||||||
def index(request):
|
def index(request):
|
||||||
options, created = GeneralOption.objects.get_or_create()
|
pagination_large_number = GeneralOption.get_cached_value('pagination_large_number')
|
||||||
pagination_large_number = options.pagination_large_number
|
machines_list = Machine.objects.select_related('user').prefetch_related('interface_set__domain__extension').prefetch_related('interface_set__ipv4__ip_type').prefetch_related('interface_set__type__ip_type__extension').prefetch_related('interface_set__domain__related_domain__extension').prefetch_related('interface_set__ipv6list')
|
||||||
machines_list = Machine.objects.select_related('user').prefetch_related('interface_set__domain__extension').prefetch_related('interface_set__ipv4__ip_type').prefetch_related('interface_set__type__ip_type__extension').prefetch_related('interface_set__domain__related_domain__extension')
|
|
||||||
machines_list = SortTable.sort(
|
machines_list = SortTable.sort(
|
||||||
machines_list,
|
machines_list,
|
||||||
request.GET.get('col'),
|
request.GET.get('col'),
|
||||||
|
@ -1166,7 +1165,7 @@ def mac_ip_list(request):
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('machines.serveur')
|
@permission_required('machines.serveur')
|
||||||
def full_mac_ip_list(request):
|
def full_mac_ip_list(request):
|
||||||
interfaces = all_active_assigned_interfaces()
|
interfaces = all_active_assigned_interfaces(full=True)
|
||||||
seria = FullInterfaceSerializer(interfaces, many=True)
|
seria = FullInterfaceSerializer(interfaces, many=True)
|
||||||
return seria.data
|
return seria.data
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import cotisations.models
|
||||||
import machines.models
|
import machines.models
|
||||||
from django.db.models.signals import post_save, post_delete
|
from django.db.models.signals import post_save, post_delete
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
from django.core.cache import cache
|
||||||
|
|
||||||
from .aes_field import AESEncryptedField
|
from .aes_field import AESEncryptedField
|
||||||
|
|
||||||
|
@ -67,6 +68,19 @@ class OptionalUser(models.Model):
|
||||||
help_text="Un nouvel utilisateur peut se créer son compte sur re2o"
|
help_text="Un nouvel utilisateur peut se créer son compte sur re2o"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_in_cache(cls):
|
||||||
|
optionaluser, _created = cls.objects.get_or_create()
|
||||||
|
cache.set('optionaluser', optionaluser, None)
|
||||||
|
return optionaluser
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_cached_value(cls, key):
|
||||||
|
optionaluser = cache.get('optionaluser')
|
||||||
|
if optionaluser == None:
|
||||||
|
optionaluser = cls.set_in_cache()
|
||||||
|
return getattr(optionaluser, key)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
("view_optionaluser", "Peut voir les options de l'user"),
|
("view_optionaluser", "Peut voir les options de l'user"),
|
||||||
|
@ -133,6 +147,13 @@ class OptionalUser(models.Model):
|
||||||
c.save()
|
c.save()
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=OptionalUser)
|
||||||
|
def optionaluser_post_save(sender, **kwargs):
|
||||||
|
"""Ecriture dans le cache"""
|
||||||
|
user_pref = kwargs['instance']
|
||||||
|
user_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class OptionalMachine(models.Model):
|
class OptionalMachine(models.Model):
|
||||||
"""Options pour les machines : maximum de machines ou d'alias par user
|
"""Options pour les machines : maximum de machines ou d'alias par user
|
||||||
sans droit, activation de l'ipv6"""
|
sans droit, activation de l'ipv6"""
|
||||||
|
@ -158,7 +179,20 @@ class OptionalMachine(models.Model):
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def ipv6(self):
|
def ipv6(self):
|
||||||
return not self.ipv6_mode == 'DISABLED'
|
return not self.get_cached_value('ipv6_mode') == 'DISABLED'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_in_cache(cls):
|
||||||
|
optionalmachine, _created = cls.objects.get_or_create()
|
||||||
|
cache.set('optionalmachine', optionalmachine, None)
|
||||||
|
return optionalmachine
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_cached_value(cls, key):
|
||||||
|
optionalmachine = cache.get('optionalmachine')
|
||||||
|
if optionalmachine == None:
|
||||||
|
optionalmachine = cls.set_in_cache()
|
||||||
|
return getattr(optionalmachine, key)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
@ -220,9 +254,10 @@ class OptionalMachine(models.Model):
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=OptionalMachine)
|
@receiver(post_save, sender=OptionalMachine)
|
||||||
def interface_post_save(sender, **kwargs):
|
def optionalmachine_post_save(sender, **kwargs):
|
||||||
"""Synchronisation ipv6"""
|
"""Synchronisation ipv6 et ecriture dans le cache"""
|
||||||
machine_pref = kwargs['instance']
|
machine_pref = kwargs['instance']
|
||||||
|
machine_pref.set_in_cache()
|
||||||
if machine_pref.ipv6_mode != "DISABLED":
|
if machine_pref.ipv6_mode != "DISABLED":
|
||||||
for interface in machines.models.Interface.objects.all():
|
for interface in machines.models.Interface.objects.all():
|
||||||
interface.sync_ipv6()
|
interface.sync_ipv6()
|
||||||
|
@ -260,6 +295,19 @@ class OptionalTopologie(models.Model):
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_in_cache(cls):
|
||||||
|
optionaltopologie, _created = cls.objects.get_or_create()
|
||||||
|
cache.set('optionaltopologie', optionaltopologie, None)
|
||||||
|
return optionaltopologie
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_cached_value(cls, key):
|
||||||
|
optionaltopologie = cache.get('optionaltopologie')
|
||||||
|
if optionaltopologie == None:
|
||||||
|
optionaltopologie = cls.set_in_cache()
|
||||||
|
return getattr(optionaltopologie, key)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
("view_optionaltopologie", "Peut voir les options de topologie"),
|
("view_optionaltopologie", "Peut voir les options de topologie"),
|
||||||
|
@ -318,6 +366,13 @@ class OptionalTopologie(models.Model):
|
||||||
de voir les préférences concernant la topologie"
|
de voir les préférences concernant la topologie"
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=OptionalTopologie)
|
||||||
|
def optionaltopologie_post_save(sender, **kwargs):
|
||||||
|
"""Ecriture dans le cache"""
|
||||||
|
topologie_pref = kwargs['instance']
|
||||||
|
topologie_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class GeneralOption(models.Model):
|
class GeneralOption(models.Model):
|
||||||
"""Options générales : nombre de resultats par page, nom du site,
|
"""Options générales : nombre de resultats par page, nom du site,
|
||||||
temps où les liens sont valides"""
|
temps où les liens sont valides"""
|
||||||
|
@ -345,6 +400,19 @@ class GeneralOption(models.Model):
|
||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_in_cache(cls):
|
||||||
|
generaloption, _created = cls.objects.get_or_create()
|
||||||
|
cache.set('generaloption', generaloption, None)
|
||||||
|
return generaloption
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_cached_value(cls, key):
|
||||||
|
generaloption = cache.get('generaloption')
|
||||||
|
if generaloption == None:
|
||||||
|
generaloption = cls.set_in_cache()
|
||||||
|
return getattr(generaloption, key)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
("view_generaloption", "Peut voir les options générales"),
|
("view_generaloption", "Peut voir les options générales"),
|
||||||
|
@ -404,6 +472,13 @@ class GeneralOption(models.Model):
|
||||||
de voir les préférences générales"
|
de voir les préférences générales"
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=GeneralOption)
|
||||||
|
def generaloption_post_save(sender, **kwargs):
|
||||||
|
"""Ecriture dans le cache"""
|
||||||
|
general_pref = kwargs['instance']
|
||||||
|
general_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class Service(models.Model):
|
class Service(models.Model):
|
||||||
"""Liste des services affichés sur la page d'accueil : url, description,
|
"""Liste des services affichés sur la page d'accueil : url, description,
|
||||||
image et nom"""
|
image et nom"""
|
||||||
|
@ -513,6 +588,18 @@ class AssoOption(models.Model):
|
||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_in_cache(cls):
|
||||||
|
assooption, _created = cls.objects.get_or_create()
|
||||||
|
cache.set('assooption', assooption, None)
|
||||||
|
return assooption
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_cached_value(cls, key):
|
||||||
|
assooption = cache.get('assooption')
|
||||||
|
if assooption == None:
|
||||||
|
assooption = cls.set_in_cache()
|
||||||
|
return getattr(assooption, key)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
@ -572,6 +659,13 @@ class AssoOption(models.Model):
|
||||||
de voir les préférences concernant l'association"
|
de voir les préférences concernant l'association"
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=AssoOption)
|
||||||
|
def assooption_post_save(sender, **kwargs):
|
||||||
|
"""Ecriture dans le cache"""
|
||||||
|
asso_pref = kwargs['instance']
|
||||||
|
asso_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class MailMessageOption(models.Model):
|
class MailMessageOption(models.Model):
|
||||||
"""Reglages, mail de bienvenue et autre"""
|
"""Reglages, mail de bienvenue et autre"""
|
||||||
PRETTY_NAME = "Options de corps de mail"
|
PRETTY_NAME = "Options de corps de mail"
|
||||||
|
|
|
@ -45,7 +45,6 @@ def can_create(model):
|
||||||
def decorator(view):
|
def decorator(view):
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
can, msg = model.can_create(request.user, *args, **kwargs)
|
can, msg = model.can_create(request.user, *args, **kwargs)
|
||||||
#options, _created = OptionalUser.objects.get_or_create()
|
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
|
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
|
||||||
return redirect(reverse('index'))
|
return redirect(reverse('index'))
|
||||||
|
|
|
@ -31,10 +31,8 @@ from preferences.models import GeneralOption, OptionalMachine
|
||||||
def context_user(request):
|
def context_user(request):
|
||||||
"""Fonction de context lorsqu'un user est logué (ou non),
|
"""Fonction de context lorsqu'un user est logué (ou non),
|
||||||
renvoie les infos sur l'user, la liste de ses droits, ses machines"""
|
renvoie les infos sur l'user, la liste de ses droits, ses machines"""
|
||||||
general_options, _created = GeneralOption.objects.get_or_create()
|
|
||||||
machine_options, _created = OptionalMachine.objects.get_or_create()
|
|
||||||
user = request.user
|
user = request.user
|
||||||
global_message = general_options.general_message
|
global_message = GeneralOption.get_cached_value('general_message')
|
||||||
if global_message:
|
if global_message:
|
||||||
messages.warning(request, global_message)
|
messages.warning(request, global_message)
|
||||||
if user.is_authenticated():
|
if user.is_authenticated():
|
||||||
|
@ -44,6 +42,6 @@ def context_user(request):
|
||||||
return {
|
return {
|
||||||
'request_user': user,
|
'request_user': user,
|
||||||
'interfaces': interfaces,
|
'interfaces': interfaces,
|
||||||
'site_name': general_options.site_name,
|
'site_name': GeneralOption.get_cached_value('site_name'),
|
||||||
'ipv6_enabled': machine_options.ipv6,
|
'ipv6_enabled': OptionalMachine.get_cached_value('ipv6'),
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,15 +121,23 @@ def filter_active_interfaces(interface_set):
|
||||||
.distinct()
|
.distinct()
|
||||||
|
|
||||||
|
|
||||||
def all_active_interfaces():
|
def filter_complete_interfaces(interface_set):
|
||||||
|
"""Appel la fonction précédente avec un prefetch_related ipv6 en plus"""
|
||||||
|
return filter_active_interfaces(interface_set).prefetch_related('ipv6list')
|
||||||
|
|
||||||
|
|
||||||
|
def all_active_interfaces(full=False):
|
||||||
"""Renvoie l'ensemble des machines autorisées à sortir sur internet """
|
"""Renvoie l'ensemble des machines autorisées à sortir sur internet """
|
||||||
return filter_active_interfaces(Interface.objects)
|
if full:
|
||||||
|
return filter_complete_interfaces(Interface.objects)
|
||||||
|
else:
|
||||||
|
return filter_active_interfaces(Interface.objects)
|
||||||
|
|
||||||
|
|
||||||
def all_active_assigned_interfaces():
|
def all_active_assigned_interfaces(full=False):
|
||||||
""" Renvoie l'ensemble des machines qui ont une ipv4 assignées et
|
""" Renvoie l'ensemble des machines qui ont une ipv4 assignées et
|
||||||
disposant de l'accès internet"""
|
disposant de l'accès internet"""
|
||||||
return all_active_interfaces().filter(ipv4__isnull=False)
|
return all_active_interfaces(full=full).filter(ipv4__isnull=False)
|
||||||
|
|
||||||
|
|
||||||
def all_active_interfaces_count():
|
def all_active_interfaces_count():
|
||||||
|
|
|
@ -136,8 +136,7 @@ def history(request, application, object_name, object_id):
|
||||||
'users:profil',
|
'users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid':str(request.user.id)}
|
||||||
))
|
))
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
reversions = Version.objects.get_for_object(instance)
|
reversions = Version.objects.get_for_object(instance)
|
||||||
paginator = Paginator(reversions, pagination_number)
|
paginator = Paginator(reversions, pagination_number)
|
||||||
page = request.GET.get('page')
|
page = request.GET.get('page')
|
||||||
|
|
|
@ -111,8 +111,7 @@ def finish_results(results, col, order):
|
||||||
SortTable.TOPOLOGIE_INDEX
|
SortTable.TOPOLOGIE_INDEX
|
||||||
)
|
)
|
||||||
|
|
||||||
options, _ = GeneralOption.objects.get_or_create()
|
max_result = GeneralOption.get_cached_value('search_display_page')
|
||||||
max_result = options.search_display_page
|
|
||||||
for name, val in results.items():
|
for name, val in results.items():
|
||||||
results[name] = val.distinct()[:max_result]
|
results[name] = val.distinct()[:max_result]
|
||||||
results.update({'max_result': max_result})
|
results.update({'max_result': max_result})
|
||||||
|
|
|
@ -99,8 +99,7 @@ def index(request):
|
||||||
request.GET.get('order'),
|
request.GET.get('order'),
|
||||||
SortTable.TOPOLOGIE_INDEX
|
SortTable.TOPOLOGIE_INDEX
|
||||||
)
|
)
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
paginator = Paginator(switch_list, pagination_number)
|
paginator = Paginator(switch_list, pagination_number)
|
||||||
page = request.GET.get('page')
|
page = request.GET.get('page')
|
||||||
try:
|
try:
|
||||||
|
@ -153,8 +152,7 @@ def index_room(request):
|
||||||
request.GET.get('order'),
|
request.GET.get('order'),
|
||||||
SortTable.TOPOLOGIE_INDEX_ROOM
|
SortTable.TOPOLOGIE_INDEX_ROOM
|
||||||
)
|
)
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
paginator = Paginator(room_list, pagination_number)
|
paginator = Paginator(room_list, pagination_number)
|
||||||
page = request.GET.get('page')
|
page = request.GET.get('page')
|
||||||
try:
|
try:
|
||||||
|
@ -192,7 +190,7 @@ def index_stack(request):
|
||||||
@can_view_all(ConstructorSwitch)
|
@can_view_all(ConstructorSwitch)
|
||||||
def index_model_switch(request):
|
def index_model_switch(request):
|
||||||
""" Affichage de l'ensemble des modèles de switches"""
|
""" Affichage de l'ensemble des modèles de switches"""
|
||||||
model_switch_list = ModelSwitch.objects
|
model_switch_list = ModelSwitch.objects.select_related('constructor')
|
||||||
constructor_switch_list = ConstructorSwitch.objects
|
constructor_switch_list = ConstructorSwitch.objects
|
||||||
model_switch_list = SortTable.sort(
|
model_switch_list = SortTable.sort(
|
||||||
model_switch_list,
|
model_switch_list,
|
||||||
|
@ -366,8 +364,7 @@ def new_switch(request):
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
)
|
)
|
||||||
if switch.is_valid() and machine.is_valid() and interface.is_valid():
|
if switch.is_valid() and machine.is_valid() and interface.is_valid():
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
user = AssoOption.get_cached_value('utilisateur_asso')
|
||||||
user = options.utilisateur_asso
|
|
||||||
if not user:
|
if not user:
|
||||||
messages.error(request, "L'user association n'existe pas encore,\
|
messages.error(request, "L'user association n'existe pas encore,\
|
||||||
veuillez le créer ou le linker dans preferences")
|
veuillez le créer ou le linker dans preferences")
|
||||||
|
|
|
@ -289,8 +289,7 @@ class AdherentForm(FieldPermissionFormMixin, ModelForm):
|
||||||
"""Verifie que le tel est présent si 'option est validée
|
"""Verifie que le tel est présent si 'option est validée
|
||||||
dans preferences"""
|
dans preferences"""
|
||||||
telephone = self.cleaned_data['telephone']
|
telephone = self.cleaned_data['telephone']
|
||||||
preferences, _created = OptionalUser.objects.get_or_create()
|
if not telephone and OptionalUser.get_cached_value('is_tel_mandatory'):
|
||||||
if not telephone and preferences.is_tel_mandatory:
|
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
"Un numéro de téléphone valide est requis"
|
"Un numéro de téléphone valide est requis"
|
||||||
)
|
)
|
||||||
|
@ -341,8 +340,7 @@ class ClubForm(FieldPermissionFormMixin, ModelForm):
|
||||||
"""Verifie que le tel est présent si 'option est validée
|
"""Verifie que le tel est présent si 'option est validée
|
||||||
dans preferences"""
|
dans preferences"""
|
||||||
telephone = self.cleaned_data['telephone']
|
telephone = self.cleaned_data['telephone']
|
||||||
preferences, _created = OptionalUser.objects.get_or_create()
|
if not telephone and OptionalUser.get_cached_value('is_tel_mandatory'):
|
||||||
if not telephone and preferences.is_tel_mandatory:
|
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
"Un numéro de téléphone valide est requis"
|
"Un numéro de téléphone valide est requis"
|
||||||
)
|
)
|
||||||
|
@ -443,7 +441,7 @@ class ListRightForm(ModelForm):
|
||||||
"""Edition, d'un groupe , équivalent à un droit
|
"""Edition, d'un groupe , équivalent à un droit
|
||||||
Ne peremet pas d'editer le gid, car il sert de primary key"""
|
Ne peremet pas d'editer le gid, car il sert de primary key"""
|
||||||
permissions = forms.ModelMultipleChoiceField(
|
permissions = forms.ModelMultipleChoiceField(
|
||||||
Permission.objects.all(),
|
Permission.objects.all().select_related('content_type'),
|
||||||
widget=forms.CheckboxSelectMultiple,
|
widget=forms.CheckboxSelectMultiple,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
|
|
@ -406,8 +406,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
""" Renvoie le solde d'un user. Vérifie que l'option solde est
|
""" Renvoie le solde d'un user. Vérifie que l'option solde est
|
||||||
activé, retourne 0 sinon.
|
activé, retourne 0 sinon.
|
||||||
Somme les crédits de solde et retire les débit payés par solde"""
|
Somme les crédits de solde et retire les débit payés par solde"""
|
||||||
options, _created = OptionalUser.objects.get_or_create()
|
user_solde = OptionalUser.get_cached_value('user_solde')
|
||||||
user_solde = options.user_solde
|
|
||||||
if user_solde:
|
if user_solde:
|
||||||
solde_objects = Paiement.objects.filter(moyen='Solde')
|
solde_objects = Paiement.objects.filter(moyen='Solde')
|
||||||
somme_debit = Vente.objects.filter(
|
somme_debit = Vente.objects.filter(
|
||||||
|
@ -531,24 +530,22 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
def notif_inscription(self):
|
def notif_inscription(self):
|
||||||
""" Prend en argument un objet user, envoie un mail de bienvenue """
|
""" Prend en argument un objet user, envoie un mail de bienvenue """
|
||||||
template = loader.get_template('users/email_welcome')
|
template = loader.get_template('users/email_welcome')
|
||||||
assooptions, _created = AssoOption.objects.get_or_create()
|
|
||||||
mailmessageoptions, _created = MailMessageOption\
|
mailmessageoptions, _created = MailMessageOption\
|
||||||
.objects.get_or_create()
|
.objects.get_or_create()
|
||||||
general_options, _created = GeneralOption.objects.get_or_create()
|
|
||||||
context = Context({
|
context = Context({
|
||||||
'nom': self.get_full_name(),
|
'nom': self.get_full_name(),
|
||||||
'asso_name': assooptions.name,
|
'asso_name': AssoOption.get_cached_value('name'),
|
||||||
'asso_email': assooptions.contact,
|
'asso_email': AssoOption.get_cached_value('contact'),
|
||||||
'welcome_mail_fr': mailmessageoptions.welcome_mail_fr,
|
'welcome_mail_fr': mailmessageoptions.welcome_mail_fr,
|
||||||
'welcome_mail_en': mailmessageoptions.welcome_mail_en,
|
'welcome_mail_en': mailmessageoptions.welcome_mail_en,
|
||||||
'pseudo': self.pseudo,
|
'pseudo': self.pseudo,
|
||||||
})
|
})
|
||||||
send_mail(
|
send_mail(
|
||||||
'Bienvenue au %(name)s / Welcome to %(name)s' % {
|
'Bienvenue au %(name)s / Welcome to %(name)s' % {
|
||||||
'name': assooptions.name
|
'name': AssoOption.get_cached_value('name')
|
||||||
},
|
},
|
||||||
'',
|
'',
|
||||||
general_options.email_from,
|
GeneralOption.get_cached_value('email_from'),
|
||||||
[self.email],
|
[self.email],
|
||||||
html_message=template.render(context)
|
html_message=template.render(context)
|
||||||
)
|
)
|
||||||
|
@ -562,22 +559,20 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
req.user = self
|
req.user = self
|
||||||
req.save()
|
req.save()
|
||||||
template = loader.get_template('users/email_passwd_request')
|
template = loader.get_template('users/email_passwd_request')
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
|
||||||
general_options, _created = GeneralOption.objects.get_or_create()
|
|
||||||
context = {
|
context = {
|
||||||
'name': req.user.get_full_name(),
|
'name': req.user.get_full_name(),
|
||||||
'asso': options.name,
|
'asso': AssoOption.get_cached_value('name'),
|
||||||
'asso_mail': options.contact,
|
'asso_mail': AssoOption.get_cached_value('contact'),
|
||||||
'site_name': general_options.site_name,
|
'site_name': GeneralOption.get_cached_value('site_name'),
|
||||||
'url': request.build_absolute_uri(
|
'url': request.build_absolute_uri(
|
||||||
reverse('users:process', kwargs={'token': req.token})),
|
reverse('users:process', kwargs={'token': req.token})),
|
||||||
'expire_in': str(general_options.req_expire_hrs) + ' heures',
|
'expire_in': str(GeneralOption.get_cached_value('req_expire_hrs')) + ' heures',
|
||||||
}
|
}
|
||||||
send_mail(
|
send_mail(
|
||||||
'Changement de mot de passe du %(name)s / Password\
|
'Changement de mot de passe du %(name)s / Password\
|
||||||
renewal for %(name)s' % {'name': options.name},
|
renewal for %(name)s' % {'name': AssoOption.get_cached_value('name')},
|
||||||
template.render(context),
|
template.render(context),
|
||||||
general_options.email_from,
|
GeneralOption.get_cached_value('email_from'),
|
||||||
[req.user.email],
|
[req.user.email],
|
||||||
fail_silently=False
|
fail_silently=False
|
||||||
)
|
)
|
||||||
|
@ -587,8 +582,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
""" Fonction appellée par freeradius. Enregistre la mac pour
|
""" Fonction appellée par freeradius. Enregistre la mac pour
|
||||||
une machine inconnue sur le compte de l'user"""
|
une machine inconnue sur le compte de l'user"""
|
||||||
all_interfaces = self.user_interfaces(active=False)
|
all_interfaces = self.user_interfaces(active=False)
|
||||||
options, _created = OptionalMachine.objects.get_or_create()
|
if all_interfaces.count() > OptionalMachine.get_cached_value('max_lambdauser_interfaces'):
|
||||||
if all_interfaces.count() > options.max_lambdauser_interfaces:
|
|
||||||
return False, "Maximum de machines enregistrees atteinte"
|
return False, "Maximum de machines enregistrees atteinte"
|
||||||
if not nas_type:
|
if not nas_type:
|
||||||
return False, "Re2o ne sait pas à quel machinetype affecter cette\
|
return False, "Re2o ne sait pas à quel machinetype affecter cette\
|
||||||
|
@ -621,20 +615,18 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
"""Notification mail lorsque une machine est automatiquement
|
"""Notification mail lorsque une machine est automatiquement
|
||||||
ajoutée par le radius"""
|
ajoutée par le radius"""
|
||||||
template = loader.get_template('users/email_auto_newmachine')
|
template = loader.get_template('users/email_auto_newmachine')
|
||||||
assooptions, _created = AssoOption.objects.get_or_create()
|
|
||||||
general_options, _created = GeneralOption.objects.get_or_create()
|
|
||||||
context = Context({
|
context = Context({
|
||||||
'nom': self.get_full_name(),
|
'nom': self.get_full_name(),
|
||||||
'mac_address' : interface.mac_address,
|
'mac_address' : interface.mac_address,
|
||||||
'asso_name': assooptions.name,
|
'asso_name': AssoOption.get_cached_value('name'),
|
||||||
'interface_name' : interface.domain,
|
'interface_name' : interface.domain,
|
||||||
'asso_email': assooptions.contact,
|
'asso_email': AssoOption.get_cached_value('contact'),
|
||||||
'pseudo': self.pseudo,
|
'pseudo': self.pseudo,
|
||||||
})
|
})
|
||||||
send_mail(
|
send_mail(
|
||||||
"Ajout automatique d'une machine / New machine autoregistered",
|
"Ajout automatique d'une machine / New machine autoregistered",
|
||||||
'',
|
'',
|
||||||
general_options.email_from,
|
GeneralOption.get_cached_value('email_from'),
|
||||||
[self.email],
|
[self.email],
|
||||||
html_message=template.render(context)
|
html_message=template.render(context)
|
||||||
)
|
)
|
||||||
|
@ -683,11 +675,10 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
:return: a message and a boolean which is True if the user can create
|
:return: a message and a boolean which is True if the user can create
|
||||||
an user or if the `options.all_can_create` is set.
|
an user or if the `options.all_can_create` is set.
|
||||||
"""
|
"""
|
||||||
options, _created = OptionalUser.objects.get_or_create()
|
if(not user_request.is_authenticated and not OptionalUser.get_cached_value('self_adhesion')):
|
||||||
if(not user_request.is_authenticated and not options.self_adhesion):
|
|
||||||
return False, None
|
return False, None
|
||||||
else:
|
else:
|
||||||
if(options.all_can_create or options.self_adhesion):
|
if(OptionalUser.get_cached_value('all_can_create') or OptionalUser.get_cached_value('self_adhesion')):
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
return user_request.has_perm('users.add_user'), u"Vous n'avez pas le\
|
return user_request.has_perm('users.add_user'), u"Vous n'avez pas le\
|
||||||
|
@ -710,7 +701,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
else:
|
else:
|
||||||
return False, u"Vous n'avez pas le droit d'éditer ce club"
|
return False, u"Vous n'avez pas le droit d'éditer ce club"
|
||||||
else:
|
else:
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
|
||||||
if self == user_request:
|
if self == user_request:
|
||||||
return True, None
|
return True, None
|
||||||
elif user_request.has_perm('users.change_all_users'):
|
elif user_request.has_perm('users.change_all_users'):
|
||||||
|
@ -718,7 +708,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
elif user_request.has_perm('users.change_user'):
|
elif user_request.has_perm('users.change_user'):
|
||||||
if self.groups.filter(listright__critical=True):
|
if self.groups.filter(listright__critical=True):
|
||||||
return False, u"Utilisateurs avec droits critiques, ne peut etre édité"
|
return False, u"Utilisateurs avec droits critiques, ne peut etre édité"
|
||||||
elif self == options.utilisateur_asso:
|
elif self == AssoOption.get_cached_value('utilisateur_asso'):
|
||||||
return False, u"Impossible d'éditer l'utilisateur asso sans droit change_all_users"
|
return False, u"Impossible d'éditer l'utilisateur asso sans droit change_all_users"
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
@ -1265,19 +1255,17 @@ class Ban(models.Model):
|
||||||
|
|
||||||
def notif_ban(self):
|
def notif_ban(self):
|
||||||
""" Prend en argument un objet ban, envoie un mail de notification """
|
""" Prend en argument un objet ban, envoie un mail de notification """
|
||||||
general_options, _created = GeneralOption.objects.get_or_create()
|
|
||||||
template = loader.get_template('users/email_ban_notif')
|
template = loader.get_template('users/email_ban_notif')
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
|
||||||
context = Context({
|
context = Context({
|
||||||
'name': self.user.get_full_name(),
|
'name': self.user.get_full_name(),
|
||||||
'raison': self.raison,
|
'raison': self.raison,
|
||||||
'date_end': self.date_end,
|
'date_end': self.date_end,
|
||||||
'asso_name': options.name,
|
'asso_name': AssoOption.get_cached_value('name'),
|
||||||
})
|
})
|
||||||
send_mail(
|
send_mail(
|
||||||
'Deconnexion disciplinaire',
|
'Deconnexion disciplinaire',
|
||||||
template.render(context),
|
template.render(context),
|
||||||
general_options.email_from,
|
GeneralOption.get_cached_value('email_from'),
|
||||||
[self.user.email],
|
[self.user.email],
|
||||||
fail_silently=False
|
fail_silently=False
|
||||||
)
|
)
|
||||||
|
@ -1499,9 +1487,8 @@ class Request(models.Model):
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
if not self.expires_at:
|
if not self.expires_at:
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
|
||||||
self.expires_at = timezone.now() \
|
self.expires_at = timezone.now() \
|
||||||
+ datetime.timedelta(hours=options.req_expire_hrs)
|
+ datetime.timedelta(hours=GeneralOption.get_cached_value('req_expire_hrs'))
|
||||||
if not self.token:
|
if not self.token:
|
||||||
self.token = str(uuid.uuid4()).replace('-', '') # remove hyphens
|
self.token = str(uuid.uuid4()).replace('-', '') # remove hyphens
|
||||||
super(Request, self).save()
|
super(Request, self).save()
|
||||||
|
|
|
@ -122,9 +122,8 @@ def new_user(request):
|
||||||
""" Vue de création d'un nouvel utilisateur,
|
""" Vue de création d'un nouvel utilisateur,
|
||||||
envoie un mail pour le mot de passe"""
|
envoie un mail pour le mot de passe"""
|
||||||
user = AdherentForm(request.POST or None, user=request.user)
|
user = AdherentForm(request.POST or None, user=request.user)
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
GTU_sum_up = GeneralOption.get_cached_value('GTU_sum_up')
|
||||||
GTU_sum_up = options.GTU_sum_up
|
GTU = GeneralOption.get_cached_value('GTU')
|
||||||
GTU = options.GTU
|
|
||||||
if user.is_valid():
|
if user.is_valid():
|
||||||
user = user.save(commit=False)
|
user = user.save(commit=False)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
|
@ -595,8 +594,7 @@ def mass_archive(request):
|
||||||
@can_view_all(Adherent)
|
@can_view_all(Adherent)
|
||||||
def index(request):
|
def index(request):
|
||||||
""" Affiche l'ensemble des adherents, need droit cableur """
|
""" Affiche l'ensemble des adherents, need droit cableur """
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
users_list = Adherent.objects.select_related('room')
|
users_list = Adherent.objects.select_related('room')
|
||||||
users_list = SortTable.sort(
|
users_list = SortTable.sort(
|
||||||
users_list,
|
users_list,
|
||||||
|
@ -621,8 +619,7 @@ def index(request):
|
||||||
@can_view_all(Club)
|
@can_view_all(Club)
|
||||||
def index_clubs(request):
|
def index_clubs(request):
|
||||||
""" Affiche l'ensemble des clubs, need droit cableur """
|
""" Affiche l'ensemble des clubs, need droit cableur """
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
clubs_list = Club.objects.select_related('room')
|
clubs_list = Club.objects.select_related('room')
|
||||||
clubs_list = SortTable.sort(
|
clubs_list = SortTable.sort(
|
||||||
clubs_list,
|
clubs_list,
|
||||||
|
@ -647,8 +644,7 @@ def index_clubs(request):
|
||||||
@can_view_all(Ban)
|
@can_view_all(Ban)
|
||||||
def index_ban(request):
|
def index_ban(request):
|
||||||
""" Affiche l'ensemble des ban, need droit cableur """
|
""" Affiche l'ensemble des ban, need droit cableur """
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
ban_list = Ban.objects.select_related('user')
|
ban_list = Ban.objects.select_related('user')
|
||||||
ban_list = SortTable.sort(
|
ban_list = SortTable.sort(
|
||||||
ban_list,
|
ban_list,
|
||||||
|
@ -673,8 +669,7 @@ def index_ban(request):
|
||||||
@can_view_all(Whitelist)
|
@can_view_all(Whitelist)
|
||||||
def index_white(request):
|
def index_white(request):
|
||||||
""" Affiche l'ensemble des whitelist, need droit cableur """
|
""" Affiche l'ensemble des whitelist, need droit cableur """
|
||||||
options, _created = GeneralOption.objects.get_or_create()
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
pagination_number = options.pagination_number
|
|
||||||
white_list = Whitelist.objects.select_related('user')
|
white_list = Whitelist.objects.select_related('user')
|
||||||
white_list = SortTable.sort(
|
white_list = SortTable.sort(
|
||||||
white_list,
|
white_list,
|
||||||
|
@ -715,7 +710,8 @@ def index_school(request):
|
||||||
@can_view_all(ListRight)
|
@can_view_all(ListRight)
|
||||||
def index_listright(request):
|
def index_listright(request):
|
||||||
""" Affiche l'ensemble des droits , need droit cableur """
|
""" Affiche l'ensemble des droits , need droit cableur """
|
||||||
listright_list = ListRight.objects.order_by('unix_name')
|
listright_list = ListRight.objects.order_by('unix_name')\
|
||||||
|
.prefetch_related('permissions').prefetch_related('user_set')
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
'users/index_listright.html',
|
'users/index_listright.html',
|
||||||
|
@ -780,10 +776,8 @@ def profil(request, users, userid):
|
||||||
request.GET.get('order'),
|
request.GET.get('order'),
|
||||||
SortTable.USERS_INDEX_WHITE
|
SortTable.USERS_INDEX_WHITE
|
||||||
)
|
)
|
||||||
options, _created = OptionalUser.objects.get_or_create()
|
user_solde = OptionalUser.get_cached_value('user_solde')
|
||||||
user_solde = options.user_solde
|
allow_online_payment = AssoOption.get_cached_value('payment') != 'NONE'
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
|
||||||
allow_online_payment = options.payment != 'NONE'
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
'users/profil.html',
|
'users/profil.html',
|
||||||
|
|
Loading…
Reference in a new issue