def get_options(self): site = get_top_site_from_url(self.context, self.request) base_url = site.absolute_url() base_vocabulary = '%s/@@getVocabulary?name=' % base_url site_path = site.getPhysicalPath() context_path = self.context.getPhysicalPath() columns = self.get_columns() options = { 'vocabularyUrl': '%splone.app.vocabularies.Catalog' % ( base_vocabulary), 'urlStructure': { 'base': base_url, 'appended': '/folder_contents' }, 'moveUrl': '%s{path}/fc-itemOrder' % base_url, 'indexOptionsUrl': '%s/@@qsOptions' % base_url, 'contextInfoUrl': '%s{path}/@@fc-contextInfo' % base_url, 'setDefaultPageUrl': '%s{path}/@@fc-setDefaultPage' % base_url, 'availableColumns': columns, 'attributes': ['Title', 'path', 'getURL', 'getIcon', 'getMimeIcon', 'portal_type'] + list(columns.keys()), # noqa 'buttons': self.get_actions(), 'rearrange': { 'properties': self.get_indexes(), 'url': '%s{path}/@@fc-rearrange' % base_url }, 'basePath': '/' + '/'.join(context_path[len(site_path):]), 'upload': { 'relativePath': 'fileUpload', 'baseUrl': base_url, 'initialFolder': IUUID(self.context, None), 'useTus': TUS_ENABLED }, 'thumb_scale': self.get_thumb_scale(), } return options
def get_relateditems_options(context, value, separator, vocabulary_name, vocabulary_view, field_name=None): if IForm.providedBy(context): context = context.context request = getRequest() site = get_top_site_from_url(context, request) options = get_ajaxselect_options(site, value, separator, vocabulary_name, vocabulary_view, field_name) msgstr = translate(_(u'Search'), context=request) options.setdefault('searchText', msgstr) msgstr = translate(_(u'Entire site'), context=request) options.setdefault('searchAllText', msgstr) msgstr = translate(_('tabs_home', default=u'Home'), context=request) options.setdefault('homeText', msgstr) options.setdefault('folderTypes', ['Folder']) options.setdefault('sort_on', 'sortable_title') options.setdefault('sort_order', 'ascending') nav_root = getNavigationRootObject(context, site) options['basePath'] = '/'.join(nav_root.getPhysicalPath()) if nav_root else '/' # noqa options['rootPath'] = '/'.join(site.getPhysicalPath()) if site else '/' options['rootUrl'] = site.absolute_url() if site else '' return options
def get_options(self): site = get_top_site_from_url(self.context, self.request) base_url = site.absolute_url() base_vocabulary = '%s/@@getVocabulary?name=' % base_url site_path = site.getPhysicalPath() context_path = self.context.getPhysicalPath() columns = self.get_columns() options = { 'vocabularyUrl': '%splone.app.vocabularies.Catalog' % ( base_vocabulary), 'urlStructure': { 'base': base_url, 'appended': '/folder_contents' }, 'moveUrl': '%s{path}/fc-itemOrder' % base_url, 'indexOptionsUrl': '%s/@@qsOptions' % base_url, 'contextInfoUrl': '%s{path}/@@fc-contextInfo' % base_url, 'setDefaultPageUrl': '%s{path}/@@fc-setDefaultPage' % base_url, 'availableColumns': columns, 'attributes': ['Title', 'path', 'getURL', 'getIcon', 'getMimeIcon', 'portal_type'] + columns.keys(), # noqa 'buttons': self.get_actions(), 'rearrange': { 'properties': self.get_indexes(), 'url': '%s{path}/@@fc-rearrange' % base_url }, 'basePath': '/' + '/'.join(context_path[len(site_path):]), 'upload': { 'relativePath': 'fileUpload', 'baseUrl': base_url, 'initialFolder': IUUID(self.context, None), 'useTus': TUS_ENABLED }, 'thumb_scale': self.get_thumb_scale(), } return options
def __call__(self): factories_menu = getUtility(IBrowserMenu, name='plone_contentmenu_factory', context=self.context).getMenuItems( self.context, self.request) factories = [] for item in factories_menu: if item.get('title') == 'folder_add_settings': continue title = item.get('title', '') factories.append({ 'id': item.get('id'), 'title': title and translate(title, context=self.request) or '', # noqa 'action': item.get('action') }) context = aq_inner(self.context) crumbs = [] top_site = get_top_site_from_url(self.context, self.request) while not context == top_site: crumbs.append({ 'id': context.getId(), 'title': utils.pretty_title_or_id(context, context) }) context = utils.parent(context) catalog = getToolByName(self.context, 'portal_catalog') try: brains = catalog(UID=IUUID(self.context)) except TypeError: brains = [] item = None if len(brains) > 0: obj = brains[0] # context here should be site root base_path = '/'.join(context.getPhysicalPath()) item = {} for attr in self.attributes: key = attr if key == 'path': attr = 'getPath' val = getattr(obj, attr, None) if callable(val): val = val() if key == 'path': val = val[len(base_path):] item[key] = val self.request.response.setHeader('Content-Type', 'application/json; charset=utf-8') return json_dumps({ 'addButtons': factories, 'defaultPage': self.context.getDefaultPage(), 'breadcrumbs': [c for c in reversed(crumbs)], 'object': item })
def __call__(self): factories_menu = getUtility( IBrowserMenu, name='plone_contentmenu_factory', context=self.context).getMenuItems(self.context, self.request) factories = [] for item in factories_menu: if item.get('title') == 'folder_add_settings': continue title = item.get('title', '') factories.append({ 'id': item.get('id'), 'title': title and translate(title, context=self.request) or '', # noqa 'action': item.get('action') }) context = aq_inner(self.context) crumbs = [] top_site = get_top_site_from_url(self.context, self.request) while not context == top_site: crumbs.append({ 'id': context.getId(), 'title': utils.pretty_title_or_id(context, context) }) context = utils.parent(context) catalog = getToolByName(self.context, 'portal_catalog') try: brains = catalog(UID=IUUID(self.context)) except TypeError: brains = [] item = None if len(brains) > 0: obj = brains[0] # context here should be site root base_path = '/'.join(context.getPhysicalPath()) item = {} for attr in self.attributes: key = attr if key == 'path': attr = 'getPath' val = getattr(obj, attr, None) if callable(val): val = val() if key == 'path': val = val[len(base_path):] item[key] = val self.request.response.setHeader( 'Content-Type', 'application/json; charset=utf-8' ) return json_dumps({ 'addButtons': factories, 'defaultPage': self.context.getDefaultPage(), 'breadcrumbs': [c for c in reversed(crumbs)], 'object': item })
def get_relateditems_options(context, value, separator, vocabulary_name, vocabulary_view, field_name=None): if IForm.providedBy(context): context = context.context request = getRequest() site = get_top_site_from_url(context, request) options = get_ajaxselect_options(site, value, separator, vocabulary_name, vocabulary_view, field_name) nav_root = getNavigationRootObject(context, site) # basePath - start to search/browse in here. base_path_context = context if not IFolder.providedBy(base_path_context): base_path_context = aq_parent(base_path_context) if not base_path_context: base_path_context = nav_root options['basePath'] = '/'.join(base_path_context.getPhysicalPath()) # rootPath - Only display breadcrumb elements deeper than this path. options['rootPath'] = '/'.join(site.getPhysicalPath()) if site else '/' # rootUrl: Visible URL up to the rootPath. This is prepended to the # currentPath to generate submission URLs. options['rootUrl'] = site.absolute_url() if site else '' # contextPath - current edited object. Will not be available to select. options['contextPath'] = '/'.join(context.getPhysicalPath()) if base_path_context != nav_root: options['favorites'] = [ { # 'title': _(u'Current Content'), 'title': u'Aktueller Inhalt', 'path': '/'.join(base_path_context.getPhysicalPath()) }, { 'title': _(u'Start Page'), 'path': '/'.join(nav_root.getPhysicalPath()) } ] return options
def get_options(self): site = get_top_site_from_url(self.context, self.request) base_url = site.absolute_url() base_vocabulary = '%s/@@getVocabulary?name=' % getSite().absolute_url() return { 'tooltip': translate(_('Tags'), context=self.request), 'id': 'tags', 'icon': 'tags', 'url': '%s{path}/@@pt-fc-tags' % base_url, 'form': { 'template': self.template( # vocabulary_url='%splone.app.vocabularies.Keywords' % ( vocabulary_url='%scollective.gtags.ProjectKeywords' % ( base_vocabulary) ) } }
def site(self): return get_top_site_from_url(self.context, self.request)
def get_relateditems_options(context, value, separator, vocabulary_name, vocabulary_view, field_name=None, include_recently_added=True): if IForm.providedBy(context): context = context.context request = getRequest() site = get_top_site_from_url(context, request) options = get_ajaxselect_options( site, value, separator, vocabulary_name, vocabulary_view, field_name ) nav_root = getNavigationRootObject(context, site) if not ISimpleItem.providedBy(context): context = nav_root # basePath - start to search/browse in here. base_path_context = context if not IFolder.providedBy(base_path_context): base_path_context = aq_parent(base_path_context) if not base_path_context: base_path_context = nav_root options['basePath'] = '/'.join(base_path_context.getPhysicalPath()) # rootPath - Only display breadcrumb elements deeper than this path. options['rootPath'] = '/'.join(site.getPhysicalPath()) if site else '/' # rootUrl: Visible URL up to the rootPath. This is prepended to the # currentPath to generate submission URLs. options['rootUrl'] = site.absolute_url() if site else '' # contextPath - current edited object. Will not be available to select. options['contextPath'] = '/'.join(context.getPhysicalPath()) if base_path_context != nav_root: options['favorites'] = [ { 'title': _(u'Current Content'), 'path': '/'.join(base_path_context.getPhysicalPath()) }, { 'title': _(u'Start Page'), 'path': '/'.join(nav_root.getPhysicalPath()) } ] if include_recently_added: # Options for recently used key tool = getToolByName(context, 'portal_membership') user = tool.getAuthenticatedMember() options['recentlyUsed'] = False # Keep that off in Plone 5.1 options['recentlyUsedKey'] = (u'relateditems_recentlyused_%s_%s' % ( field_name or '', user.id )) # use string substitution with %s here for automatic str casting. return options
def get_relateditems_options(context, value, separator, vocabulary_name, vocabulary_view, field_name=None, include_recently_added=True): if IForm.providedBy(context): context = context.context request = getRequest() site = get_top_site_from_url(context, request) options = { 'separator': separator, } if not vocabulary_name: # we need a vocabulary! raise ValueError('RelatedItems needs a vocabulary') options['vocabularyUrl'] = '{0}/{1}?name={2}'.format( get_context_url(site), vocabulary_view, vocabulary_name, ) if field_name: options['vocabularyUrl'] += '&field={0}'.format(field_name) if value: options['initialValues'] = {} catalog = False if vocabulary_name == 'plone.app.vocabularies.Catalog': catalog = getToolByName(getSite(), 'portal_catalog') for value in value.split(separator): title = value if catalog: result = catalog(UID=value) title = result[0].Title if result else value options['initialValues'][value] = title nav_root = getNavigationRootObject(context, site) if not ISimpleItem.providedBy(context): context = nav_root # basePath - start to search/browse in here. base_path_context = context if not IFolder.providedBy(base_path_context): base_path_context = aq_parent(base_path_context) if not base_path_context: base_path_context = nav_root options['basePath'] = '/'.join(base_path_context.getPhysicalPath()) # rootPath - Only display breadcrumb elements deeper than this path. options['rootPath'] = '/'.join(site.getPhysicalPath()) if site else '/' # rootUrl: Visible URL up to the rootPath. This is prepended to the # currentPath to generate submission URLs. options['rootUrl'] = site.absolute_url() if site else '' # contextPath - current edited object. Will not be available to select. options['contextPath'] = '/'.join(context.getPhysicalPath()) if base_path_context != nav_root: options['favorites'] = [{ 'title': _(u'Current Content'), 'path': '/'.join(base_path_context.getPhysicalPath()) }, { 'title': _(u'Start Page'), 'path': '/'.join(nav_root.getPhysicalPath()) }] if include_recently_added: # Options for recently used key tool = getToolByName(context, 'portal_membership') user = tool.getAuthenticatedMember() options['recentlyUsed'] = False # Keep that off in Plone 5.1 options['recentlyUsedKey'] = ( u'relateditems_recentlyused_%s_%s' % (field_name or '', user.id) ) # use string substitution with %s here for automatic str casting. return options