def __call__(self, context): site = get_portal() groups_tool = getToolByName(site, 'portal_groups') is_zope_manager = getSecurityManager().checkPermission( ManagePortal, context) groups = groups_tool.listGroups() # Get group id, title tuples for each, omitting virtual group # 'AuthenticatedUsers' terms = [] for g in groups: if g.id == 'AuthenticatedUsers': continue if 'Manager' in g.getRoles() and not is_zope_manager: continue group_title = safe_unicode(g.getGroupTitleOrName()) if group_title != g.id: title = u'%s (%s)' % (group_title, g.id) else: title = group_title terms.append(SimpleTerm(g.id, g.id, title)) # Sort by title terms.sort(key=lambda x: normalizeString(x.title)) return SimpleVocabulary(terms)
def get_portal_url(context): """DEPRECATED""" warnings.warn( "Instead of Products.CMFPlone.patterns.get_portal_url: " "Use Products.CMFPlone.utils.portal.absolute_url()", DeprecationWarning, ) return utils.get_portal().absolute_url()
def get_portal(): """DEPRECATED""" warnings.warn( "Instead of Products.CMFPlone.patterns.get_portal: " "use Products.CMFPlone.utils.get_portal", DeprecationWarning, ) return utils.get_portal()
def get_portal_url(context): """DEPRECATED """ warnings.warn( 'Instead of Products.CMFPlone.patterns.get_portal_url: ' 'Use Products.CMFPlone.utils.portal.absolute_url()', DeprecationWarning ) return utils.get_portal().absolute_url()
def get_portal(): """DEPRECATED """ warnings.warn( 'Instead of Products.CMFPlone.patterns.get_portal: ' 'use Products.CMFPlone.utils.get_portal', DeprecationWarning ) return utils.get_portal()
def getRegisterSchema(): portal = get_portal() schema = getattr(portal, '_v_register_schema', None) if schema is None: portal._v_register_schema = schema = getFromBaseSchema( ICombinedRegisterSchema, form_name=u'On Registration') # as schema is a generated supermodel, # needed adapters can only be registered at run time provideAdapter(AccountPanelSchemaAdapter, (IPloneSiteRoot, ), schema) return schema
def getUserDataSchema(): portal = get_portal() schema = getattr(portal, '_v_userdata_schema', None) if schema is None: portal._v_userdata_schema = schema = getFromBaseSchema( IUserDataSchema, form_name=u'In User Profile') # as schema is a generated supermodel, # needed adapters can only be registered at run time provideAdapter(UserDataPanelAdapter, (IPloneSiteRoot, ), schema) provideAdapter(UserDataPanelAdapter, (INavigationRoot, ), schema) return schema
def __init__(self, context, request): self.context = context self.request = request self.settings = getUtility(IRegistry).forInterface(ITinyMCESchema, prefix="plone", check=False) self.nav_root = getNavigationRootObject( self.context, get_portal(), ) self.nav_root_url = self.nav_root.absolute_url()
def getRegisterSchema(): portal = get_portal() schema = getattr(portal, '_v_register_schema', None) if schema is None: portal._v_register_schema = schema = getFromBaseSchema( ICombinedRegisterSchema, form_name=u'On Registration' ) # as schema is a generated supermodel, # needed adapters can only be registered at run time provideAdapter(AccountPanelSchemaAdapter, (IPloneSiteRoot,), schema) return schema
def applySchema(snew_schema): site = get_portal() # get the old schema (currently stored in the annotation) old_schema = get_ttw_edited_schema() # check if more than 2 image fields: if snew_schema.count('NamedBlobImage') > 1: site.plone_utils.addPortalMessage( _(u'One image field maximum.'), 'error') return # store the current schema in the annotation set_schema(snew_schema) # load the new schema new_schema = get_ttw_edited_schema() # update portal_memberdata properties pm = getToolByName(site, "portal_memberdata") existing = pm.propertyIds() for field_id in [a for a in new_schema]: field_type = field_type_mapping.get( new_schema[field_id].__class__.__name__, None) if not field_type: log('Unsupported field: %s (%s)' % ( field_id, new_schema[field_id].__class__.__name__)) continue if field_type == '__portrait__': continue if field_id in existing: pm._delProperty(field_id) pm._setProperty( field_id, DEFAULT_VALUES.get(field_type, ''), field_type) if old_schema: to_remove = [field_id for field_id in [a for a in old_schema] if field_id not in [a for a in new_schema]] for field_id in to_remove: field_type = field_type_mapping.get( old_schema[field_id].__class__.__name__, None) if field_type == '__portrait__': continue pm._delProperty(field_id) invalidateSchemasInCache(site)
def getUserDataSchema(): portal = get_portal() schema = getattr(portal, '_v_userdata_schema', None) if schema is None: portal._v_userdata_schema = schema = getFromBaseSchema( IUserDataSchema, form_name=u'In User Profile' ) # as schema is a generated supermodel, # needed adapters can only be registered at run time provideAdapter(UserDataPanelAdapter, (IPloneSiteRoot,), schema) provideAdapter(UserDataPanelAdapter, (INavigationRoot,), schema) return schema
def __init__(self, context, request): self.context = context self.request = request self.settings = getUtility(IRegistry).forInterface( ITinyMCESchema, prefix="plone", check=False ) self.nav_root = getNavigationRootObject( self.context, get_portal(), ) self.nav_root_url = self.nav_root.absolute_url()
def tinymce(self): """ data-pat-tinymce : JSON.stringify({ relatedItems: { vocabularyUrl: config.portal_url + '/@@getVocabulary?name=plone.app.vocabularies.Catalog' }, tiny: config, prependToUrl: 'resolveuid/', linkAttribute: 'UID', prependToScalePart: '/@@images/image/' }) """ generator = TinyMCESettingsGenerator(self.context, self.request) settings = generator.settings folder = aq_inner(self.context) # Test if we are currently creating an Archetype object if IFactoryTempFolder.providedBy(aq_parent(folder)): folder = aq_parent(aq_parent(aq_parent(folder))) if not IFolderish.providedBy(folder): folder = aq_parent(folder) if IPloneSiteRoot.providedBy(folder): initial = None else: initial = IUUID(folder, None) portal = get_portal() portal_url = portal.absolute_url() nav_root = getNavigationRootObject(folder, portal) nav_root_url = nav_root.absolute_url() current_path = folder.absolute_url()[len(portal_url):] image_types = settings.image_objects or [] folder_types = settings.contains_objects or [] server_url = self.request.get('SERVER_URL', '') site_path = portal_url[len(server_url):] configuration = { 'base_url': self.context.absolute_url(), 'imageTypes': image_types, 'imageScales': self.image_scales, 'linkAttribute': 'UID', # This is for loading the languages on tinymce 'loadingBaseUrl': '{0}/++plone++static/components/tinymce-builded/' 'js/tinymce'.format(portal_url), 'relatedItems': { 'folderTypes': folder_types, 'rootPath': '/'.join(nav_root.getPhysicalPath()) if nav_root else '/', 'sort_on': 'sortable_title', 'sort_order': 'ascending', 'vocabularyUrl': '{0}/@@getVocabulary?name=plone.app.vocabularies.' 'Catalog'.format(nav_root_url), }, 'prependToScalePart': '/@@images/image/', 'prependToUrl': '{0}/resolveuid/'.format(site_path.rstrip('/')), 'tiny': generator.get_tiny_config(), 'upload': { 'baseUrl': portal_url, 'currentPath': current_path, 'initialFolder': initial, 'maxFiles': 1, 'relativePath': '@@fileUpload', 'showTitle': False, 'uploadMultiple': False, }, } return {'data-pat-tinymce': json.dumps(configuration)}
def set_schema(string, site=None): if site is None: site = get_portal() annotations = IAnnotations(site) annotations[SCHEMA_ANNOTATION] = string
def tinymce(self): """ data-pat-tinymce : JSON.stringify({ relatedItems: { vocabularyUrl: config.portal_url + '/@@getVocabulary?name=plone.app.vocabularies.Catalog' }, tiny: config, prependToUrl: 'resolveuid/', linkAttribute: 'UID', prependToScalePart: '/@@images/image/' }) """ generator = TinyMCESettingsGenerator(self.context, self.request) settings = generator.settings folder = aq_inner(self.context) # Test if we are currently creating an Archetype object if IFactoryTempFolder.providedBy(aq_parent(folder)): folder = aq_parent(aq_parent(aq_parent(folder))) if not IFolderish.providedBy(folder): folder = aq_parent(folder) if IPloneSiteRoot.providedBy(folder): initial = None else: initial = IUUID(folder, None) portal = get_portal() portal_url = portal.absolute_url() current_path = folder.absolute_url()[len(portal_url):] image_types = settings.image_objects or [] server_url = self.request.get("SERVER_URL", "") site_path = portal_url[len(server_url):] related_items_config = get_relateditems_options( context=self.context, value=None, separator=";", vocabulary_name="plone.app.vocabularies.Catalog", vocabulary_view="@@getVocabulary", field_name=None, ) related_items_config = call_callables(related_items_config, self.context) configuration = { "base_url": self.context.absolute_url(), "imageTypes": image_types, "imageScales": self.image_scales, "linkAttribute": "UID", # This is for loading the languages on tinymce "loadingBaseUrl": "{}/++plone++static/components/tinymce-builded/" "js/tinymce".format(portal_url), "relatedItems": related_items_config, "prependToScalePart": "/@@images/image/", "prependToUrl": "{}/resolveuid/".format(site_path.rstrip("/")), "tiny": generator.get_tiny_config(), "upload": { "baseUrl": portal_url, "currentPath": current_path, "initialFolder": initial, "maxFiles": 1, "relativePath": "@@fileUpload", "showTitle": False, "uploadMultiple": False, }, } return {"data-pat-tinymce": json.dumps(configuration)}
def tinymce(self): """ data-pat-tinymce : JSON.stringify({ relatedItems: { vocabularyUrl: config.portal_url + '/@@getVocabulary?name=plone.app.vocabularies.Catalog' }, tiny: config, prependToUrl: 'resolveuid/', linkAttribute: 'UID', prependToScalePart: '/@@images/image/' }) """ generator = TinyMCESettingsGenerator(self.context, self.request) settings = generator.settings folder = aq_inner(self.context) # Test if we are currently creating an Archetype object if IFactoryTempFolder.providedBy(aq_parent(folder)): folder = aq_parent(aq_parent(aq_parent(folder))) if not IFolderish.providedBy(folder): folder = aq_parent(folder) if IPloneSiteRoot.providedBy(folder): initial = None else: initial = IUUID(folder, None) portal = get_portal() portal_url = portal.absolute_url() nav_root = getNavigationRootObject(folder, portal) nav_root_url = nav_root.absolute_url() current_path = folder.absolute_url()[len(portal_url):] image_types = settings.image_objects or [] folder_types = settings.contains_objects or [] server_url = self.request.get('SERVER_URL', '') site_path = portal_url[len(server_url):] configuration = { 'base_url': self.context.absolute_url(), 'imageTypes': image_types, 'linkAttribute': 'UID', # This is for loading the languages on tinymce 'loadingBaseUrl': '{0}/++plone++static/components/tinymce-builded/' 'js/tinymce'.format(portal_url), 'relatedItems': { 'folderTypes': folder_types, 'rootPath': '/'.join(nav_root.getPhysicalPath()) if nav_root else '/', 'sort_on': 'sortable_title', 'sort_order': 'ascending', 'vocabularyUrl': '{0}/@@getVocabulary?name=plone.app.vocabularies.' 'Catalog'.format(nav_root_url), }, 'prependToScalePart': '/@@images/image/', 'prependToUrl': '{0}/resolveuid/'.format(site_path.rstrip('/')), 'tiny': generator.get_tiny_config(), 'upload': { 'baseUrl': portal_url, 'currentPath': current_path, 'initialFolder': initial, 'maxFiles': 1, 'relativePath': '@@fileUpload', 'showTitle': False, 'uploadMultiple': False, }, } return {'data-pat-tinymce': json.dumps(configuration)}
def tinymce(self): """ data-pat-tinymce : JSON.stringify({ relatedItems: { vocabularyUrl: config.portal_url + '/@@getVocabulary?name=plone.app.vocabularies.Catalog' }, tiny: config, prependToUrl: 'resolveuid/', linkAttribute: 'UID', prependToScalePart: '/@@images/image/' }) """ generator = TinyMCESettingsGenerator(self.context, self.request) settings = generator.settings folder = aq_inner(self.context) # Test if we are currently creating an Archetype object if IFactoryTempFolder.providedBy(aq_parent(folder)): folder = aq_parent(aq_parent(aq_parent(folder))) if not IFolderish.providedBy(folder): folder = aq_parent(folder) if IPloneSiteRoot.providedBy(folder): initial = None else: initial = IUUID(folder, None) portal = get_portal() portal_url = portal.absolute_url() current_path = folder.absolute_url()[len(portal_url):] image_types = settings.image_objects or [] server_url = self.request.get('SERVER_URL', '') site_path = portal_url[len(server_url):] related_items_config = get_relateditems_options( context=self.context, value=None, separator=';', vocabulary_name='plone.app.vocabularies.Catalog', vocabulary_view='@@getVocabulary', field_name=None ) related_items_config = call_callables( related_items_config, self.context ) configuration = { 'base_url': self.context.absolute_url(), 'imageTypes': image_types, 'imageScales': self.image_scales, 'linkAttribute': 'UID', # This is for loading the languages on tinymce 'loadingBaseUrl': '{}/++plone++static/components/tinymce-builded/' 'js/tinymce'.format(portal_url), 'relatedItems': related_items_config, 'prependToScalePart': '/@@images/image/', 'prependToUrl': '{}/resolveuid/'.format(site_path.rstrip('/')), 'tiny': generator.get_tiny_config(), 'upload': { 'baseUrl': portal_url, 'currentPath': current_path, 'initialFolder': initial, 'maxFiles': 1, 'relativePath': '@@fileUpload', 'showTitle': False, 'uploadMultiple': False, }, } return {'data-pat-tinymce': json.dumps(configuration)}
def get_schema(site=None): if site is None: site = get_portal() annotations = IAnnotations(site) return annotations.get(SCHEMA_ANNOTATION, '')