def items(self):
        catalog = getToolByName(self.context, 'portal_catalog')
        # Get the path of where the portlet is created. That's the blog.
        assignment_context = find_assignment_context(self.data, self.context)
        if assignment_context is None:
            assignment_context = self.context
        folder_path = '/'.join(assignment_context.getPhysicalPath())
        # Because of ExtendedPathIndex being braindead it's tricky (read:
        # impossible) to get all subobjects for all folder, without also
        # getting the folder. So we set depth to 1, which means we only get
        # the immediate children. This is not a bug, but a lack of feature.
        # Find the blog types:
        portal_properties = getToolByName(self.context, 'portal_properties',
                                          None)
        site_properties = getattr(portal_properties, 'site_properties', None)
        portal_types = site_properties.getProperty('blog_types', None)
        if portal_types == None:
            portal_types = ('Document', 'News Item', 'File')

        brains = catalog(path={
            'query': folder_path,
            'depth': 1
        },
                         portal_type=portal_types,
                         sort_on='effective',
                         sort_order='reverse')
        return brains[:self.data.entries]
Пример #2
0
    def update(self):
        self._counts = {}
        catalog = getToolByName(self.context, 'portal_catalog')
        # Get the path of where the portlet is created. That's the blog.
        assignment_context = find_assignment_context(self.data, self.context)
        if assignment_context is None:
            assignment_context = self.context
        self.folder_path = '/'.join(assignment_context.getPhysicalPath())
        self.folder_url = assignment_context.absolute_url()

        # Find the blog types:
        portal_properties = getToolByName(self.context, 'portal_properties',
                                          None)
        site_properties = getattr(portal_properties, 'site_properties', None)
        portal_types = site_properties.getProperty('blog_types', None)
        if portal_types == None:
            portal_types = ('Document', 'News Item', 'File')

        # Because of ExtendedPathIndex being braindead it's tricky (read:
        # impossible) to get all subobjects for all folders, without also
        # getting the folder. So we set a specific depth.
        brains = catalog(path={
            'query': self.folder_path,
            'depth': self.data.depth + 1
        },
                         portal_type=portal_types)
        if not brains:
            return

        # Count the number of posts per month:
        allmonths = {}
        for brain in brains:
            effective = brain.effective
            year = str(effective.year())
            if year == '1000':
                continue  # No effective date == not published
            month = str(effective.month())
            count = allmonths.setdefault((year, month), 0)
            allmonths[(year, month)] = count + 1

        for year, month in allmonths:
            year = str(year)
            month = str(month)
            # Make sure there is a year in the _counts dict:
            self._counts.setdefault(year, {})
            # Add this month:
            months = self._counts[year]
            months[month] = allmonths[year, month]
Пример #3
0
    def update(self):
        self._counts = {}
        catalog = getToolByName(self.context, 'portal_catalog')
        # Get the path of where the portlet is created. That's the blog.
        assignment_context = find_assignment_context(self.data, self.context)
        if assignment_context is None:
            assignment_context = self.context
        self.folder_path = '/'.join(assignment_context.getPhysicalPath())
        self.folder_url = assignment_context.absolute_url()

        # Find the blog types:
        portal_properties = getToolByName(self.context, 'portal_properties', None)
        site_properties = getattr(portal_properties, 'site_properties', None)
        portal_types = site_properties.getProperty('blog_types', None)
        if portal_types == None:
            portal_types = ('Document', 'News Item', 'File')

        # Because of ExtendedPathIndex being braindead it's tricky (read:
        # impossible) to get all subobjects for all folders, without also
        # getting the folder. So we set a specific depth.
        brains = catalog(path={'query': self.folder_path, 'depth': self.data.depth + 1},
                         portal_type=portal_types)
        if not brains:
            return

        # Count the number of posts per month:
        allmonths = {}
        for brain in brains:
            effective = brain.effective
            year = str(effective.year())
            if year == '1000':
                continue # No effective date == not published
            month = str(effective.month())
            count = allmonths.setdefault((year, month), 0)
            allmonths[(year, month)] = count +1

        for year, month in allmonths:
            year = str(year)
            month = str(month)
            # Make sure there is a year in the _counts dict:
            self._counts.setdefault(year, {})
            # Add this month:
            months = self._counts[year]
            months[month] = allmonths[year, month]
    def items(self):
        catalog = getToolByName(self.context, "portal_catalog")
        # Get the path of where the portlet is created. That's the blog.
        assignment_context = find_assignment_context(self.data, self.context)
        folder_path = "/".join(assignment_context.getPhysicalPath())
        # Find the blog types:
        portal_properties = getToolByName(self.context, "portal_properties", None)
        site_properties = getattr(portal_properties, "site_properties", None)
        portal_types = site_properties.getProperty("blog_types", None)
        if self.data.root:
            rootPath = getToolByName(self, "portal_url").getPortalPath()
            folder_path = rootPath + self.data.root
        if portal_types == None:
            portal_types = ("Document", "News Item", "File")

        brains = catalog(
            path={"query": folder_path}, portal_type=portal_types, sort_on="effective", sort_order="reverse"
        )
        return brains[: self.data.entries]
Пример #5
0
    def update(self):
        self._counts = {}
        catalog = getToolByName(self.context, 'portal_catalog')
        # Get the path of where the portlet is created. That's the blog.
        assignment_context = find_assignment_context(self.data, self.context)
        self.folder_path = '/'.join(assignment_context.getPhysicalPath())
        self.folder_url = assignment_context.absolute_url()

        # Find the blog types:
        portal_properties = getToolByName(self.context, 'portal_properties', None)
        site_properties = getattr(portal_properties, 'site_properties', None)
        portal_types = site_properties.getProperty('blog_types', None)
        if portal_types == None:
            portal_types = ('Document', 'News Item', 'File')

        if self.data.root:
            rootPath = getToolByName(self, 'portal_url').getPortalPath()
            self.folder_path = rootPath + self.data.root
        brains = catalog(path={'query': self.folder_path},
                         portal_type=portal_types)
        if not brains:
            return

        # Count the number of posts per month:
        allmonths = {}
        for brain in brains:
            effective = brain.effective
            year = str(effective.year())
            if year == '1000':
                continue # No effective date == not published
            month = str(effective.month())
            count = allmonths.setdefault((year, month), 0)
            allmonths[(year, month)] = count +1

        for year, month in allmonths:
            year = str(year)
            month = str(month)
            # Make sure there is a year in the _counts dict:
            self._counts.setdefault(year, {})
            # Add this month:
            months = self._counts[year]
            months[month] = allmonths[year, month]
    def items(self):
        catalog = getToolByName(self.context, 'portal_catalog')
        # Get the path of where the portlet is created. That's the blog.
        assignment_context = find_assignment_context(self.data, self.context)
        folder_path = '/'.join(assignment_context.getPhysicalPath())
        # Because of ExtendedPathIndex being braindead it's tricky (read:
        # impossible) to get all subobjects for all folder, without also
        # getting the folder. So we set depth to 1, which means we only get
        # the immediate children. This is not a bug, but a lack of feature.
        # Find the blog types:
        portal_properties = getToolByName(self.context, 'portal_properties', None)
        site_properties = getattr(portal_properties, 'site_properties', None)
        portal_types = site_properties.getProperty('blog_types', None)
        if portal_types == None:
            portal_types = ('Document', 'News Item', 'File')

        brains = catalog(path={'query': folder_path, 'depth': 1},
                         portal_type=portal_types,
                         sort_on='effective', sort_order='reverse')
        return brains[:self.data.entries]