示例#1
0
文件: archive.py 项目: vwc/vwc.blog
    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_portlet_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()
        brains = catalog(path={'query': self.folder_path, 'depth': 3},
                         object_provides=IBlogEntry.__identifier__,)
        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]
示例#2
0
 def archive_url(self, subject):
     # Get the path of where the portlet is created. That's the blog.
     assignment_context = find_portlet_assignment_context(self.data,
                                                          self.context)
     if assignment_context is None:
         assignment_context = aq_inner(self.context)
     self.folder_url = assignment_context.absolute_url()
     sub = urllib2.quote(subject.encode('utf-8'))
     url = '%s/%s?category=%s' % (self.folder_url,
                                  self.data.archive_view,
                                  sub)
     return url
示例#3
0
 def blog_url(self):
     assignment_context = find_portlet_assignment_context(self.data,
                                                          self.context)
     if assignment_context is None:
         assignment_context = aq_inner(self.context)
     return assignment_context.absolute_url()