def loop_task_scheduler_info_factory(context): """Loop-style task scheduling info factory""" return get_annotation_adapter(context, SCHEDULER_TASK_LOOP_INFO, ILoopTaskScheduling, notify=False, locate=False)
def cron_task_scheduler_info_factory(context): """Cron-style task scheduling info factory""" return get_annotation_adapter(context, SCHEDULER_TASK_CRON_INFO, ICronTaskScheduling, notify=False, locate=False)
def __init__(self, image): self.image = image self.thumbnails = get_annotation_adapter(image, THUMBNAIL_ANNOTATIONS_KEY, OOBTree.OOBTree, notify=False, locate=False)
def date_task_scheduler_info_factory(context): """Date-style task scheduling info factory""" return get_annotation_adapter(context, SCHEDULER_TASK_DATE_INFO, IDateTaskScheduling, notify=False, locate=False)
def set_geometry(self, selection_name, geometry): """Set geometry for given selection name""" geometries = get_annotation_adapter(self.image, THUMBNAIL_GEOMETRY_KEY, PersistentDict, notify=False, locate=False) geometries[selection_name] = geometry for current_thumbnail_name in list(self.thumbnails.keys()): if (current_thumbnail_name == selection_name) or \ current_thumbnail_name.startswith('{0}:'.format(selection_name)): self.delete_thumbnail(current_thumbnail_name)
def get_geometry(self, selection_name): """Get geometry matching given selection name""" geometries = get_annotation_adapter(self.image, THUMBNAIL_GEOMETRY_KEY, default={}) # get default geometry for custom thumbnails if ':' in selection_name: selection_name, options = selection_name.split(':', 1) else: options = None if selection_name in geometries: return geometries[selection_name] registry = check_request().registry thumbnailer = registry.queryAdapter(self.image, IThumbnailer, name=selection_name) if thumbnailer is not None: return thumbnailer.get_default_geometry(options) return None
def principal_profile_factory(principal): """Principal public profile factory adapter Public profile is stored using IPrincipalAnnotations utility (using the IPrincipalInfo to IAnnotations adapter defined into :py:mod:pyams_security.principal module). """ def public_profile_callback(profile): """Public profile creation callback""" request = get_current_request() if request is not None: root = request.root intids = get_utility(IIntIds) locate(profile, root) # avoid NotYet exception locate(profile, root, '++profile++{0}'.format(intids.register(profile))) return get_annotation_adapter(principal, PUBLIC_PROFILE_KEY, IPublicProfile, locate=False, callback=public_profile_callback)
def upgrade_site(request): """Upgrade site when needed This function is executed by *pyams_upgrade* console script. Site generations are registered named utilities providing :py:class:`ISiteGenerations <pyams_utils.interfaces.site.ISiteGenerations>` interface. Current site generations are stored into annotations for each generation adapter. """ application = site_factory(request) if application is not None: try: set_local_registry(application.getSiteManager()) generations = get_annotation_adapter(application, SITE_GENERATIONS_KEY, PersistentMapping, notify=False, locate=False) for name, utility in sorted(get_utilities_for(ISiteGenerations), key=lambda x: x[1].order): if not name: name = '.'.join( (utility.__module__, utility.__class__.__name__)) current = generations.get(name) if not current: print("Upgrading {0} to generation {1}...".format( name, utility.generation)) elif current < utility.generation: print("Upgrading {0} from generation {1} to {2}...".format( name, current, utility.generation)) utility.evolve(application, current) generations[name] = utility.generation finally: set_local_registry(None) import transaction # pylint: disable=import-outside-toplevel transaction.commit() return application
def workflow_content_publication_info_factory(context): """Workflow content info factory""" return get_annotation_adapter(context, WORKFLOW_CONTENT_KEY, IWorkflowPublicationInfo)
def protected_object_factory(context): """Default protected object factory""" return get_annotation_adapter(context, POLICY_ANNOTATIONS_KEY, IRoleProtectedObject)
def document_container_synchronizer(context): """Document container synchronizer adapter""" return get_annotation_adapter(context, DOCUMENT_SYNCHRONIZER_KEY, IDocumentSynchronizer)
def task_notifications_container_factory(context): """Task notifications container factory""" return get_annotation_adapter(context, SCHEDULER_TASK_NOTIFICATIONS_KEY, ITaskNotificationContainer, name='++notify++')
def clear_geometries(self): """Clear all stored geometries""" geometries = get_annotation_adapter(self.image, THUMBNAIL_GEOMETRY_KEY) if geometries is not None: for geometry_name in list(geometries.keys()): del geometries[geometry_name]
def get_instance_attributes(instance): """Get file attributes of given instance""" return get_annotation_adapter(instance, FILE_CONTAINER_ATTRIBUTES, set, notify=False, locate=False)
def security_notification_factory(context): """Security manager notifications factory adapter""" return get_annotation_adapter(context, NOTIFICATIONS_KEY, INotificationSettings, locate=False)
def securiy_manager_jwt_configuration_factory(context): """Security manager JWT configuration factory adapter""" return get_annotation_adapter(context, JWT_CONFIGURATION_KEY, IJWTSecurityConfiguration)
def workflow_version_state_factory(context): """Workflow content version state factory""" return get_annotation_adapter(context, WORKFLOW_VERSION_KEY, IWorkflowState)
def workflow_content_versions_factory(context): """Workflow versions factory""" return get_annotation_adapter(context, WORKFLOW_VERSIONS_KEY, IWorkflowVersions, name='++versions++')
def zmi_configuration_factory(context): """ZMI configuration factory""" return get_annotation_adapter(context, ZMI_CONFIGURATION_KEY, IZMIConfiguration, notify=False, name='++etc++zmi.configuration')