Feature no. 1 is pretty simple: I don't like my blog entries list to be limited by no. of posts in x days (top_days), but I prefer to display x no. of entries. Adding a COREBlog setting to store the maximum no. of entries to display on the front page would be very convenient. This involves adding a few lines to COREBlog/utility.py, COREBlog/dtml/manage_editSettingForm.dtml, and COREBlog/COREBlog.py.
Feature no. 2 is a bit more complicated, and is specific to ZPT skins In the ZPT_CSS_THIN, request variables used for entries lists that need to be passed as ints are defined in the templates like this:
tal:define="oneMonth python: getattr(request, 'month', 0);"
What I would like to see is a more "natural" way to pass req variables to COREBlog's Protected methods, like this:
tal:define="req_month request/month | nothing">
It may sound stupid, but the TALsyntax comes out cleaner, and you can use the defined var in other TAL statements, eg:
tal:condition="req_month"
since if no month req variable exists, the TAL variable gets the TAL "nothing" value
Moreover, I noticed that in COREBLOG.py there are a few places where method args are explicitly converted to int, eg:
def month_entry_items(self,count=1,year=0,month=0):
#Return list of Entry on the month.
year = int(year)
month = int(month)so what I'm proposing is that instead of explictly converting req vars to ints in different places (TAL templates, COREBlog methods), the convertion happens only in COREBlog, using a small method (eg COREBlog.req_to_int). This has the added benefit of trapping in a single place ValueError exceptions possibly raised by the conversions (eg. index_html?month=).
The patch is attahced to this email, if it's totally stupid don't hesitate to shoot.
Ludo
ps - sorry if this message is a duplicate, the first one was posted from the wrong address
diff -u -r -x '*pyc' COREBlog/COREBlog.py COREBlog_modified/COREBlog.py
--- COREBlog/COREBlog.py 2004-05-15 18:12:28.000000000 +0200
+++ COREBlog_modified/COREBlog.py 2004-05-19 11:32:51.000000000 +0200
@@ -275,6 +275,7 @@
self._updateProperty("blog_url","")
self._updateProperty("module_item_count",10)
self._updateProperty("top_days",4)
+ self._updateProperty("top_entries",12)
self._updateProperty("category_length",20)
self._updateProperty("skin_name","default")
self._updateProperty("require_name",1)
@@ -606,8 +607,24 @@
#Listing
+ def req_to_int(self, v, default = None):
+ """
+ provide support for ZPT tal:define="req_var request/var | nothing"
+ """
+ if isinstance(v, int):
+ return v
+ if default is not None and (v is None or v == ''):
+ return default
+ try:
+ return int(v)
+ except ValueError:
+ return default
+
security.declareProtected(View, 'entry_items')
def entry_items(self,start=0,count=-1,consider_moderation = 1):
+ start = self.req_to_int(start, 0)
+ count = self.req_to_int(count, -1)
+ consider_moderation = self.req_to_int(consider_moderation, 1)
#Return list of Entry.
l = []
list_c = len(self.entry_list)
@@ -622,10 +639,12 @@
if not consider_moderation or obj.moderated:
l.append(obj)
return l
-
-
+
security.declareProtected(View, 'rev_entry_items')
def rev_entry_items(self,start=0,count=-1,consider_moderation = 1):
+ start = self.req_to_int(start, 0)
+ count = self.req_to_int(count, -1)
+ consider_moderation = self.req_to_int(consider_moderation, 1)
#Return list of Entry(reversed indexing).
l = []
if count == -1:
@@ -667,7 +686,13 @@
security.declareProtected(View, 'rev_day_entry_items')
def rev_day_entry_items(self,count=1,start_year=0,start_month=0,start_day=0):
- #Return list of Entry,based on date(reversed indexing).
+ """
+ Return list of Entry, based on date(reversed indexing).
+ """
+ count = self.req_to_int(count, 1)
+ start_year = self.req_to_int(start_year, 0)
+ start_month = self.req_to_int(start_month, 0)
+ start_day = self.req_to_int(start_day, 0)
if start_year == 0 or start_month == 0 or start_day == 0:
#Base date is today
t = localtime(time())
@@ -734,9 +759,10 @@
security.declareProtected(View, 'month_entry_items')
def month_entry_items(self,count=1,year=0,month=0):
- #Return list of Entry on the month.
- year = int(year)
- month = int(month)
+ """Return list of Entry on the month."""
+ count = self.req_to_int(count, 1)
+ year = self.req_to_int(year, 0)
+ month = self.req_to_int(month, 0)
if year == 0 or month == 0:
#Base date is today
t = localtime(time())
@@ -780,6 +806,9 @@
security.declareProtected(View, 'month_archive_items')
def month_archive_items(self,count=1,start_year=0,start_month=0):
""" Return list of month archive. """
+ count = self.req_to_int(count, 1)
+ start_year = self.req_to_int(start_year, 0)
+ start_month = self.req_to_int(start_month, 0)
if start_year == 0 or start_month == 0 or start_day == 0:
#Base date is today
t = localtime(time())
@@ -809,6 +838,7 @@
security.declareProtected(View, 'getMonthName')
def getMonthName(self,month):
+ month = self.req_to_int(month, 0)
m_list = ["January","February","March","April", \
"May","June","July","August", \
"September","October","November","December"]
@@ -816,7 +846,6 @@
tmp_mlist = split(self.getProperty("month_names"),",")
if len(tmp_mlist) == 12:
m_list = tmp_mlist
- month = int(month)
if month < 1 or month > 12:
return ""
return m_list[month-1]
@@ -824,7 +853,11 @@
security.declareProtected(View, 'rev_category_entry_items')
def rev_category_entry_items(self,category_id,start=0,count=-1,consider_moderation = 1):
- #Return list of Entry.
+ """Return list of Entry."""
+ category_id = self.req_to_int(category_id)
+ start = self.req_to_int(start, 0)
+ count = self.req_to_int(count, -1)
+ consider_moderation = self.req_to_int(count, 1)
l = []
try:
int_cat = int(category_id)
@@ -847,7 +880,7 @@
security.declareProtected(View, 'count_entry')
def count_entry(self):
- #Return count of Entry.
+ """Return count of Entry."""
return len(self.entries)
@@ -994,7 +1027,7 @@
#security.declarePrivate('getNewCommentID')
def getNewCommentID(self):
- #return new id for comments
+ """return new id for comments"""
new_id = getNewID(self.comment_count,self.comments)
self.comment_count = new_id
return new_id
@@ -1002,7 +1035,9 @@
security.declareProtected(View, 'rev_comment_items')
def rev_comment_items(self,start=0,count=-1):
- #Return list of Comment(reversed indexing).
+ """Return list of Comment(reversed indexing)."""
+ start = self.req_to_int(start, 0)
+ count = self.req_to_int(count, -1)
l = []
if count == -1:
count = len(self.comment_list)
@@ -1022,7 +1057,7 @@
security.declareProtected(View, 'count_blog_comment')
def count_blog_comment(self):
- #return count of Comment.
+ """return count of Comment."""
return len(self.comment_list)
#
@@ -1063,7 +1098,9 @@
security.declareProtected(View, 'rev_trackback_items')
def rev_trackback_items(self,start=0,count=-1):
- #Return list of Trackback(reversed indexing).
+ """Return list of Trackback(reversed indexing)."""
+ start = self.req_to_int(start, 0)
+ count = self.req_to_int(count, -1)
l = []
if count == -1:
count = len(self.trackback_list)
@@ -1093,7 +1130,9 @@
security.declareProtected(View, 'get_calendar')
def get_calendar(self,year=0,month=0,firstweekday=SUNDAY):
- """Reutrn list of days for the month"""
+ """Return list of days for the month"""
+ year = self.req_to_int(year, 0)
+ month = self.req_to_int(month, 0)
if year == 0 or month == 0:
#return calendar of 'now'
t = localtime(time())
@@ -1180,10 +1219,10 @@
security.declareProtected(View, 'getCategory')
def getCategory(self,id):
- id_i = int(id)
- if not self.categories.has_key(id_i):
- raise KeyError,id_i
- return (self.categories[id_i],)
+ id = self.req_to_int(id)
+ if not self.categories.has_key(id):
+ raise KeyError,id
+ return (self.categories[id],)
security.declarePrivate('getNewCategoryID')
@@ -1904,7 +1943,7 @@
security.declareProtected(View, 'getTrackbackPings')
def getTrackbackPings(self,postid,REQUEST=None):
""" Return entry's trackback """
- int_id = int(postid)
+ int_id = self.req_to_int(postid)
#get entry
ent = self.getEntry(int_id)
c = convert_charcode
diff -u -r -x '*pyc' COREBlog/dtml/manage_editSettingForm.dtml COREBlog_modified/dtml/manage_editSettingForm.dtml
--- COREBlog/dtml/manage_editSettingForm.dtml 2004-05-15 18:12:28.000000000 +0200
+++ COREBlog_modified/dtml/manage_editSettingForm.dtml 2004-05-19 10:19:41.000000000 +0200
@@ -105,6 +105,17 @@
</td>
</tr>
+ <tr>
+ <td align="left" valign="top" class="list-header">
+ <div class="form-label">
+ Entries count<br> for Top Page
+ </div>
+ </td>
+ <td align="left" valign="top">
+ <input type="text" name="top_entries:int" size="80" value="<dtml-var top_entries html_quote missing="15">" />
+ </td>
+ </tr>
+
<tr>
<td align="left" valign="top" class="list-header">
<div class="form-label">
@@ -477,4 +488,4 @@
</table>
-<dtml-var manage_page_footer>
\ No newline at end of file
+<dtml-var manage_page_footer>
diff -u -r -x '*pyc' COREBlog/utility.py COREBlog_modified/utility.py
--- COREBlog/utility.py 2004-05-15 18:12:29.000000000 +0200
+++ COREBlog_modified/utility.py 2004-05-19 10:20:23.000000000 +0200
@@ -254,6 +254,7 @@
#Optional
#length for modules
{'id':'module_item_count', 'type':'int','mode':'w'},
+ {'id':'top_entries', 'type':'int','mode':'w'},
{'id':'top_days', 'type':'int','mode':'w'},
{'id':'category_length', 'type':'int','mode':'w'},
