You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jumpserver/apps/labels/const.py

25 lines
710 B

from django.utils.functional import LazyObject
class LabeledResourceType(LazyObject):
@staticmethod
def get_res_types():
from rbac.models import ContentType
content_types = ContentType.objects.all()
ids = []
for ct in content_types:
model_cls = ct.model_class()
if not model_cls:
continue
if model_cls._meta.parents:
continue
if 'labels' in model_cls._meta._forward_fields_map.keys():
ids.append(ct.id)
return ContentType.objects.filter(id__in=ids)
def _setup(self):
self._wrapped = self.get_res_types()
label_resource_types = LabeledResourceType()