本文整理汇总了Python中tracim.config.app_cfg.CFG类的典型用法代码示例。如果您正苦于以下问题:Python CFG类的具体用法?Python CFG怎么用?Python CFG使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CFG类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_deleted_calendar_file_path
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
开发者ID:lebouquetin,项目名称:tracim,代码行数:25,代码来源:calendar.py
示例2: download_pdf_one
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()
开发者ID:lebouquetin,项目名称:tracim,代码行数:31,代码来源:page.py
示例3: test_is_item_still_editable
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))
开发者ID:buxx,项目名称:tracim,代码行数:25,代码来源:test_helpers.py
示例4: send_email_through
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,
)
)
开发者ID:lebouquetin,项目名称:tracim,代码行数:26,代码来源:email.py
示例5: get_one
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,
)
开发者ID:buxx,项目名称:tracim,代码行数:30,代码来源:workspace.py
示例6: get_one
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
开发者ID:lebouquetin,项目名称:tracim,代码行数:29,代码来源:page.py
示例7: index
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,
)
开发者ID:lebouquetin,项目名称:tracim,代码行数:29,代码来源:calendar.py
示例8: create
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)
开发者ID:buxx,项目名称:tracim,代码行数:8,代码来源:notifications.py
示例9: test_email_notifier__build_name_with_no_user
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)
开发者ID:lebouquetin,项目名称:tracim,代码行数:8,代码来源:test_notification.py
示例10: _get_server
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
)
开发者ID:Nonolost,项目名称:tracim,代码行数:10,代码来源:daemons.py
示例11: treeview_root
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')
开发者ID:lebouquetin,项目名称:tracim,代码行数:55,代码来源:workspace.py
示例12: test_email_notifier__build_name_without_user_id
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
开发者ID:lebouquetin,项目名称:tracim,代码行数:11,代码来源:test_notification.py
示例13: test_notifier_factory_method
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__)
开发者ID:DarkDare,项目名称:tracim,代码行数:11,代码来源:test_notification.py
示例14: get_one
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,
)
开发者ID:lebouquetin,项目名称:tracim,代码行数:53,代码来源:workspace.py
示例15: get_base_url
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)
开发者ID:buxx,项目名称:tracim,代码行数:12,代码来源:calendar.py
示例16: __init__
def __init__(self, current_user: User=None):
"""
:param current_user: the user that has triggered the notification
:return:
"""
logger.info(self, 'Instantiating Real Notifier')
cfg = CFG.get_instance()
self._user = current_user
self._smtp_config = SmtpConfiguration(cfg.EMAIL_NOTIFICATION_SMTP_SERVER,
cfg.EMAIL_NOTIFICATION_SMTP_PORT,
cfg.EMAIL_NOTIFICATION_SMTP_USER,
cfg.EMAIL_NOTIFICATION_SMTP_PASSWORD)
开发者ID:DarkDare,项目名称:tracim,代码行数:13,代码来源:notifications.py
示例17: _prepare_config
def _prepare_config(self):
from tracim.config.app_cfg import CFG
cfg = CFG.get_instance()
tracim_auth = 'tracim.lib.radicale.auth'
tracim_rights = 'tracim.lib.radicale.rights'
tracim_storage = 'tracim.lib.radicale.storage'
fs_path = cfg.RADICALE_SERVER_FILE_SYSTEM_FOLDER
allow_origin = cfg.RADICALE_SERVER_ALLOW_ORIGIN
realm_message = cfg.RADICALE_SERVER_REALM_MESSAGE
radicale_config.set('auth', 'type', 'custom')
radicale_config.set('auth', 'custom_handler', tracim_auth)
radicale_config.set('rights', 'type', 'custom')
radicale_config.set('rights', 'custom_handler', tracim_rights)
radicale_config.set('storage', 'type', 'custom')
radicale_config.set('storage', 'custom_handler', tracim_storage)
radicale_config.set('storage', 'filesystem_folder', fs_path)
radicale_config.set('server', 'realm', realm_message)
try:
radicale_config.add_section('headers')
except DuplicateSectionError:
pass # It is not a problem, we just want it exist
if allow_origin:
radicale_config.set(
'headers',
'Access-Control-Allow-Origin',
allow_origin,
)
# Radicale is not 100% CALDAV Compliant, we force some Allow-Methods
radicale_config.set(
'headers',
'Access-Control-Allow-Methods',
'DELETE, HEAD, GET, MKCALENDAR, MKCOL, MOVE, OPTIONS, PROPFIND, '
'PROPPATCH, PUT, REPORT',
)
# Radicale is not 100% CALDAV Compliant, we force some Allow-Headers
radicale_config.set(
'headers',
'Access-Control-Allow-Headers',
'X-Requested-With,X-Auth-Token,Content-Type,Content-Length,'
'X-Client,Authorization,depth,Prefer,If-None-Match,If-Match',
)
开发者ID:Nonolost,项目名称:tracim,代码行数:50,代码来源:daemons.py
示例18: __init__
def __init__(self, current_user: User=None):
"""
:param current_user: the user that has triggered the notification
:return:
"""
logger.info(self, 'Instantiating Real Notifier')
# TODO: Find a way to import properly without cyclic import
from tracim.config.app_cfg import CFG
cfg = CFG.get_instance()
self._user = current_user
self._smtp_config = SmtpConfiguration(cfg.EMAIL_NOTIFICATION_SMTP_SERVER,
cfg.EMAIL_NOTIFICATION_SMTP_PORT,
cfg.EMAIL_NOTIFICATION_SMTP_USER,
cfg.EMAIL_NOTIFICATION_SMTP_PASSWORD)
开发者ID:buxx,项目名称:tracim,代码行数:15,代码来源:notifications.py
示例19: get_email_manager
def get_email_manager():
"""
:return: EmailManager instance
"""
# TODO: Find a way to import properly without cyclic import
from tracim.config.app_cfg import CFG
global_config = CFG.get_instance()
smtp_config = SmtpConfiguration(
global_config.EMAIL_NOTIFICATION_SMTP_SERVER,
global_config.EMAIL_NOTIFICATION_SMTP_PORT,
global_config.EMAIL_NOTIFICATION_SMTP_USER,
global_config.EMAIL_NOTIFICATION_SMTP_PASSWORD
)
return EmailManager(global_config=global_config, smtp_config=smtp_config)
开发者ID:Nonolost,项目名称:tracim,代码行数:16,代码来源:email.py
示例20: _render
def _render(self, mako_template_filepath: str, context: dict):
"""
Render mako template with all needed current variables
:param mako_template_filepath: file path of mako template
:param context: dict with template context
:return: template rendered string
"""
# TODO - D.A. - 2014-11-06 - move this
# Import is here for circular import problem
import tracim.lib.helpers as helpers
from tracim.config.app_cfg import CFG
template = Template(filename=mako_template_filepath)
return template.render(
base_url=self._global_config.WEBSITE_BASE_URL,
_=_,
h=helpers,
CFG=CFG.get_instance(),
**context
)
开发者ID:Nonolost,项目名称:tracim,代码行数:20,代码来源:email.py
注:本文中的tracim.config.app_cfg.CFG类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论