22 February
2007

This blog is based on the Zope product COREBlog. While COREBlog 1.2.5 (and prior) allow an article to be assigned to both primary and secondary when created, the secondary categories are not used in in the blog index, which seems like a clear oversight.

Sascha Welter noticed this, figured out the problem, and fixed it with a patch for an earlier version of COREBlog. That patch isn't quite right for COREBlog 1.2.5, but the trivially modified patch below seems to do the job (see the extended version of this article by clicking the 'permalink' or 'read more' links below).

Note the counts of the number of entries per category will then look wrong, since they only reflect the primary category of each article. Fixing this requires a second patch which I cooked up (see the extended version of this article for details and patches, by clicking the 'permalink' or 'Continue reading' links below).


Patch1: fixing the categories:

*** COREBlog-original.py        Thu Feb 22 19:11:05 2007
--- COREBlog.py Thu Feb 22 19:12:54 2007
***************
*** 912,918 ****
          l = []
          for id in self.entry_list:
              obj = self.getEntry(id)
!             if obj.category and obj.category[0] == category_id:
                  if not consider_moderation or (obj.moderated and obj.date_created() <= DateTime()):
                      l.append(obj)
          return l
--- 912,920 ----
          l = []
          for id in self.entry_list:
              obj = self.getEntry(id)
!             # line below modified to check for id and any of the object categories,
!             # not just the first (primary) one. GD.
!             if obj.category and category_id in obj.category:
                  if not consider_moderation or (obj.moderated and obj.date_created() <= DateTime()):
                      l.append(obj)
          return l

To fix the item counts, the second patch below also needs to be added. This correctly updates the counts for any new articles, but not for old ones. To force all the counts to be recomputed for all existing articles, you can visit the method "manage_calculateCategory" from the browser (e.g. http://YOURSITE/blog/manage_calculateCategory ) which will print out nothing, but will cause the counts to be re-estimated. You only need to do this once after installing the patch.

*** 1339,1347 ****
              cat.set_count(0)
          for id in self.entry_list:
              ent = self.getEntry(id)
!             if ent.category and self.categories.has_key(ent.category[0]):
!                 cat = self.categories[ent.category[0]]
!                 cat.set_count(cat.get_count()+1)
  
          #reset datemap
          self.datemap = IOBTree()
--- 1341,1353 ----
              cat.set_count(0)
          for id in self.entry_list:
              ent = self.getEntry(id)
!             #if ent.category and self.categories.has_key(ent.category[0]):
!             # GD. Fix to use sub-categories too.
!             if ent.category:
!                 for ecat in ent.category:
!                    if self.categories.has_key(ecat):
!                       cat = self.categories[ecat]
!                       cat.set_count(cat.get_count()+1)
  
          #reset datemap
          self.datemap = IOBTree()

Posted by dudek at February 22 19:26 | Leave a comment | permalink link to this entry |
Comments
There are no comments.
Post your own response


(Some kind of name is required, will be visible)

Required, whatever you enter will be visible to other users.


(Optional, used for "mailto" link)

Your email address is not required, but if you insert it it will be displayed so people can contact you.


(Optional, will appear as a link)

Leave an URL if you want to provide a relevant link that relates to your comment or identifies you.



The title for your comment.



Your comment goes here. All relevant comments are welcome, except for those that simply promote an irrelevant product or else are used to fraudulently inflate the link count to an irrelevant web page.


(you must preview before posting)




Science Blogs - Blog Top Sites Science Blogs - Blog Catalog Blog Directory Science Blogs - Blog Top Sites Science Blogs - Blog Catalog Blog Directory