[Update] stash it

pull/1571/head
ibuler 2018-07-18 12:57:08 +08:00
parent 790652ff4d
commit fd5f562cbf
3 changed files with 18 additions and 2 deletions

View File

@ -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()

View File

@ -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 = (

View File

@ -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)