本文整理汇总了Python中tracim.lib.content.ContentApi.get_base_query方法的典型用法代码示例。如果您正苦于以下问题:Python ContentApi.get_base_query方法的具体用法?Python ContentApi.get_base_query怎么用?Python ContentApi.get_base_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim.lib.content.ContentApi
的用法示例。
在下文中一共展示了ContentApi.get_base_query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PathValidationManager
# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import get_base_query [as 别名]
class PathValidationManager(object):
def __init__(self, is_case_sensitive: bool=False):
"""
:param is_case_sensitive: If True, consider name with different
case as different.
"""
self._is_case_sensitive = is_case_sensitive
self._workspace_api = UnsafeWorkspaceApi(None)
self._content_api = ContentApi(None)
def workspace_label_is_free(self, workspace_name: str) -> bool:
"""
:param workspace_name: Workspace name
:return: True if workspace is available
"""
query = self._workspace_api.get_base_query()
label_filter = Workspace.label == workspace_name
if not self._is_case_sensitive:
label_filter = func.lower(Workspace.label) == \
func.lower(workspace_name)
return not bool(query.filter(label_filter).count())
def content_label_is_free(
self,
content_label_as_file,
workspace: Workspace,
parent: Content=None,
exclude_content_id: int=None,
) -> bool:
"""
:param content_label_as_file:
:param workspace:
:param parent:
:return: True if content label is available
"""
query = self._content_api.get_base_query(workspace)
if parent:
query = query.filter(Content.parent_id == parent.content_id)
if exclude_content_id:
query = query.filter(Content.content_id != exclude_content_id)
query = query.filter(Content.workspace_id == workspace.workspace_id)
return not \
bool(
self._content_api.filter_query_for_content_label_as_path(
query=query,
content_label_as_file=content_label_as_file,
is_case_sensitive=self._is_case_sensitive,
).count()
)
def validate_new_content(self, content: Content) -> bool:
"""
:param content: Content with label to test
:return: True if content label is not in conflict with existing
resource
"""
return self.content_label_is_free(
content_label_as_file=content.get_label_as_file(),
workspace=content.workspace,
parent=content.parent,
exclude_content_id=content.content_id,
)