mirror of
https://github.com/Nebucatnetzer/network_inventory.git
synced 2024-06-22 07:26:46 +02:00
make get_customers an internal function
This commit is contained in:
parent
b78780555d
commit
f901999aee
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user