mirror of https://github.com/jumpserver/jumpserver
[Update] stash it
parent
790652ff4d
commit
fd5f562cbf
|
@ -79,7 +79,6 @@ class OrgModelForm(ModelForm):
|
|||
for name, field in self.fields.items():
|
||||
if not hasattr(field, 'queryset'):
|
||||
continue
|
||||
print(field)
|
||||
model = field.queryset.model
|
||||
field.queryset = model.objects.all()
|
||||
|
||||
|
|
|
@ -4,11 +4,13 @@ from __future__ import absolute_import, unicode_literals
|
|||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from orgs.mixins import OrgModelForm
|
||||
from orgs.utils import get_current_org
|
||||
from .hands import User
|
||||
from .models import AssetPermission
|
||||
|
||||
|
||||
class AssetPermissionForm(forms.ModelForm):
|
||||
class AssetPermissionForm(OrgModelForm):
|
||||
users = forms.ModelMultipleChoiceField(
|
||||
queryset=User.objects.exclude(role=User.ROLE_APP),
|
||||
label=_("User"),
|
||||
|
@ -21,6 +23,15 @@ class AssetPermissionForm(forms.ModelForm):
|
|||
required=False,
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if 'initial' not in kwargs:
|
||||
return
|
||||
users_field = self.fields.get('users')
|
||||
if hasattr(users_field, 'queryset'):
|
||||
current_org = get_current_org()
|
||||
users_field.queryset = User.objects.filter(orgs=current_org)
|
||||
|
||||
class Meta:
|
||||
model = AssetPermission
|
||||
exclude = (
|
||||
|
|
|
@ -306,6 +306,12 @@ class UserGroupForm(forms.ModelForm):
|
|||
})
|
||||
kwargs['initial'] = initial
|
||||
super().__init__(**kwargs)
|
||||
if 'initial' not in kwargs:
|
||||
return
|
||||
users_field = self.fields.get('users')
|
||||
if hasattr(users_field, 'queryset'):
|
||||
current_org = get_current_org()
|
||||
users_field.queryset = User.objects.filter(orgs=current_org)
|
||||
|
||||
def save(self, commit=True):
|
||||
group = super().save(commit=commit)
|
||||
|
|
Loading…
Reference in New Issue