本文整理汇总了Python中tracim.config.app_cfg.CFG.get_instance方法的典型用法代码示例。如果您正苦于以下问题:Python CFG.get_instance方法的具体用法?Python CFG.get_instance怎么用?Python CFG.get_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim.config.app_cfg.CFG
的用法示例。
在下文中一共展示了CFG.get_instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_deleted_calendar_file_path
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def get_deleted_calendar_file_path(
self,
calendar_class,
related_object_id,
) -> str:
from tracim.config.app_cfg import CFG
cfg = CFG.get_instance()
calendar_file_name = '{}.ics'.format(related_object_id)
if calendar_class == WorkspaceCalendar:
calendar_type_folder = 'workspace'
elif calendar_class == UserCalendar:
calendar_type_folder = 'user'
else:
raise NotImplementedError()
deleted_calendar_file_path = os.path.join(
cfg.RADICALE_SERVER_FILE_SYSTEM_FOLDER,
calendar_type_folder,
'deleted',
calendar_file_name,
)
return deleted_calendar_file_path
示例2: download_pdf_one
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def download_pdf_one(self,
page_id: str,
revision_id: str=None,
*args, **kwargs):
file_id = int(tg.request.controller_state.routing_args.get('file_id'))
revision_id = int(revision_id) if revision_id != 'latest' else None
page = int(page_id)
cache_path = CFG.get_instance().PREVIEW_CACHE_DIR
preview_manager = PreviewManager(cache_path, create_folder=True)
user = tmpl_context.current_user
content_api = ContentApi(user,
show_archived=True,
show_deleted=True)
file = content_api.get_one(file_id, self._item_type)
if revision_id:
file_path = content_api.get_one_revision_filepath(revision_id)
else:
file = content_api.get_one(file_id, self._item_type)
file_path = content_api.get_one_revision_filepath(file.revision_id)
path = preview_manager.get_pdf_preview(file_path=file_path,
page=page)
file_suffix = ''
if page > -1:
file_suffix = '.page-{}'.format(page + 1)
tg.response.headers['Content-Disposition'] = \
'attachment; filename="{}{}.pdf"'.format(
file.label,
file_suffix,
)
with open(path, 'rb') as pdf:
return pdf.read()
示例3: test_is_item_still_editable
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def test_is_item_still_editable(self):
config = CFG.get_instance()
item = DictLikeClass()
config.DATA_UPDATE_ALLOWED_DURATION = 0
item.created = datetime.datetime.now() - datetime.timedelta(0, 10)
item.type = DictLikeClass({'id': 5})
eq_(False, h.is_item_still_editable(config, item))
item.type.id = 'comment'
eq_(False, h.is_item_still_editable(config, item))
config.DATA_UPDATE_ALLOWED_DURATION = -1
item.type.id = 'comment'
item.created = datetime.datetime.now() - datetime.timedelta(0, 10)
eq_(True, h.is_item_still_editable(config, item))
config.DATA_UPDATE_ALLOWED_DURATION = 12
item.created = datetime.datetime.now() - datetime.timedelta(0, 10)
eq_(True, h.is_item_still_editable(config, item), 'created: {}, now: {}'.format(item.created, datetime.datetime.now())) # This test will pass only if the test duration is less than 120s !!!
config.DATA_UPDATE_ALLOWED_DURATION = 8
item.created = datetime.datetime.now() - datetime.timedelta(0, 10)
eq_(False, h.is_item_still_editable(config, item))
示例4: send_email_through
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def send_email_through(
sendmail_callable: typing.Callable[[Message], None],
message: Message,
) -> None:
"""
Send mail encapsulation to send it in async or sync mode.
TODO BS 20170126: A global mail/sender management should be a good
thing. Actually, this method is an fast solution.
:param sendmail_callable: A callable who get message on first parameter
:param message: The message who have to be sent
"""
from tracim.config.app_cfg import CFG
cfg = CFG.get_instance()
if cfg.EMAIL_PROCESSING_MODE == CFG.CST.SYNC:
sendmail_callable(message)
elif cfg.EMAIL_PROCESSING_MODE == CFG.CST.ASYNC:
queue = get_rq_queue('mail_sender')
queue.enqueue(sendmail_callable, message)
else:
raise NotImplementedError(
'Mail sender processing mode {} is not implemented'.format(
cfg.EMAIL_PROCESSING_MODE,
)
)
示例5: get_one
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def get_one(self, workspace_id):
user = tmpl_context.current_user
current_user_content = Context(CTX.CURRENT_USER).toDict(user)
current_user_content.roles.sort(key=lambda role: role.workspace.name)
workspace_api = WorkspaceApi(user)
workspace = workspace_api.get_one(workspace_id)
dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
dictified_folders = self.folders.get_all_fake(workspace).result
fake_api = DictLikeClass(
current_user=dictified_current_user,
current_workspace_folders=dictified_folders,
current_user_workspace_role=workspace.get_user_role(user)
)
fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(
# TODO BS 20161209: Is the correct way to grab folders? No use API?
workspace.get_valid_children(ContentApi.DISPLAYABLE_CONTENTS)
)
dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace, 'workspace')
webdav_url = CFG.get_instance().WSGIDAV_CLIENT_BASE_URL
return DictLikeClass(
result=dictified_workspace,
fake_api=fake_api,
webdav_url=webdav_url,
)
示例6: get_one
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def get_one(self,
page_id: str='-1',
revision_id: str=None,
size: int=300,
*args, **kwargs):
file_id = int(tg.request.controller_state.routing_args.get('file_id'))
page = int(page_id)
revision_id = int(revision_id) if revision_id != 'latest' else None
cache_path = CFG.get_instance().PREVIEW_CACHE_DIR
preview_manager = PreviewManager(cache_path, create_folder=True)
user = tmpl_context.current_user
content_api = ContentApi(user,
show_archived=True,
show_deleted=True)
if revision_id:
file_path = content_api.get_one_revision_filepath(revision_id)
else:
file = content_api.get_one(file_id, self._item_type)
file_path = content_api.get_one_revision_filepath(file.revision_id)
try:
path = preview_manager.get_jpeg_preview(file_path=file_path,
page=page,
height=size,
width=size)
with open(path, 'rb') as large:
result = large.read()
except PreviewGeneratorException:
result = None
return result
示例7: index
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def index(self):
from tracim.config.app_cfg import CFG
cfg = CFG.get_instance()
# TODO BS 20160720: S'assurer d'être identifié !
user = tmpl_context.identity.get('user')
dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
fake_api = DictLikeClass(
current_user=dictified_current_user,
)
user_base_url = CalendarManager.get_user_base_url()
workspace_base_url = CalendarManager.get_workspace_base_url()
workspace_calendar_urls = CalendarManager\
.get_workspace_readable_calendars_urls_for_user(user)
base_href_url = \
re.sub(r"^http[s]?://", '', cfg.RADICALE_CLIENT_BASE_URL_HOST)
# Template will use User.auth_token, ensure it's validity
user.ensure_auth_token()
return DictLikeClass(
fake_api=fake_api,
user_base_url=user_base_url,
workspace_base_url=workspace_base_url,
workspace_clendar_urls=workspace_calendar_urls,
auth_token=user.auth_token,
base_href_url=base_href_url,
)
示例8: create
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def create(cls, current_user: User=None) -> INotifier:
# TODO: Find a way to import properly without cyclic import
from tracim.config.app_cfg import CFG
cfg = CFG.get_instance()
if not cfg.EMAIL_NOTIFICATION_ACTIVATED:
return DummyNotifier(current_user)
return RealNotifier(current_user)
示例9: test_email_notifier__build_name_with_no_user
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def test_email_notifier__build_name_with_no_user(self):
config = CFG.get_instance()
config.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = 'Robot'
config.EMAIL_NOTIFICATION_FROM_EMAIL = '[email protected]'
notifier = EmailNotifier(smtp_config=None, global_config=config)
email = notifier._get_sender()
eq_('Robot <[email protected]>', email)
示例10: _get_server
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def _get_server(self):
from tracim.config.app_cfg import CFG
cfg = CFG.get_instance()
return make_server(
cfg.RADICALE_SERVER_HOST,
cfg.RADICALE_SERVER_PORT,
RadicaleApplication(),
RadicaleHTTPSServer if cfg.RADICALE_SERVER_SSL else RadicaleHTTPServer,
RadicaleRequestHandler
)
示例11: treeview_root
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def treeview_root(self, id='#',
current_id=None,
all_workspaces=True,
folder_allowed_content_types='',
ignore_id=None,
ignore_workspace_id=None):
all_workspaces = bool(int(all_workspaces))
# ignore_workspace_id is a string like 3,12,78,15
ignored_ids = [int(id) for id in ignore_workspace_id.split(',')] if ignore_workspace_id else None
if not current_id:
# Default case is to return list of workspaces
api = WorkspaceApi(tmpl_context.current_user)
workspaces = api.get_all_for_user(tmpl_context.current_user,
ignored_ids)
dictified_workspaces = Context(CTX.MENU_API).toDict(workspaces, 'd')
return dictified_workspaces
allowed_content_types = ContentType.allowed_types_from_str(folder_allowed_content_types)
ignored_item_ids = [int(ignore_id)] if ignore_id else []
# Now complex case: we must return a structured tree
# including the selected node, all parents (and their siblings)
workspace, content = convert_id_into_instances(current_id)
# The following step allow to select the parent folder when content itself is not visible in the treeview
if content and content.type!=ContentType.Folder and CFG.CST.TREEVIEW_ALL!=CFG.get_instance().WEBSITE_TREEVIEW_CONTENT:
content = content.parent if content.parent else None
# This is the init of the recursive-like build of the tree
content_parent = content
tree_items = []
# The first step allow to load child of selected item
# (for example, when you select a folder in the windows explorer,
# then the selected folder is expanded by default)
content_api = ContentApi(tmpl_context.current_user)
child_folders = content_api.get_child_folders(content_parent, workspace, allowed_content_types, ignored_item_ids)
if len(child_folders)>0:
first_child = child_folders[0]
content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, first_child, tree_items, False, allowed_content_types, ignored_item_ids)
content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, content_parent, tree_items, True, allowed_content_types, ignored_item_ids)
while content_parent:
# Do the same for the parent level
content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, content_parent, tree_items)
# Now, we have a tree_items list that is the root folders list,
# so we now have to put it as a child of a list of workspaces
should_select_workspace = not content
full_tree = self._build_sibling_list_of_workspaces(workspace, tree_items, should_select_workspace, all_workspaces)
return Context(CTX.MENU_API_BUILD_FROM_TREE_ITEM).toDict(full_tree, 'd')
示例12: test_email_notifier__build_name_without_user_id
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def test_email_notifier__build_name_without_user_id(self):
u = User()
u.user_id = 3
u.display_name = 'François Michâlié'
config = CFG.get_instance()
config.EMAIL_NOTIFICATION_FROM_EMAIL = '[email protected]'
notifier = EmailNotifier(smtp_config=None, global_config=config)
email = notifier._get_sender(user=u)
eq_('=?utf-8?q?Fran=C3=A7ois_Mich=C3=A2li=C3=A9_via_Tracim?= <[email protected]>', email) # nopep8
示例13: test_notifier_factory_method
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def test_notifier_factory_method(self):
u = User()
cfg = CFG.get_instance()
cfg.EMAIL_NOTIFICATION_ACTIVATED = True
notifier = NotifierFactory.create(u)
eq_(RealNotifier, notifier.__class__)
cfg.EMAIL_NOTIFICATION_ACTIVATED = False
notifier = NotifierFactory.create(u)
eq_(DummyNotifier, notifier.__class__)
示例14: get_one
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def get_one(self, workspace_id, **kwargs):
"""
:param workspace_id: Displayed workspace id
:param kwargs:
* show_deleted: bool: Display deleted contents or hide them if False
* show_archived: bool: Display archived contents or hide them
if False
"""
show_deleted = str_as_bool(kwargs.get('show_deleted', False))
show_archived = str_as_bool(kwargs.get('show_archived', ''))
user = tmpl_context.current_user
workspace_api = WorkspaceApi(user)
workspace = workspace_api.get_one(workspace_id)
unread_contents = ContentApi(user).get_last_unread(None,
ContentType.Any,
workspace=workspace)
current_user_content = Context(CTX.CURRENT_USER).toDict(user)
current_user_content.roles.sort(key=lambda role: role.workspace.name)
dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
dictified_folders = self.folders.get_all_fake(workspace).result
fake_api = DictLikeClass(
last_unread=Context(CTX.CONTENT_LIST).toDict(unread_contents,
'contents',
'nb'),
current_user=dictified_current_user,
current_workspace_folders=dictified_folders,
current_user_workspace_role=workspace.get_user_role(user)
)
fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(
# TODO BS 20161209: Is the correct way to grab folders? No use API?
workspace.get_valid_children(
ContentApi.DISPLAYABLE_CONTENTS,
show_deleted=show_deleted,
show_archived=show_archived,
)
)
dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace, 'workspace')
webdav_url = CFG.get_instance().WSGIDAV_CLIENT_BASE_URL
return DictLikeClass(
result=dictified_workspace,
fake_api=fake_api,
webdav_url=webdav_url,
show_deleted=show_deleted,
show_archived=show_archived,
)
示例15: get_base_url
# 需要导入模块: from tracim.config.app_cfg import CFG [as 别名]
# 或者: from tracim.config.app_cfg.CFG import get_instance [as 别名]
def get_base_url(cls, low_level: bool=False) -> str:
"""
:param low_level: If True, use local ip address with radicale port.
:return: Radical address base url.
"""
from tracim.config.app_cfg import CFG
cfg = CFG.get_instance()
if not low_level:
return cfg.RADICALE_CLIENT_BASE_URL_TEMPLATE
return '127.0.0.1:{0}'.format(cfg.RADICALE_SERVER_PORT)