本文整理汇总了Python中substanced.util.find_service函数的典型用法代码示例。如果您正苦于以下问题:Python find_service函数的具体用法?Python find_service怎么用?Python find_service使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_service函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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')
开发者ID:robx,项目名称:adhocracy3.mercator,代码行数:7,代码来源:test_principal.py
示例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()
开发者ID:liqd,项目名称:adhocracy3,代码行数:34,代码来源:root.py
示例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()
开发者ID:robx,项目名称:adhocracy3.mercator,代码行数:28,代码来源:import_users.py
示例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, {})
开发者ID:liqd,项目名称:adhocracy3,代码行数:9,代码来源:__init__.py
示例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})
开发者ID:robx,项目名称:adhocracy3.mercator,代码行数:11,代码来源:__init__.py
示例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')
开发者ID:Janaba,项目名称:adhocracy3,代码行数:12,代码来源:__init__.py
示例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")
开发者ID:pra85,项目名称:adhocracy3,代码行数:12,代码来源:__init__.py
示例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)
开发者ID:andantic,项目名称:adhocracy3,代码行数:53,代码来源:root.py
示例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)
开发者ID:Janaba,项目名称:adhocracy3,代码行数:13,代码来源:__init__.py
示例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
开发者ID:robx,项目名称:adhocracy3.mercator,代码行数:13,代码来源:badge.py
示例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)
开发者ID:pra85,项目名称:adhocracy3,代码行数:14,代码来源:__init__.py
示例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
开发者ID:robx,项目名称:adhocracy3.mercator,代码行数:15,代码来源:test_root.py
示例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')
开发者ID:liqd,项目名称:adhocracy3,代码行数:7,代码来源:subscriber.py
示例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')
开发者ID:liqd,项目名称:adhocracy3,代码行数:7,代码来源:subscriber.py
示例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}]})
开发者ID:Janaba,项目名称:adhocracy3,代码行数:27,代码来源:__init__.py
示例16: change_bplan_officeworker_email_representation
def change_bplan_officeworker_email_representation(root, registry):
"""Change bplan officeworker email representation."""
from substanced.util import find_objectmap
from adhocracy_core.utils import find_graph
from adhocracy_meinberlin.resources.bplan import IProcess
from adhocracy_meinberlin.sheets.bplan import IProcessSettings
from adhocracy_meinberlin.sheets.bplan import IProcessPrivateSettings
from adhocracy_meinberlin.sheets.bplan import OfficeWorkerUserReference
migrate_new_sheet(root, IProcess, IProcessPrivateSettings)
catalogs = find_service(root, 'catalogs')
bplaene = _search_for_interfaces(catalogs, IProcess)
objectmap = find_objectmap(root)
graph = find_graph(root)
for bplan in bplaene:
process_settings_ref = graph.get_references_for_isheet(
bplan,
IProcessSettings)
if 'office_worker' in process_settings_ref:
office_worker = process_settings_ref['office_worker'][0]
private_settings = registry.content.get_sheet(
bplan,
IProcessPrivateSettings)
private_settings.set({'office_worker_email': office_worker.email})
objectmap.disconnect(bplan, office_worker,
OfficeWorkerUserReference)
开发者ID:Janaba,项目名称:adhocracy3,代码行数:25,代码来源:__init__.py
示例17: start
def start(self, context, request, appstruct, **kw):
login = appstruct['email']
adapter = request.registry.queryMultiAdapter(
(context, request),
IUserLocator
)
if adapter is None:
adapter = DefaultUserLocator(context, request)
user = adapter.get_user_by_email(login)
if user is not None:
principals = find_service(user, 'principals')
reset = principals.add_reset(user)
reseturl = request.resource_url(reset)
if not user.email:
raise ValueError('User does not possess a valid email address.')
subject = RESETPW_SUBJECT.format(novaideo_title=request.root.title)
localizer = request.localizer
message = RESETPW_MESSAGE.format(
recipient_title=localizer.translate(_(getattr(user, 'user_title',''))),
recipient_first_name=getattr(user, 'first_name', user.name),
recipient_last_name=getattr(user, 'last_name',''),
reseturl=reseturl,
novaideo_title=request.root.title
)
mailer_send(subject=subject,
recipients=[user.email],
body=message)
return {}
开发者ID:jean,项目名称:nova-ideo,代码行数:31,代码来源:reset_password.py
示例18: add_user
def add_user(root, login: str=None, password: str=None, email: str=None,
roles=None, registry=None) -> str:
"""Add user to :app:`Pyramid`."""
from substanced.util import find_service
from adhocracy_core.resources.principal import IUser
import adhocracy_core.sheets
users = find_service(root, 'principals', 'users')
roles = roles or []
passwd_sheet = adhocracy_core.sheets.principal.IPasswordAuthentication
appstructs =\
{adhocracy_core.sheets.principal.IUserBasic.__identifier__:
{'name': login},
adhocracy_core.sheets.principal.IUserExtended.__identifier__:
{'email': email},
adhocracy_core.sheets.principal.IPermissions.__identifier__:
{'roles': roles},
passwd_sheet.__identifier__:
{'password': password},
}
user = registry.content.create(IUser.__identifier__,
parent=users,
appstructs=appstructs,
registry=registry,
run_after_creation=False,
)
user.activate()
return user
开发者ID:andantic,项目名称:adhocracy3,代码行数:27,代码来源:testing.py
示例19: update_comments_count
def update_comments_count(resource: ICommentVersion,
delta: int,
registry: Registry):
"""Update all commentable resources related to `resource`.
Traverse all commentable resources that have a IComment or ISubresource
reference to `resource` and update the comment_count value with `delta`.
Example reference structure that is traversed:
comment <-IComment- comment <-IComment- comment
"""
catalogs = find_service(resource, 'catalogs')
traverse = ReferenceComparator.traverse.value
query = search_query._replace(
only_visible=True,
references=((traverse,
(resource, sheets.comment.IComment, '', None)),
),
resolve=True,
)
commentables = catalogs.search(query).elements
for commentable in commentables:
commentable_sheet = registry.content.get_sheet(commentable,
ICommentable)
old_count = commentable_sheet.get()['comments_count']
commentable_sheet.set({'comments_count': old_count + delta},
omit_readonly=False)
开发者ID:pra85,项目名称:adhocracy3,代码行数:28,代码来源:subscriber.py
示例20: delete_password_resets
def delete_password_resets(request: Request, age_in_days: int):
"""Delete password resets that are older than `age_in_days`."""
resets = find_service(request.root, 'principals', 'resets')
expired = [u for u in resets.values() if is_older_than(u, age_in_days)]
for reset in expired:
logger.info('deleting reset {0}'.format(reset))
del resets[reset.__name__]
开发者ID:Janaba,项目名称:adhocracy3,代码行数:7,代码来源:principal.py
注:本文中的substanced.util.find_service函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论