jumpserver/apps/labels/const.py

26 lines
732 B
Python
Raw Normal View History

2023-12-18 09:56:16 +00:00
from django.utils.functional import LazyObject
class LabeledResourceType(LazyObject):
@staticmethod
def get_res_types():
from rbac.models import ContentType
2023-12-20 02:52:02 +00:00
from .mixins import LabeledMixin
2023-12-18 09:56:16 +00:00
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
2023-12-20 02:52:02 +00:00
if issubclass(model_cls, LabeledMixin):
2023-12-18 09:56:16 +00:00
ids.append(ct.id)
return ContentType.objects.filter(id__in=ids)
def _setup(self):
self._wrapped = self.get_res_types()
label_resource_types = LabeledResourceType()