mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-14 09:08:32 +00:00
32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
from django.db.models import Q, QuerySet
|
|
|
|
from baserow.contrib.builder.models import Builder
|
|
from baserow.core.object_scopes import (
|
|
ApplicationObjectScopeType,
|
|
WorkspaceObjectScopeType,
|
|
)
|
|
from baserow.core.registries import ObjectScopeType, object_scope_type_registry
|
|
|
|
|
|
class BuilderObjectScopeType(ObjectScopeType):
|
|
type = "builder"
|
|
model_class = Builder
|
|
|
|
def get_parent_scope(self):
|
|
return object_scope_type_registry.get("application")
|
|
|
|
def get_base_queryset(self, include_trash: bool = False) -> QuerySet:
|
|
return super().get_base_queryset(include_trash)
|
|
|
|
def get_enhanced_queryset(self, include_trash: bool = False) -> QuerySet:
|
|
return self.get_base_queryset(include_trash).select_related("workspace")
|
|
|
|
def get_filter_for_scope_type(self, scope_type, scopes):
|
|
if scope_type.type == WorkspaceObjectScopeType.type:
|
|
return Q(workspace__in=[s.id for s in scopes])
|
|
if scope_type.type == ApplicationObjectScopeType.type:
|
|
return Q(id__in=[s.id for s in scopes])
|
|
if scope_type.type == self.type:
|
|
return Q(id__in=[s.id for s in scopes])
|
|
|
|
raise TypeError("The given type is not handled.")
|