changeset 479:9a32bd1332af

MonthCalendar can take an additional template page argument for creating new day pages imported from: moin--main--1.5--patch-483
author Thomas Waldmann <tw@waldmann-edv.de>
date Sat, 18 Mar 2006 17:10:20 +0000
parents ce2e934557f4
children c611a218ae9b
files ChangeLog MoinMoin/macro/MonthCalendar.py docs/CHANGES
diffstat 3 files changed, 52 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Mar 18 15:20:09 2006 +0000
+++ b/ChangeLog	Sat Mar 18 17:10:20 2006 +0000
@@ -2,6 +2,20 @@
 # arch-tag: automatic-ChangeLog--arch@arch.thinkmo.de--2003-archives/moin--main--1.5
 #
 
+2006-03-18 18:10:20 GMT	Thomas Waldmann <tw@waldmann-edv.de>	patch-483
+
+    Summary:
+      MonthCalendar can take an additional template page argument for creating new day pages
+    Revision:
+      moin--main--1.5--patch-483
+
+    MonthCalendar can take an additional template page argument for creating new day pages
+    
+
+    modified files:
+     ChangeLog MoinMoin/macro/MonthCalendar.py docs/CHANGES
+
+
 2006-03-18 16:20:09 GMT	Thomas Waldmann <tw@waldmann-edv.de>	patch-482
 
     Summary:
--- a/MoinMoin/macro/MonthCalendar.py	Sat Mar 18 15:20:09 2006 +0000
+++ b/MoinMoin/macro/MonthCalendar.py	Sat Mar 18 17:10:20 2006 +0000
@@ -85,7 +85,8 @@
         * fixed CSS for IE users
         * fix javascript for IE4
         * do a correct calculation of "today" using user's timezone
-
+    * 2.2:
+        * added template argument for specifying an edit template for new pages
 
     Usage:
         [[MonthCalendar(BasePage,year,month,monthoffset,monthoffset2,height6)]]
@@ -138,6 +139,10 @@
 This creates calendars of the format Yearly/MM-DD 
 By leaving out the year, you can set birthdays, and anniversaries in this 
 calendar and not have to re-enter each year.
+
+This creates a calendar which uses MonthCalendarTemplate for directly editing
+nonexisting day pages:
+[[MonthCalendar(,,,,,,MonthCalendarTemplate)]]
 """
 
 Dependencies = ['namespace','time']
@@ -173,7 +178,7 @@
         year = year + 1
     return year, month
 
-def parseargs(args, defpagename, defyear, defmonth, defoffset, defoffset2, defheight6, defanniversary):
+def parseargs(args, defpagename, defyear, defmonth, defoffset, defoffset2, defheight6, defanniversary, deftemplate):
     strpagename = args.group('basepage')
     if strpagename:
         parmpagename = wikiutil.unquoteWikiname(strpagename)
@@ -218,7 +223,12 @@
     else:
         parmanniversary = defanniversary
 
-    return parmpagename, parmyear, parmmonth, parmoffset, parmoffset2, parmheight6, parmanniversary
+    strtemplate = args.group('template')
+    if strtemplate:
+        parmtemplate = wikiutil.unquoteWikiname(strtemplate)
+    else:
+        parmtemplate = deftemplate
+    return parmpagename, parmyear, parmmonth, parmoffset, parmoffset2, parmheight6, parmanniversary, parmtemplate
         
 # FIXME:                          vvvvvv is there a better way for matching a pagename ?
 _arg_basepage = r'\s*(?P<basepage>[^, ]+)?\s*'
@@ -228,9 +238,10 @@
 _arg_offset2 = r',\s*(?P<offset2>[+-]?\d+)?\s*'
 _arg_height6 = r',\s*(?P<height6>[+-]?\d+)?\s*'
 _arg_anniversary =  r',\s*(?P<anniversary>[+-]?\d+)?\s*'
-_args_re_pattern = r'^(%s)?(%s)?(%s)?(%s)?(%s)?(%s)?(%s)?$' % \
+_arg_template = r',\s*(?P<template>[^, ]+)?\s*' # XXX see basepage comment
+_args_re_pattern = r'^(%s)?(%s)?(%s)?(%s)?(%s)?(%s)?(%s)?(%s)?$' % \
                      (_arg_basepage,_arg_year,_arg_month, \
-                      _arg_offset,_arg_offset2,_arg_height6,_arg_anniversary)
+                      _arg_offset,_arg_offset2,_arg_height6,_arg_anniversary,_arg_template)
 
 
 def execute(macro, text):
@@ -254,22 +265,22 @@
             return ('<p><strong class="error">%s</strong></p>' % _('Invalid MonthCalendar calparms "%s"!')) % (text2,)
         else:
             has_calparms = 1 # yes!
-            cparmpagename, cparmyear, cparmmonth, cparmoffset, cparmoffset2, cparmheight6, cparmanniversary = \
-                parseargs(args2, thispage, currentyear, currentmonth, 0, 0, 0, 0)
+            cparmpagename, cparmyear, cparmmonth, cparmoffset, cparmoffset2, cparmheight6, cparmanniversary, cparmtemplate = \
+                parseargs(args2, thispage, currentyear, currentmonth, 0, 0, 0, 0, '')
     else:
         has_calparms = 0
 
     if text is None: # macro call without parameters
-        parmpagename, parmyear, parmmonth, parmoffset, parmoffset2, parmheight6, anniversary = \
-            [thispage], currentyear, currentmonth, 0, 0, 0, 0
+        parmpagename, parmyear, parmmonth, parmoffset, parmoffset2, parmheight6, anniversary, parmtemplate = \
+            [thispage], currentyear, currentmonth, 0, 0, 0, 0, ''
     else:
         # parse and check arguments
         args = args_re.match(text)
         if not args:
             return ('<p><strong class="error">%s</strong></p>' % _('Invalid MonthCalendar arguments "%s"!')) % (text,)
         else:
-            parmpagename, parmyear, parmmonth, parmoffset, parmoffset2, parmheight6, anniversary = \
-                parseargs(args, thispage, currentyear, currentmonth, 0, 0, 0, 0)
+            parmpagename, parmyear, parmmonth, parmoffset, parmoffset2, parmheight6, anniversary, parmtemplate = \
+                parseargs(args, thispage, currentyear, currentmonth, 0, 0, 0, 0, '')
 
     # does url have calendar params and is THIS the right calendar to modify (we can have multiple
     # calendars on the same page)?
@@ -279,6 +290,7 @@
     if has_calparms and cparmpagename == parmpagename:
         year,month = yearmonthplusoffset(parmyear, parmmonth, parmoffset + cparmoffset2)
         parmoffset2 = cparmoffset2
+        parmtemplate = cparmtemplate
     else:
         year,month = yearmonthplusoffset(parmyear, parmmonth, parmoffset)
 
@@ -298,11 +310,12 @@
     colorstep = 85
     p = Page(request, thispage)
     qpagenames = '*'.join(map(wikiutil.quoteWikinameURL, parmpagename))
-    querystr = "calparms=%%s,%d,%d,%d,%%d" % (parmyear, parmmonth, parmoffset)
-    prevlink  = p.url(request, querystr % (qpagenames, parmoffset2 - 1), 0)
-    nextlink  = p.url(request, querystr % (qpagenames, parmoffset2 + 1), 0)
-    prevylink = p.url(request, querystr % (qpagenames, parmoffset2 - 12), 0)
-    nextylink = p.url(request, querystr % (qpagenames, parmoffset2 + 12), 0)
+    qtemplate = wikiutil.quoteWikinameURL(parmtemplate)
+    querystr = "calparms=%s,%d,%d,%d,%%d,%s" % (qpagenames, parmyear, parmmonth, parmoffset, qtemplate)
+    prevlink  = p.url(request, querystr % (parmoffset2 - 1), 0)
+    nextlink  = p.url(request, querystr % (parmoffset2 + 1), 0)
+    prevylink = p.url(request, querystr % (parmoffset2 - 12), 0)
+    nextylink = p.url(request, querystr % (parmoffset2 + 12), 0)
     prevmonth = formatter.url(1, prevlink, 'cal-link') + '&lt;' + formatter.url(0)
     nextmonth = formatter.url(1, nextlink, 'cal-link') + '&gt;' + formatter.url(0)
     prevyear  = formatter.url(1, prevylink, 'cal-link') + '&lt;&lt;' + formatter.url(0)
@@ -378,6 +391,7 @@
                 daypage = Page(request, link)
                 if daypage.exists():
                     csslink = "cal-usedday"
+                    query = {}
                     r, g, b, u = (255, 0, 0, 1)
                     daycontent = daypage.get_raw_body()
                     header1_re = re.compile(r'^\s*=\s(.*)\s=$', re.MULTILINE) # re.UNICODE
@@ -394,6 +408,10 @@
                     onmouse = '''onMouseOver="tip('%s')" onMouseOut="untip()"''' % tipname
                 else:
                     csslink = "cal-emptyday"
+                    if parmtemplate:
+                        query = {'action': 'edit', 'template': parmtemplate}
+                    else:
+                        query = {}
                     r, g, b, u = (255, 255, 255, 0)
                     if wkday in wkend:
                         csslink = "cal-weekend"
@@ -409,7 +427,7 @@
                             r, g, b = (r, g+colorstep, b)
                 r, g, b = cliprgb(r, g, b)
                 style = 'background-color:#%02x%02x%02x' % (r, g, b)
-                fmtlink = formatter.url(1, daypage.url(request), csslink, attrs=onmouse) + str(day) + formatter.url(0)
+                fmtlink = formatter.url(1, daypage.url(request, query), csslink, attrs=onmouse) + str(day) + formatter.url(0)
                 if day == currentday and month == currentmonth and year == currentyear:
                     cssday = "cal-today"
                     fmtlink = "<b>%s</b>" % fmtlink # for browser with CSS probs
--- a/docs/CHANGES	Sat Mar 18 15:20:09 2006 +0000
+++ b/docs/CHANGES	Sat Mar 18 17:10:20 2006 +0000
@@ -67,6 +67,9 @@
     * moin_cookie auth method now logs out a user by deleting the cookie and
       setting user_obj.valid = 0. This makes it possible to still get the
       user's name in subsequent auth method calls within the same request.
+    * MonthCalendar now takes an additional argument for specifying a template
+      to use to directly invoke the page editor when clicking on non-existing
+      day pages.
 
   Bugfixes:
     * cookie_lifetime didn't work comfortable for low values. The cookie was