示例#1
0
 def getAddableTypes(self):
     collage_options = getCollageSiteOptions()
     plone_view = self.context.restrictedTraverse('@@plone')
     container = plone_view.getCurrentFolder()
     idnormalizer = queryUtility(IIDNormalizer)
     try:
         # Plone 4
         factories_view = getMultiAdapter((self.context, self.request),
                                          name='folder_factories')
         allowed_types = [
             i for i in factories_view.addable_types()
             if collage_options.enabledType(i['id'])
         ]
         return allowed_types
     except Exception:
         # BBB Not completely implemented as it seems.
         # This code is probably dead, because nothing is returned?
         portal_url = getToolByName(self.context, 'portal_url')()
         results = []
         for t in container.getAllowedTypes():
             if collage_options.enabledType(t.getId()):
                 cssId = idnormalizer.normalize(t.getId())
                 cssClass = 'contenttype-%s' % cssId
                 results.append({
                     'id': t.getId(),
                     'title': t.Title(),
                     'description': t.Description(),
                     'icon': '%s/%s' % (portal_url, t.getIcon()),
                     'extra': {
                         'id': cssId,
                         'separator': None,
                         'class': cssClass,
                     },
                 })
示例#2
0
文件: views.py 项目: Vinsurya/Plone
    def getColumnBatches(self, bsize=None):
        """Rows with more than *bsize* columns are split.

        @param bsize: number of max. allowed columns per row. 0 for no batching.

        @return: list of columns, each containing a list of rows.
        """
        if not bsize:
            options = getCollageSiteOptions()
            if not hasattr(options, 'batch_size'):
                bsize = 3
            else:
                bsize = options.batch_size

        columns = self.context.folderlistingFolderContents()
        if not columns:
            return []
        if bsize == 0:
            return [columns, ]
        numbatches = (len(columns) - 1) / bsize + 1
        batches = []
        for numbatch in range(numbatches):
            batch = []
            for bidx in range(bsize):
                index = numbatch * bsize + bidx
                column = None
                if index < len(columns):
                    column = columns[index]
                # pad with null-columns, but do not pad first row
                if column or numbatch > 0:
                    batch.append(column)
            batches.append(batch)
        return batches
示例#3
0
    def getAddableTypes(self):
        collage_options = getCollageSiteOptions()
        plone_view = self.context.restrictedTraverse('@@plone')
        container = plone_view.getCurrentFolder()
        idnormalizer = queryUtility(IIDNormalizer)

        #BBB Plone 4
        try:
            factories_view = getMultiAdapter((self.context, self.request),
                                             name='folder_factories')
            allowed_types = [i for i in factories_view.addable_types() if
                             collage_options.enabledType(i['id'])]

            return allowed_types
        except:
            portal_url = getToolByName(self.context, 'portal_url')()
            results = []
            for t in container.getAllowedTypes():
                if collage_options.enabledType(t.getId()):
                    cssId = idnormalizer.normalize(t.getId())
                    cssClass = 'contenttype-%s' % cssId
                    results.append({'title': t.Title(),
                                    'description': t.Description(),
                                    'icon': '%s/%s' % (portal_url, t.getIcon()),
                                    'extra': {'id' : cssId, 'separator' : None,
                                              'class' : cssClass},
                                    'id': t.getId()})
示例#4
0
 def readitems(self):
     options = getCollageSiteOptions()
     if (options.ref_browser_empty
             and self.request.form.get('portal_type', '') == ''
             and self.request.form.get('path', '') == ''
             and self.request.form.get('b_start', None) is None):
         return False
     return True
 def readitems(self):
     options = getCollageSiteOptions()
     if (
         options.ref_browser_empty
         and self.request.form.get("portal_type", "") == ""
         and self.request.form.get("path", "") == ""
         and self.request.form.get("b_start", None) is None
     ):
         return False
     return True
示例#6
0
 def listEnabledTypes(self):
     """Enabled types in a Collage as list of dicts.
     """
     actual_portal_type = self.request.get('portal_type', None)
     collage_options = getCollageSiteOptions()
     ttool = getToolByName(self.context, 'portal_types', None)
     if ttool is None:
         return None
     return [{'id': pt.getId(),
              'title': p_(pt.Title()),
              'selected': pt.getId() == actual_portal_type and 'selected' or None}
             for pt in ttool.listTypeInfo()
             if collage_options.enabledAlias(pt.getId())]
 def typefilter(self):
     options = getCollageSiteOptions()
     if not options.ref_browser_types:
         return list()
     ret = [{"title": "", "value": "", "selected": False}]
     factory = getUtility(IVocabularyFactory, name=u"collage.vocabularies.CollageUserFriendlyTypes")
     for term in factory(self.context):
         if options.use_whitelist:
             if not term.value in options.alias_whitelist:
                 continue
         selected = self.request.form.get("portal_type") == term.value and True or False
         ret.append({"title": term.title, "value": term.value, "selected": selected})
     return ret
示例#8
0
 def listEnabledTypes(self):
     """Enabled types in a Collage as list of dicts.
     """
     actual_type = self.request.get('portal_type', None)
     collage_options = getCollageSiteOptions()
     ttool = getToolByName(self.context, 'portal_types', None)
     if ttool is None:
         return None
     return [{
         'id': pt.getId(),
         'title': p_(pt.Title()),
         'selected': pt.getId() == actual_type and 'selected' or None
     } for pt in ttool.listTypeInfo()
             if collage_options.enabledAlias(pt.getId())]
 def listEnabledTypes(self):
     """Enabled types in a Collage as list of dicts.
     """
     actual_portal_type = self.request.get("portal_type", None)
     collage_options = getCollageSiteOptions()
     ttool = getToolByName(self.context, "portal_types", None)
     if ttool is None:
         return None
     return [
         {
             "id": pt.getId(),
             "title": p_(pt.Title()),
             "selected": pt.getId() == actual_portal_type and "selected" or None,
         }
         for pt in ttool.listTypeInfo()
         if collage_options.enabledAlias(pt.getId())
     ]
示例#10
0
 def typefilter(self):
     options = getCollageSiteOptions()
     if not options.ref_browser_types:
         return list()
     ret = [{'title': '', 'value': '', 'selected': False}]
     factory = getUtility(IVocabularyFactory,
                      name=u'collage.vocabularies.CollageUserFriendlyTypes')
     for term in factory(self.context):
         if options.use_whitelist:
             if not term.value in options.alias_whitelist:
                 continue
         selected = self.request.form.get('portal_type') == term.value \
             and True or False
         ret.append({
             'title': term.title,
             'value': term.value,
             'selected': selected,
         })
     return ret
示例#11
0
 def typefilter(self):
     options = getCollageSiteOptions()
     if not options.ref_browser_types:
         return list()
     ret = [{'title': '', 'value': '', 'selected': False}]
     factory = getUtility(
         IVocabularyFactory,
         name=u'collage.vocabularies.CollageUserFriendlyTypes')
     for term in factory(self.context):
         if options.use_whitelist:
             if term.value not in options.alias_whitelist:
                 continue
         selected = self.request.form.get('portal_type') == term.value \
             and True or False
         ret.append({
             'title': term.title,
             'value': term.value,
             'selected': selected,
         })
     return ret
示例#12
0
    def getColumnBatches(self, bsize=None):
        """Rows with more than *bsize* columns are split.

        @param bsize: number of max. allowed columns per row.
                      0 for no batching.

        @return: list of columns, each containing a list of rows.
        """
        if not bsize:
            options = getCollageSiteOptions()
            if not hasattr(options, 'batch_size'):
                bsize = 3
            else:
                bsize = options.batch_size

        columns = self.context.folderlistingFolderContents()
        if not columns:
            return []
        if bsize == 0:
            return [
                columns,
            ]
        numbatches = (len(columns) - 1) / bsize + 1
        batches = []
        for numbatch in range(numbatches):
            batch = []
            for bidx in range(bsize):
                index = numbatch * bsize + bidx
                column = None
                if index < len(columns):
                    column = columns[index]
                # pad with null-columns, but do not pad first row
                if column or numbatch > 0:
                    batch.append(column)
            batches.append(batch)
        return batches
示例#13
0
 def readitems(self):
     options = getCollageSiteOptions()
     return not (options.ref_browser_empty
                 and self.request.form.get('portal_type', '') == ''
                 and self.request.form.get('path', '') == ''
                 and self.request.form.get('b_start', None) is None)