8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-05 09:26:27 +00:00

Optimisation sur assooption et divers

This commit is contained in:
Gabriel Detraz 2018-01-31 03:27:59 +01:00 committed by root
parent 8015b27baa
commit a3c0a50f4a
7 changed files with 43 additions and 40 deletions

View file

@ -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}

View file

@ -180,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']
@ -199,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({
@ -222,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, {
@ -232,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)
}) })
@ -683,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é."
@ -707,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)

View file

@ -982,7 +982,7 @@ def del_nas(request, instances):
@can_view_all(Machine) @can_view_all(Machine)
def index(request): def index(request):
pagination_large_number = GeneralOption.get_cached_value('pagination_large_number') pagination_large_number = GeneralOption.get_cached_value('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') 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 = SortTable.sort( machines_list = SortTable.sort(
machines_list, machines_list,
request.GET.get('col'), request.GET.get('col'),

View file

@ -571,6 +571,19 @@ class AssoOption(models.Model):
blank=True, blank=True,
) )
@classmethod
def set_in_cache(cls, key):
machine_options, _created = cls.objects.get_or_create()
value = getattr(machine_options, key)
cache.set('assooption_' + key, value, None)
return value
@classmethod
def get_cached_value(cls, key):
value = cache.get('assooption_' + key)
if value == None:
value = cls.set_in_cache(key)
return value
class Meta: class Meta:
permissions = ( permissions = (

View file

@ -190,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,

View file

@ -530,20 +530,19 @@ 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()
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')
}, },
'', '',
GeneralOption.get_cached_value('email_from'), GeneralOption.get_cached_value('email_from'),
@ -560,11 +559,10 @@ 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()
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': GeneralOption.get_cached_value('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})),
@ -572,7 +570,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
} }
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),
GeneralOption.get_cached_value('email_from'), GeneralOption.get_cached_value('email_from'),
[req.user.email], [req.user.email],
@ -617,13 +615,12 @@ 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()
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(
@ -1260,12 +1257,11 @@ 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 """
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',

View file

@ -777,8 +777,7 @@ def profil(request, users, userid):
SortTable.USERS_INDEX_WHITE SortTable.USERS_INDEX_WHITE
) )
user_solde = OptionalUser.get_cached_value('user_solde') user_solde = OptionalUser.get_cached_value('user_solde')
options, _created = AssoOption.objects.get_or_create() allow_online_payment = AssoOption.get_cached_value('payment') != 'NONE'
allow_online_payment = options.payment != 'NONE'
return render( return render(
request, request,
'users/profil.html', 'users/profil.html',