Starting code base optimizations

This commit is contained in:
Kumi 2019-02-01 13:46:00 +00:00
parent 5979e2cec5
commit a251f07ed4
2 changed files with 6 additions and 14 deletions

View file

@ -255,27 +255,19 @@ def ping(request, device_id):
@login_required @login_required
def devices(request): def devices(request):
user = request.user
devices = set() devices = set()
wifis = set() wifis = set()
users = set() users = set()
for organization in Organization.objects.filter(users=user): for organization in request.user.organization_set.all():
for device in Device.objects.filter(organization=organization): devices = devices.union(organization.device_set.all())
devices.add(device) wifis = wifis.union(organization.wifi_set.all())
for wifi in Wifi.objects.filter(organization=organization): users = users.union(organization.users.all()) if request.user.is_superuser else users
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)
return render(request, "manager/index.html", return render(request, "manager/index.html",
{ {
"title": "Device Administration", "title": "Device Administration",
"user": user, "user": request.user,
"devices": sorted(devices, key=lambda x: x.serial), "devices": sorted(devices, key=lambda x: x.serial),
"wifis": sorted(wifis, key=lambda x: x.serial), "wifis": sorted(wifis, key=lambda x: x.serial),
"users": sorted(users, key=lambda x: x.username) "users": sorted(users, key=lambda x: x.username)

View file

@ -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' SECRET_KEY = '=go8&h#^kh6ksr11e2z-@4qqd6t%63$x#-!s#l_yhw@oyanrys'
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False DEBUG = True
ALLOWED_HOSTS = ["admin360.kumi.host", "test360.kumi.host"] ALLOWED_HOSTS = ["admin360.kumi.host", "test360.kumi.host"]