From a251f07ed4ec6b6189fc5cf285feeeabb2cd6e2b Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Fri, 1 Feb 2019 13:46:00 +0000 Subject: [PATCH] Starting code base optimizations --- manager/views.py | 18 +++++------------- vpnmanager/settings.py | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/manager/views.py b/manager/views.py index 3e9be0d..5391670 100644 --- a/manager/views.py +++ b/manager/views.py @@ -255,27 +255,19 @@ def ping(request, device_id): @login_required def devices(request): - user = request.user devices = set() wifis = set() users = set() - for organization in Organization.objects.filter(users=user): - for device in Device.objects.filter(organization=organization): - devices.add(device) - for wifi in Wifi.objects.filter(organization=organization): - wifis.add(wifi) - if user.is_staff: - for orgauser in User.objects.filter(organization=organization): - orgauser.organizations = set() - for orga in Organization.objects.filter(users=orgauser): - orgauser.organizations.add(orga) - users.add(orgauser) + for organization in request.user.organization_set.all(): + devices = devices.union(organization.device_set.all()) + wifis = wifis.union(organization.wifi_set.all()) + users = users.union(organization.users.all()) if request.user.is_superuser else users return render(request, "manager/index.html", { "title": "Device Administration", - "user": user, + "user": request.user, "devices": sorted(devices, key=lambda x: x.serial), "wifis": sorted(wifis, key=lambda x: x.serial), "users": sorted(users, key=lambda x: x.username) diff --git a/vpnmanager/settings.py b/vpnmanager/settings.py index 6b575ca..d5856fb 100644 --- a/vpnmanager/settings.py +++ b/vpnmanager/settings.py @@ -7,7 +7,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = '=go8&h#^kh6ksr11e2z-@4qqd6t%63$x#-!s#l_yhw@oyanrys' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True ALLOWED_HOSTS = ["admin360.kumi.host", "test360.kumi.host"]