8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 03:13:12 +00:00

Fix bug sur infra + optimisation avec selec_related sur le chargement pages

This commit is contained in:
chirac 2017-10-18 03:50:33 +02:00
parent 4adc6e8fc8
commit b635553132
11 changed files with 86 additions and 24 deletions

View file

@ -99,18 +99,18 @@ urlpatterns = [
views.index_paiement, views.index_paiement,
name='index-paiement' name='index-paiement'
), ),
url(r'^history/(?P<object>facture)/(?P<id>[0-9]+)$', url(r'^history/(?P<object_name>facture)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history' name='history'
), ),
url(r'^history/(?P<object>article)/(?P<id>[0-9]+)$', url(r'^history/(?P<object_name>article)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history' name='history'
), ),
url(r'^history/(?P<object>paiement)/(?P<id>[0-9]+)$', url(r'^history/(?P<object_name>paiement)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history'), name='history'),
url(r'^history/(?P<object>banque)/(?P<id>[0-9]+)$', url(r'^history/(?P<object_name>banque)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history' name='history'
), ),

View file

@ -603,9 +603,9 @@ def index(request):
@login_required @login_required
def history(request, object, object_id): def history(request, object_name, object_id):
"""Affiche l'historique de chaque objet""" """Affiche l'historique de chaque objet"""
if object == 'facture': if object_name == 'facture':
try: try:
object_instance = Facture.objects.get(pk=object_id) object_instance = Facture.objects.get(pk=object_id)
except Facture.DoesNotExist: except Facture.DoesNotExist:
@ -616,19 +616,19 @@ def history(request, object, object_id):
messages.error(request, "Vous ne pouvez pas afficher l'historique\ messages.error(request, "Vous ne pouvez pas afficher l'historique\
d'une facture d'un autre user que vous sans droit cableur") d'une facture d'un autre user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id)) return redirect("/users/profil/" + str(request.user.id))
elif object == 'paiement' and request.user.has_perms(('cableur',)): elif object_name == 'paiement' and request.user.has_perms(('cableur',)):
try: try:
object_instance = Paiement.objects.get(pk=object_id) object_instance = Paiement.objects.get(pk=object_id)
except Paiement.DoesNotExist: except Paiement.DoesNotExist:
messages.error(request, "Paiement inexistant") messages.error(request, "Paiement inexistant")
return redirect("/cotisations/") return redirect("/cotisations/")
elif object == 'article' and request.user.has_perms(('cableur',)): elif object_name == 'article' and request.user.has_perms(('cableur',)):
try: try:
object_instance = Article.objects.get(pk=object_id) object_instance = Article.objects.get(pk=object_id)
except Article.DoesNotExist: except Article.DoesNotExist:
messages.error(request, "Article inexistante") messages.error(request, "Article inexistante")
return redirect("/cotisations/") return redirect("/cotisations/")
elif object == 'banque' and request.user.has_perms(('cableur',)): elif object_name == 'banque' and request.user.has_perms(('cableur',)):
try: try:
object_instance = Banque.objects.get(pk=object_id) object_instance = Banque.objects.get(pk=object_id)
except Banque.DoesNotExist: except Banque.DoesNotExist:

View file

@ -1056,7 +1056,7 @@ def history(request, object, id):
@login_required @login_required
@permission_required('cableur') @permission_required('cableur')
def index_portlist(request): def index_portlist(request):
port_list = OuverturePortList.objects.prefetch_related('ouvertureport_set').prefetch_related('interface_set').order_by('name') port_list = OuverturePortList.objects.prefetch_related('ouvertureport_set').prefetch_related('interface_set__domain__extension').prefetch_related('interface_set__machine__user').order_by('name')
return render(request, "machines/index_portlist.html", {'port_list':port_list}) return render(request, "machines/index_portlist.html", {'port_list':port_list})
@login_required @login_required

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-10-15 15:41
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0020_optionalmachine_ipv6'),
]
operations = [
migrations.AlterField(
model_name='optionaltopologie',
name='radius_general_policy',
field=models.CharField(choices=[('MACHINE', 'Sur le vlan de la plage ip machine'), ('DEFINED', 'Prédéfini dans "Vlan où placer les machines après acceptation RADIUS"')], default='DEFINED', max_length=32),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-10-15 15:58
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0021_auto_20171015_1741'),
]
operations = [
migrations.AlterField(
model_name='optionaltopologie',
name='radius_general_policy',
field=models.CharField(choices=[('MACHINE', 'Sur le vlan de la plage ip machine'), ('DEFINED', 'Prédéfini dans "Vlan où placer les machines après acceptation RADIUS"')], default='DEFINED', max_length=32),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-10-15 18:33
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0022_auto_20171015_1758'),
]
operations = [
migrations.AlterField(
model_name='optionaltopologie',
name='radius_general_policy',
field=models.CharField(choices=[('MACHINE', 'Sur le vlan de la plage ip machine'), ('DEFINED', 'Prédéfini dans "Vlan où placer les machines après acceptation RADIUS"')], default='DEFINED', max_length=32),
),
]

View file

@ -69,7 +69,7 @@ urlpatterns = [
), ),
url(r'^del_services/$', views.del_services, name='del-services'), url(r'^del_services/$', views.del_services, name='del-services'),
url( url(
r'^history/(?P<object>service)/(?P<id>[0-9]+)$', r'^history/(?P<object_name>service)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history' name='history'
), ),

View file

@ -42,16 +42,16 @@ urlpatterns = [
url(r'^switch/(?P<switch_id>[0-9]+)$', url(r'^switch/(?P<switch_id>[0-9]+)$',
views.index_port, views.index_port,
name='index-port'), name='index-port'),
url(r'^history/(?P<object>switch)/(?P<id>[0-9]+)$', url(r'^history/(?P<object_name>switch)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history'), name='history'),
url(r'^history/(?P<object>port)/(?P<id>[0-9]+)$', url(r'^history/(?P<object_name>port)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history'), name='history'),
url(r'^history/(?P<object>room)/(?P<id>[0-9]+)$', url(r'^history/(?P<object_name>room)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history'), name='history'),
url(r'^history/(?P<object>stack)/(?P<id>[0-9]+)$', url(r'^history/(?P<object_name>stack)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history'), name='history'),
url(r'^edit_port/(?P<port_id>[0-9]+)$', views.edit_port, name='edit-port'), url(r'^edit_port/(?P<port_id>[0-9]+)$', views.edit_port, name='edit-port'),

View file

@ -135,7 +135,8 @@ def index_port(request, switch_id):
port_list = Port.objects.filter(switch=switch)\ port_list = Port.objects.filter(switch=switch)\
.select_related('room')\ .select_related('room')\
.select_related('machine_interface__domain__extension')\ .select_related('machine_interface__domain__extension')\
.select_related('related')\ .select_related('machine_interface__machine__user')\
.select_related('related__switch__switch_interface__domain__extension')\
.select_related('switch')\ .select_related('switch')\
.order_by('port') .order_by('port')
return render(request, 'topologie/index_p.html', { return render(request, 'topologie/index_p.html', {

View file

@ -452,13 +452,14 @@ class RightForm(ModelForm):
class DelRightForm(Form): class DelRightForm(Form):
"""Suppression d'un droit d'un user""" """Suppression d'un droit d'un user"""
rights = forms.ModelMultipleChoiceField( rights = forms.ModelMultipleChoiceField(
queryset=Right.objects.all(), queryset=Right.objects.select_related('user'),
widget=forms.CheckboxSelectMultiple widget=forms.CheckboxSelectMultiple
) )
def __init__(self, right, *args, **kwargs): def __init__(self, right, *args, **kwargs):
super(DelRightForm, self).__init__(*args, **kwargs) super(DelRightForm, self).__init__(*args, **kwargs)
self.fields['rights'].queryset = Right.objects.filter(right=right) self.fields['rights'].queryset = Right.objects.select_related('user')\
.select_related('right').filter(right=right)
class BanForm(ModelForm): class BanForm(ModelForm):

View file

@ -88,32 +88,32 @@ urlpatterns = [
url(r'^reset_password/$', views.reset_password, name='reset-password'), url(r'^reset_password/$', views.reset_password, name='reset-password'),
url(r'^mass_archive/$', views.mass_archive, name='mass-archive'), url(r'^mass_archive/$', views.mass_archive, name='mass-archive'),
url( url(
r'^history/(?P<object>user)/(?P<id>[0-9]+)$', r'^history/(?P<object_name>user)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history' name='history'
), ),
url( url(
r'^history/(?P<object>ban)/(?P<id>[0-9]+)$', r'^history/(?P<object_name>ban)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history' name='history'
), ),
url( url(
r'^history/(?P<object>whitelist)/(?P<id>[0-9]+)$', r'^history/(?P<object_name>whitelist)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history' name='history'
), ),
url( url(
r'^history/(?P<object>school)/(?P<id>[0-9]+)$', r'^history/(?P<object_name>school)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history' name='history'
), ),
url( url(
r'^history/(?P<object>listright)/(?P<id>[0-9]+)$', r'^history/(?P<object_name>listright)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history' name='history'
), ),
url( url(
r'^history/(?P<object>serviceuser)/(?P<id>[0-9]+)$', r'^history/(?P<object_name>serviceuser)/(?P<object_id>[0-9]+)$',
views.history, views.history,
name='history' name='history'
), ),