本文整理汇总了Python中substanced.util.find_service函数的典型用法代码示例。如果您正苦于以下问题:Python find_service函数的具体用法?Python find_service怎么用?Python find_service使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_service函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_register_services
def test_register_services(self, meta, registry, pool):
from substanced.util import find_service
from . import principal
registry.content.create(meta.iresource.__identifier__, parent=pool)
assert find_service(pool, 'principals', 'users')
assert find_service(pool, 'principals', 'groups')
assert find_service(pool, 'principals', 'resets')
示例2: _add_initial_user_and_group
def _add_initial_user_and_group(context, registry):
settings = registry['config']
user_name = settings.adhocracy.initial_login
user_password = settings.adhocracy.initial_password
user_email = settings.adhocracy.initial_email
group_name = settings.adhocracy.initial_group_name
group_roles = ['god']
groups = find_service(context, 'principals', 'groups')
appstructs = {adhocracy_core.sheets.principal.IGroup.__identifier__:
{'roles': group_roles},
adhocracy_core.sheets.name.IName.__identifier__:
{'name': group_name},
}
group = registry.content.create(IGroup.__identifier__, groups,
appstructs=appstructs,
registry=registry)
users = find_service(context, 'principals', 'users')
password_sheet = adhocracy_core.sheets.principal.IPasswordAuthentication
appstruct = {adhocracy_core.sheets.principal.IUserBasic.__identifier__:
{'name': user_name},
adhocracy_core.sheets.principal.IUserExtended.__identifier__:
{'email': user_email},
adhocracy_core.sheets.principal.IPermissions.__identifier__:
{'groups': [group]},
password_sheet.__identifier__:
{'password': user_password},
}
user = registry.content.create(IUser.__identifier__,
users,
appstruct,
run_after_creation=False,
send_event=False,
registry=registry)
user.activate()
示例3: _import_users
def _import_users(context: IResource, registry: Registry, filename: str):
users_info = _load_users_info(filename)
users_info = [_normalize_user_info(u) for u in users_info]
users = find_service(context, 'principals', 'users')
groups = find_service(context, 'principals', 'groups')
for user_info in users_info:
user_by_name, user_by_email = _locate_user(user_info,
context,
registry)
if user_by_name or user_by_email:
logger.info('Updating user {} ({})'.format(user_info['name'],
user_info['email']))
_update_user(user_by_name, user_by_email, user_info, groups)
else:
logger.info('Creating user {}'.format(user_info['name']))
send_invitation = user_info.get('send_invitation_mail', False)
activate = not send_invitation
user = _create_user(user_info, users, registry, groups,
activate=activate)
if send_invitation:
logger.info('Sending invitation mail to {}'.format(user.name))
_send_invitation_mail(user, user_info, registry)
badge_names = user_info.get('badges', [])
if badge_names:
logger.info('Assign badge for user {}'.format(user.name))
badges = _create_badges(user, badge_names, registry)
_assign_badges(user, badges, registry)
transaction.commit()
示例4: add_badge_assignments_services_to_proposal_items
def add_badge_assignments_services_to_proposal_items(root, registry):
"""Add badge assignments services to proposals."""
catalogs = find_service(root, 'catalogs')
query = search_query._replace(interfaces=IMercatorProposal)
proposals = catalogs.search(query).elements
for proposal in proposals:
if find_service(proposal, 'badge_assignments') is None:
logger.info('add badge assignments to {0}'.format(proposal))
add_badge_assignments_service(proposal, registry, {})
示例5: add_logbook_service_to_proposal_items
def add_logbook_service_to_proposal_items(root): # pragma: no cover
"""Add logbook service to proposals."""
catalogs = find_service(root, 'catalogs')
query = search_query._replace(interfaces=IMercatorProposal)
proposals = catalogs.search(query).elements
registry = get_current_registry(root)
for proposal in proposals:
if find_service(proposal, 'logbook') is None:
logger.info('add logbook service to {0}'.format(proposal))
creator = get_sheet_field(proposal, IMetadata, 'creator')
add_logbook_service(proposal, registry, {'creator': creator})
示例6: lower_case_users_emails
def lower_case_users_emails(root, registry): # pragma: no cover
"""Lower case users email, add 'private_user_email'/'user_name' index."""
_update_adhocracy_catalog(root)
catalogs = find_service(root, 'catalogs')
users = find_service(root, 'principals', 'users')
for user in users.values():
if not IUserExtended.providedBy(user):
return
sheet = registry.content.get_sheet(user, IUserExtended)
sheet.set({'email': user.email.lower()})
catalogs.reindex_index(user, 'private_user_email')
catalogs.reindex_index(user, 'user_name')
示例7: lower_case_users_emails
def lower_case_users_emails(root): # pragma: no cover
"""Lower case users email, add 'private_user_email'/'user_name' index."""
_update_adhocracy_catalog(root)
catalogs = find_service(root, "catalogs")
users = find_service(root, "principals", "users")
for user in users.values():
if not IUserExtended.providedBy(user):
return
sheet = get_sheet(user, IUserExtended)
sheet.set({"email": user.email.lower()})
catalogs.reindex_index(user, "private_user_email")
catalogs.reindex_index(user, "user_name")
示例8: add_example_process
def add_example_process(context: IPool, registry: Registry, options: dict):
"""Add meinberlin specific example content."""
registry = get_current_registry(context)
# sample locations
locations = find_service(context, 'locations')
appstructs = {adhocracy_core.sheets.geo.IMultiPolygon.__identifier__:
{'coordinates': POLYGON_ALT_TREPTOW,
'administrative_division': 'bezirksregion'},
adhocracy_core.sheets.name.IName.__identifier__:
{'name': 'alt-treptow'}}
kiezregion = registry.content.create(IMultiPolygon.__identifier__,
parent=locations,
appstructs=appstructs,
registry=registry)
# sample organisation
appstructs = {adhocracy_core.sheets.name.IName.__identifier__:
{'name': 'organisation'}}
registry.content.create(IOrganisation.__identifier__,
parent=context,
appstructs=appstructs,
registry=registry)
# sample kiezkasse
appstructs = {adhocracy_core.sheets.name.IName.__identifier__:
{'name': 'kiezkasse'},
adhocracy_core.sheets.geo.ILocationReference.__identifier__:
{'location': kiezregion},
adhocracy_core.sheets.title.ITitle.__identifier__:
{'title': 'Sample Kiezkassen process'}}
registry.content.create(resources.kiezkassen.IProcess.__identifier__,
parent=context['organisation'],
appstructs=appstructs,
registry=registry)
# sample bplan
office_worker = None
users = find_service(context, 'principals', 'users')
if users is not None: # pragma: no cover
# ease testing
office_worker = users.values()[0]
appstructs = {adhocracy_core.sheets.name.IName.__identifier__:
{'name': 'bplan'},
adhocracy_core.sheets.title.ITitle.__identifier__:
{'title': 'Sample BPlan process'},
adhocracy_meinberlin.sheets.bplan.
IProcessSettings.__identifier__:
{'office_worker': office_worker,
'plan_number': 112233,
'participation_kind': 'öffentliche Auslegung',
'participation_start_date': datetime.date(2015, 5, 5),
'participation_end_date': datetime.date(2015, 6, 11)}}
registry.content.create(resources.bplan.IProcess.__identifier__,
parent=context['organisation'],
appstructs=appstructs,
registry=registry)
示例9: make_users_badgeable
def make_users_badgeable(root, registry): # pragma: no cover
"""Add badge services and make user badgeable."""
principals = find_service(root, 'principals')
if not IHasBadgesPool.providedBy(principals):
logger.info('Add badges service to {0}'.format(principals))
add_badges_service(principals, registry, {})
alsoProvides(principals, IHasBadgesPool)
users = find_service(root, 'principals', 'users')
assignments = find_service(users, 'badge_assignments')
if assignments is None:
logger.info('Add badge assignments service to {0}'.format(users))
add_badge_assignments_service(users, registry, {})
migrate_new_sheet(root, IUser, IBadgeable)
示例10: get_assignable_badges
def get_assignable_badges(context: IBadgeable, request: Request) -> [IBadge]:
"""Get assignable badges for the IBadgeAssignment sheet."""
badges = find_service(context, 'badges')
if badges is None:
return []
catalogs = find_service(context, 'catalogs')
principals = request.effective_principals
query = search_query._replace(root=badges,
interfaces=IBadge,
allows=(principals, 'assign_badge'),
)
result = catalogs.search(query)
return result.elements
示例11: make_users_badgeable
def make_users_badgeable(root): # pragma: no cover
"""Add badge services and make user badgeable."""
registry = get_current_registry(root)
principals = find_service(root, "principals")
if not IHasBadgesPool.providedBy(principals):
logger.info("Add badges service to {0}".format(principals))
add_badges_service(principals, registry, {})
alsoProvides(principals, IHasBadgesPool)
users = find_service(root, "principals", "users")
assignments = find_service(users, "badge_assignments")
if assignments is None:
logger.info("Add badge assignments service to {0}".format(users))
add_badge_assignments_service(users, registry, {})
migrate_new_sheet(root, IUser, IBadgeable)
示例12: test_create_root_with_initial_content
def test_create_root_with_initial_content(self, registry):
from adhocracy_core.resources.root import IRootPool
from adhocracy_core.utils import find_graph
from substanced.util import find_objectmap
from substanced.util import find_catalog
from substanced.util import find_service
inst = registry.content.create(IRootPool.__identifier__)
assert IRootPool.providedBy(inst)
assert find_objectmap(inst) is not None
assert find_graph(inst) is not None
assert find_graph(inst)._objectmap is not None
assert find_catalog(inst, 'system') is not None
assert find_catalog(inst, 'adhocracy') is not None
assert find_service(inst, 'principals', 'users') is not None
assert find_service(inst, 'locations') is not None
示例13: reindex_item_badge
def reindex_item_badge(event):
"""Reindex `item_badge` for all item versions of èvent.object."""
catalogs = find_service(event.object, 'catalogs')
children = event.object.values()
versionables = (c for c in children if IVersionable.providedBy(c))
for versionable in versionables:
catalogs.reindex_index(versionable, 'item_badge')
示例14: _reindex_resource_and_descendants
def _reindex_resource_and_descendants(resource: IResource):
catalogs = find_service(resource, 'catalogs')
if catalogs is None: # ease testing
return
resource_and_descendants = list_resource_with_descendants(resource)
for res in resource_and_descendants:
catalogs.reindex_index(res, 'private_visibility')
示例15: use_workflow_state_for_participation_time_range
def use_workflow_state_for_participation_time_range(root, registry):
"""use workflow state data for participation start and end."""
from adhocracy_core.sheets.workflow import IWorkflowAssignment
from adhocracy_meinberlin.resources.bplan import IProcess
from adhocracy_meinberlin.sheets.bplan import IProcessSettings
catalogs = find_service(root, 'catalogs')
bplaene = _search_for_interfaces(catalogs, IProcess)
for bplan in bplaene:
process_settings_sheet = bplan.\
_sheet_adhocracy_meinberlin_sheets_bplan_IProcessSettings
if ('participation_start_date' in process_settings_sheet
and 'participation_end_date' in process_settings_sheet):
participation_start_date = \
process_settings_sheet['participation_start_date']
participation_end_date = \
process_settings_sheet['participation_end_date']
process_settings = registry.content.get_sheet(bplan,
IProcessSettings)
process_settings.delete_field_values(['participation_start_date'])
process_settings.delete_field_values(['participation_end_date'])
workflow_assignment = registry.content.get_sheet(
bplan,
IWorkflowAssignment)
workflow_assignment.set(
{'state_data': [{'name': 'participate', 'description': '',
'start_date': participation_start_date,
'end_date': participation_end_date}]})