Attachment 'Blog.py_adapt_to_1.3.5.diff'

Download

   1 diff -u -r1.2 Blog.py
   2 --- Blog.py	12 Jun 2006 17:05:23 -0000	1.2
   3 +++ Blog.py	13 Jun 2006 16:20:46 -0000
   4 @@ -48,11 +48,15 @@
   5      $Id$
   6  """
   7  
   8 -from MoinMoin import config, wikiutil
   9 +from MoinMoin import config
  10  from MoinMoin.Page import Page
  11 -import re, time, string
  12 +import re, time
  13  import MoinMoin.macro.Include
  14  
  15 +# compile regular expressions once at start time
  16 +re_entries=re.compile(r'(?P<entries>\d+)')
  17 +re_date=re.compile(r'(?P<year>\d\d\d\d)-(?P<month>\d?\d)-(?P<day>\d?\d)')
  18 +
  19  def getStyle():
  20      style = """
  21  <style type="text/css">
  22 @@ -111,7 +115,7 @@
  23  }
  24  
  25  function updateBlog() {
  26 -    window.location.href = global.page+"?date="+global.date+"&entries="+global.entries+"&showAll="+global.showAll
  27 +    window.location.href = "/"+global.page+"?date="+global.date+"&entries="+global.entries+"&showAll="+global.showAll
  28  }
  29  
  30  function setToday() {
  31 @@ -378,23 +382,21 @@
  32  #def execute(macro, text, args_re=re.compile(_args_re_pattern)):
  33  
  34  def execute(macro, text):
  35 -    thisPage = macro.formatter.page.url(macro.request)
  36 -
  37 +    thisPage = macro.formatter.page.page_name
  38  
  39      #get incoming macro args, else set to []
  40      if text:
  41 -        args = string.split(text, ",")
  42 +        args = text.split(",")
  43      else:
  44          args = []
  45  
  46      #remove all leading and trailing spaces
  47 -    for i in range(len(args)):
  48 -        args[i] = string.strip(args[i])
  49 +    args = map(lambda line: line.strip(), args)
  50  
  51      #set date
  52      if macro.form.has_key('date'):
  53          date = macro.form['date'][0]
  54 -    elif (len(args) >= 0) and (not args[0] == ""):
  55 +    elif (len(args) > 0) and (args[0]):
  56          date = args[0]
  57      else:
  58          date = ""
  59 @@ -403,7 +405,7 @@
  60      #set showAll
  61      if macro.form.has_key('showAll'):
  62          showAll = macro.form['showAll'][0]
  63 -    elif (len(args) >= 1) and (not args[1] == ""):
  64 +    elif (len(args) > 1) and (args[1]):
  65          showAll = args[1]
  66      else:
  67          showAll = "0"
  68 @@ -411,29 +413,28 @@
  69      #set entries
  70      if macro.form.has_key('entries'):
  71          entries = macro.form['entries'][0]
  72 -    elif (len(args) >= 2) and (not args[2] == ""):
  73 +    elif (len(args) > 2) and (args[2]):
  74          entries = args[2]
  75      else:
  76 -        entries = -1
  77 +        entries = None
  78  
  79      #set max entries
  80 -    if (len(args) >= 3) and (not args[3] == ""):
  81 +    if (len(args) > 3) and (args[3]):
  82          maxEntries = int(args[3])
  83          if maxEntries < 0:
  84              maxEntries = 20
  85      else:
  86          maxEntries = 20
  87  
  88 -    if (len(args) >= 4) and (not args[4] == ""):
  89 +    if (len(args) > 4) and (args[4]):
  90          startDay = args[4]
  91      else:
  92          startDay = "Mo";
  93  
  94  
  95      #set the number of visible entries
  96 -    if not entries == -1:
  97 -        args_re=re.compile(r'(?P<entries>\d+)')
  98 -        args = args_re.match(entries)
  99 +    if entries:
 100 +        args = re_entries.match(entries)
 101          if not args:
 102              return ('<p><strong class="error">%s</strong></p>' %('Invalid entries "%s"!')) % (macro.form['beforeDate'][0])
 103          entries = int(macro.form['entries'][0])
 104 @@ -446,8 +447,7 @@
 105  
 106      #get the date
 107      if not date == "":
 108 -        args_re=re.compile(r'(?P<year>\d\d\d\d)-(?P<month>\d?\d)-(?P<day>\d?\d)')
 109 -        args = args_re.match(date)
 110 +        args = re_date.match(date)
 111          if not args:
 112              return ('<p><strong class="error">%s</strong></p>' %('Invalid date "%s"!')) % (macro.form['date'][0])
 113          year  = int(args.group('year'))
 114 @@ -465,7 +465,7 @@
 115      if (showAll == '1'):
 116          ret += getShowAll(macro, thisPage, year, month, day, entries, maxEntries)
 117      else:
 118 -        ret += getShowEntered(macro, macro.formatter.page.page_name, year, month, day, entries, maxEntries)
 119 +        ret += getShowEntered(macro, thisPage, year, month, day, entries, maxEntries)
 120  
 121      return ret
 122  
 123 @@ -482,7 +482,7 @@
 124      ret += "</select>"
 125  
 126      for i in range(entries):
 127 -        includeParams = '%s/BlogEntry-%d-%02d-%02d, "%d-%02d-%02d", 1' % (macro.formatter.page.page_name, year, month, day, year, month, day)
 128 +        includeParams = '%s/BlogEntry-%d-%02d-%02d, "%d-%02d-%02d", 1' % (thisPage, year, month, day, year, month, day)
 129          ret += MoinMoin.macro.Include.execute(macro, includeParams)
 130          #date = strftime("%Y-%m-$d", (year,month,day, 0, 0, 0, 0, 0, 0)
 131          day = day - 1

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-06-13 16:24:51, 4.2 KB) [[attachment:Blog.py_adapt_to_1.3.5.diff]]
  • [get | view] (2006-06-15 17:55:01, 22.3 KB) [[attachment:Blog_MoinMoin1.5.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.