make get_customers an internal function

This commit is contained in:
Andreas Zweili 2021-12-24 12:55:34 +01:00
parent b78780555d
commit f901999aee
3 changed files with 13 additions and 5 deletions

View File

@ -10,6 +10,8 @@ from computers.models import ComputerRamRelation
from computers.models import ComputerSoftwareRelation
from computers.models import Raid
from customers.models import Customer
class ComputerCreateForm(forms.ModelForm):
class Meta:
@ -26,7 +28,9 @@ class ComputerCreateForm(forms.ModelForm):
"""
super(ComputerCreateForm, self).__init__(*args, **kwargs)
if not user.is_superuser:
self.fields['customer'].queryset = utils.get_customers(user)
self.fields['customer'].queryset = (
utils.get_all_objects_for_alLowed_customers(
Customer, user=user))
class ComputerUpdateForm(forms.ModelForm):

View File

@ -29,7 +29,7 @@ def td_format(td_object):
return ", ".join(strings)
def get_customers(user):
def _get_customers(user):
"""
Returns a queryset of customers the user is allowed to view.
@ -48,7 +48,7 @@ def get_objects(model_name, user):
user : django.contrib.auth.models.User
"""
model_name = model_name.lower()
customers = get_customers(user)
customers = _get_customers(user)
app_names = [
'backups',
'computers',
@ -82,7 +82,7 @@ def get_object_with_view_permission(model, user=None, pk=None):
def get_all_objects_for_alLowed_customers(model, user=None):
customers = get_customers(user)
customers = _get_customers(user)
if model.__name__ == 'Customer':
return customers
objects = model.objects.filter(customer__in=customers)

View File

@ -2,6 +2,8 @@ import floppyforms.__future__ as forms
from core import utils
from customers.models import Customer
from devices.models import Device
from devices.models import DeviceInNet
from devices.models import Warranty
@ -22,7 +24,9 @@ class DeviceCreateForm(forms.ModelForm):
"""
super(DeviceCreateForm, self).__init__(*args, **kwargs)
if not user.is_superuser:
self.fields['customer'].queryset = utils.get_customers(user)
self.fields['customer'].queryset = (
utils.get_all_objects_for_alLowed_customers(
Customer, user=user))
class DeviceUpdateForm(forms.ModelForm):