Commit 883e3479 authored by Benjamin Graillot's avatar Benjamin Graillot

Fix de la macro EventCalendar pour les pages avec des accents

parent b6ec1bc5
# -*- mode: python; coding: utf-8 -*-
"""
2018-03-12
* Version modifiée avec des str.format
* Certains strings changés en strings utf-8 pour éviter des problèmes d'encodage
EventCalendar.py Version 0.99a July 22, 2009
* Base 0.99 version
......@@ -322,10 +327,10 @@ def execute(macro, args):
html.append( show_page_list() )
if Params.showerror and Globs.errormsg:
html.append(u'<p><i><font size="2" color="#aa0000"><ol>%s</ol></font></i>' % Globs.errormsg)
html.append(u'<p><i><font size="2" color="#aa0000"><ol>{0}</ol></font></i>'.format(Globs.errormsg))
if Params.debug and Globs.debugmsg:
html.append(u'<p><b>Debug messages:</b><font color="#000099"><ol>%s</ol></font>' % Globs.debugmsg)
html.append(u'<p><b>Debug messages:</b><font color="#000099"><ol>{0}</ol></font>'.format(Globs.debugmsg))
return formatter.rawHTML(u''.join(html))
......@@ -361,26 +366,26 @@ def getparams(args):
# default: 600px
Params.monthlywidth = params.get('monthlywidth', '600')
if Params.monthlywidth:
Params.monthlywidth = ' width="%s" ' % Params.monthlywidth
Params.monthlywidth = ' width="{0}" '.format(Params.monthlywidth)
# calendar width in pixel or percent (weekly)
# default: 600px
Params.weeklywidth = params.get('weeklywidth', '600')
if Params.weeklywidth:
Params.weeklywidth = ' width="%s" ' % Params.weeklywidth
Params.weeklywidth = ' width="{0}" '.format(Params.weeklywidth)
# calendar width in pixel or percent (daily)
# default: 600px
Params.dailywidth = params.get('dailywidth', '600')
if Params.monthlywidth:
Params.dailywidth = ' width="%s" ' % Params.dailywidth
Params.dailywidth = ' width="{0}" '.format(Params.dailywidth)
# calendar width in pixel or percent (simply)
# default: 150px
Params.simplewidth = params.get('simplewidth', '150')
if Params.simplewidth:
# Params.simplewidth = Params.simplewidth.replace('%', '%%')
Params.simplewidth = ' width="%s" ' % Params.simplewidth
Params.simplewidth = ' width="{0}" '.format(Params.simplewidth)
# calendar view: monthly, list, simple
# default: 'monthly'
......@@ -453,7 +458,7 @@ def setglobalvalues(macro):
Globs.pagename = formatter.page.page_name
Globs.request = request
Globs.formatter = formatter
Globs.pageurl = '%s/%s' % (request.getScriptname(), wikiutil.quoteWikinameURL(formatter.page.page_name))
Globs.pageurl = '{0}/{1}'.format(request.getScriptname(), wikiutil.quoteWikinameURL(formatter.page.page_name))
# This fixes the subpages bug. subname is now used instead of pagename when creating certain urls
Globs.subname = Globs.pagename.split('/')[-1]
......@@ -497,7 +502,7 @@ def showReferPageParsed(event, targettext='title', showdesc=0):
endtime = event['endtime']
hid = event['hid']
refer_url = '%s/%s' % (request.getScriptname(), wikiutil.quoteWikinameURL(refer))
refer_url = '{0}/{1}'.format(request.getScriptname(), wikiutil.quoteWikinameURL(refer))
if not Params.changeview:
refer_url = ''
......@@ -505,16 +510,16 @@ def showReferPageParsed(event, targettext='title', showdesc=0):
if showdesc:
if (startdate == enddate) and (starttime and endtime):
timedescription = '(%s:%s ~ %s:%s)' % (starttime[:2], starttime[2:], endtime[:2], endtime[2:])
timedescription = '({0}:{1} ~ {2}:{3})'.format(starttime[:2], starttime[2:], endtime[:2], endtime[2:])
if description:
timedescription = '%s ' % timedescription
timedescription = '{0} '.format(timedescription)
else:
timedescription = ''
targetlink = '<a href="%s#%s" title="%s%s">%s</a>' % ( refer_url, hid, timedescription, wikiutil.escape(description), wikiutil.escape(targettext) )
targetlink = u'<a href="{0}#{1}" title="{2}{3}">{4}</a>'.format( refer_url, hid, timedescription, wikiutil.escape(description), wikiutil.escape(targettext) )
else:
targetlink = '<a href="%s#%s">%s</a>' % ( refer_url, hid, wikiutil.escape(targettext))
targetlink = u'<a href="{0}#{1}">{2}</a>'.format( refer_url, hid, wikiutil.escape(targettext))
return targetlink
......@@ -535,14 +540,14 @@ def showReferPageParsedForLabel(thelabel, targettext='name', showdesc=1):
label_bgcolor = labels[thelabel]['bgcolor']
if not refer:
return '<i>%s</i>' % thelabel
return '<i>{0}</i>'.format(thelabel)
refer_url = '%s/%s' % (request.getScriptname(), wikiutil.quoteWikinameURL(refer))
refer_url = '{0}/{1}'.format(request.getScriptname(), wikiutil.quoteWikinameURL(refer))
if showdesc:
targetlink = '<a href="%s" title="%s">%s</a>' % ( refer_url, label_bgcolor, wikiutil.escape(targettext) )
targetlink = '<a href="{0}" title="{1}">{2}</a>'.format( refer_url, label_bgcolor, wikiutil.escape(targettext) )
else:
targetlink = '<a href="%s">%s</a>' % ( refer_url, wikiutil.escape(targettext))
targetlink = '<a href="{0}">{1}</a>'.format( refer_url, wikiutil.escape(targettext))
return targetlink
......@@ -558,7 +563,7 @@ def getheadingid(request, referpage, title):
request._eventcal_headings.setdefault(pntt, 0)
request._eventcal_headings[pntt] += 1
if request._eventcal_headings[pntt] > 1:
hid += '-%d'%(request._eventcal_headings[pntt],)
hid += '-{0}'.format(request._eventcal_headings[pntt],)
return hid
......@@ -572,16 +577,16 @@ def getquerystring(req_fields):
# action should be poped out
for field in req_fields:
if tmp_form_vals.has_key(field):
m_query.append(u'%s=%s' % (field, tmp_form_vals[field]) )
m_query.append(u'{0}={1}'.format(field, tmp_form_vals[field]) )
if 'prevcalaction' in req_fields:
if not tmp_form_vals.has_key('prevcalaction'):
m_query.append(u'%s=%s' % ('prevcalaction', tmp_form_vals['calaction']) )
m_query.append(u'{0}={1}'.format('prevcalaction', tmp_form_vals['calaction']) )
m_query = u'&'.join(m_query)
if m_query:
m_query = '&%s' % m_query
m_query = '&{0}'.format(m_query)
return m_query
......@@ -609,32 +614,32 @@ def showmenubar():
# Go Today
year, month, day = gettodaydate()
mnu_curmonthcal = u'<a href="%s?calaction=%s&amp;caldate=%d%02d%02d%s" title="Aujourd\'hui">[Aujourd\'hui]</a>' % (page_url, cal_action, year, month, day, getquerystring(['numcal']))
mnu_curmonthcal = u'<a href="{0}?calaction={1}&amp;caldate={2}{3:02d}{4:02d}{5}" title="Aujourd\'hui">[Aujourd\'hui]</a>'.format(page_url, cal_action, year, month, day, getquerystring(['numcal']))
# List View
mnu_listview = u'<a href="%s?calaction=list%s" title="Liste de tous les évènements">[Liste]</a>' % (page_url, getquerystring(['caldate', 'numcal']))
mnu_listview = u'<a href="{0}?calaction=list{1}" title="Liste de tous les évènements">[Liste]</a>'.format(page_url, getquerystring(['caldate', 'numcal']))
# Monthly View
mnu_monthview = u'<a href="%s?calaction=monthly%s" title="Vue du mois">[Mois]</a>' % (page_url, getquerystring(['caldate', 'numcal']) )
mnu_monthview = u'<a href="{0}?calaction=monthly{1}" title="Vue du mois">[Mois]</a>'.format(page_url, getquerystring(['caldate', 'numcal']) )
# Simple Calendar View
mnu_simpleview = u'<a href="%s?calaction=simple%s" title="Simple calendrier">[Simple]</a>' % (page_url, getquerystring(['caldate', 'numcal']) )
mnu_simpleview = u'<a href="{0}?calaction=simple{1}" title="Simple calendrier">[Simple]</a>'.format(page_url, getquerystring(['caldate', 'numcal']) )
# Upcoming Event List
mnu_upcomingview = u'<a href="%s?calaction=upcoming%s" title="Évènements à venir">[À venir]</a>' % (page_url, getquerystring(['caldate', 'numcal']) )
mnu_upcomingview = u'<a href="{0}?calaction=upcoming{1}" title="Évènements à venir">[À venir]</a>'.format(page_url, getquerystring(['caldate', 'numcal']) )
# Daily View
mnu_dayview = u'<a href="%s?calaction=daily%s" title="Vue du jour">[Jour]</a>' % (page_url, getquerystring(['caldate', 'numcal']) )
mnu_dayview = u'<a href="{0}?calaction=daily{1}" title="Vue du jour">[Jour]</a>'.format(page_url, getquerystring(['caldate', 'numcal']) )
# Weekly View
mnu_weekview = u'<a href="%s?calaction=weekly%s" title="Vue de la semaine" >[Semaine]</a>' % (page_url, getquerystring(['caldate', 'numcal']) )
mnu_weekview = u'<a href="{0}?calaction=weekly{1}" title="Vue de la semaine" >[Semaine]</a>'.format(page_url, getquerystring(['caldate', 'numcal']) )
html = [
u'\r\n',
u'<table class="eventcalendar_menubar" %s>',
u'<table class="eventcalendar_menubar" {0}>',
u' <tr>',
u' <td class="eventcalendar_menubar" align="left">%s</td>',
u' <td class="eventcalendar_menubar" align="right">%s</td>',
u' <td class="eventcalendar_menubar" align="left">{1}</td>',
u' <td class="eventcalendar_menubar" align="right">{2}</td>',
u' </tr>',
u'</table>',
]
......@@ -689,7 +694,7 @@ def showmenubar():
right_menu_selected = u'\r\n'.join(right_menu_selected)
html = u'\r\n'.join(html)
html = html % (menuwidth, left_menu_selected, right_menu_selected)
html = html.format(menuwidth, left_menu_selected, right_menu_selected)
return html
......@@ -706,8 +711,8 @@ def show_page_list():
for eid in events.keys():
event = events[eid]
refer = event['refer']
refer_url = '%s/%s' % (request.getScriptname(), wikiutil.quoteWikinameURL(refer))
targetlink = '<a href="%s">%s</a>' % ( refer_url, wikiutil.escape(refer))
refer_url = '{0}/{1}'.format(request.getScriptname(), wikiutil.quoteWikinameURL(refer))
targetlink = '<a href="{0}">{1}</a>'.format( refer_url, wikiutil.escape(refer))
source_pages.append( targetlink )
from sets import Set
......@@ -833,8 +838,8 @@ def showeventlist():
html_list_table = [
u'\r\n<div id="eventlist">',
u'<table class="eventlist">',
u'%s' % html_list_header,
u'%s' % html_event_rows,
u'{0}'.format(html_list_header),
u'{0}'.format(html_event_rows),
u'</table>',
u'</div>',
]
......@@ -847,24 +852,24 @@ def listshow_event(event):
if event['recur_freq']:
if event['recur_freq'] == -1:
recur_desc = 'last %s' % event['recur_type']
recur_desc = 'last {0}'.format(event['recur_type'])
else:
recur_desc = 'every %d %s' % (event['recur_freq'], event['recur_type'])
recur_desc = 'every {0} {1}'.format(event['recur_freq'], event['recur_type'])
if event['recur_until']:
recur_desc = '%s until %s' % (recur_desc, formatcfgdatetime(event['recur_until']))
recur_desc = '{0} until {1}'.format(recur_desc, formatcfgdatetime(event['recur_until']))
else:
recur_desc = ''
html = [
u' <tr>',
u' <td class="list_entry">%s</td>' % converttext(event['title']),
u' <td class="list_entry">%s</td>' % formatcfgdatetime(event['startdate'], event['starttime']),
u' <td class="list_entry">%s</td>' % formatcfgdatetime(event['enddate'], event['endtime']),
u' <td class="list_entry">%s</td>' % recur_desc,
u' <td class="list_entry">%s</td>' % showReferPageParsedForLabel(event['label']),
u' <td class="list_entry">%s</td>' % converttext(event['description']),
u' <td class="list_entry">%s</td>' % showReferPageParsed(event, 'refer'),
u' <td class="list_entry">{0}</td>'.format(converttext(event['title'])),
u' <td class="list_entry">{0}</td>'.format(formatcfgdatetime(event['startdate'], event['starttime'])),
u' <td class="list_entry">{0}</td>'.format(formatcfgdatetime(event['enddate'], event['endtime'])),
u' <td class="list_entry">{0}</td>'.format(recur_desc),
u' <td class="list_entry">{0}</td>'.format(showReferPageParsedForLabel(event['label'])),
u' <td class="list_entry">{0}</td>'.format(converttext(event['description'])),
u' <td class="list_entry">{0}</td>'.format(showReferPageParsed(event, 'refer')),
u' </tr>',
]
......@@ -887,8 +892,8 @@ def showupcomingeventlist():
next_range = cur_date + day_delta
# set ranges of events
datefrom = u'%04d%02d%02d' % (year, month, day)
dateto = u'%04d%02d%02d' % (next_range.year, next_range.month, next_range.day)
datefrom = u'{0:04d}{1:02d}{2:02d}'.format(year, month, day)
dateto = u'{0:04d}{1:02d}{2:02d}'.format(next_range.year, next_range.month, next_range.day)
# read all the events (no cache)
events, cal_events, labels = loadEvents(datefrom, dateto, 1)
......@@ -896,9 +901,9 @@ def showupcomingeventlist():
nowtime = formattimeobject(Globs.now)
datefrom = formatcfgdatetime(cur_date, nowtime)
#u'%04d-%02d-%02d %s:%s' % (year, month, day, nowtime[:2], nowtime[2:])
#u'{0:04d}-{1:02d}-{2:02d} {3}:{4}'.format(year, month, day, nowtime[:2], nowtime[2:])
dateto = formatcfgdatetime(formatdateobject(next_range))
#u'%04d-%02d-%02d' % (next_range.year, next_range.month, next_range.day)
#u'{0:04d}-{1:02d}-{2:02d}'.format(next_range.year, next_range.month, next_range.day)
# sort events
sorted_eventids = events.keys()
......@@ -914,9 +919,9 @@ def showupcomingeventlist():
html_list_table = [
u'\r\n<div id="eventlist">',
u'<table class="eventlist">',
u'<tr><td colspan="7" class="list_entry" style="border-width: 0px;"><b>Évènement à venir: %s ~ %s</b><p><br><p></td></tr>' % (datefrom, dateto),
u'%s' % html_list_header,
u'%s' % html_event_rows,
u'<tr><td colspan="7" class="list_entry" style="border-width: 0px;"><b>Évènement à venir: {0} ~ {1}</b><p><br><p></td></tr>'.format(datefrom, dateto),
u'{0}'.format(html_list_header),
u'{0}'.format(html_event_rows),
u'</table>',
u'</div>',
]
......@@ -1142,8 +1147,8 @@ def loadEvents(datefrom='', dateto='', nocache=0):
# cache configurations
arena = Page(request, Globs.pagename)
eventkey = 'events'
filteredeventkey = 'events_%s-%s' % (datefrom, dateto)
caleventkey = 'calevents_%s-%s' % (datefrom, dateto)
filteredeventkey = 'events_{0}-{1}'.format(datefrom, dateto)
caleventkey = 'calevents_{0}-{1}'.format(datefrom, dateto)
cache_events = caching.CacheEntry(request, arena, eventkey, scope='item')
cache_filteredevents = caching.CacheEntry(request, arena, filteredeventkey, scope='item')
......@@ -1158,7 +1163,7 @@ def loadEvents(datefrom='', dateto='', nocache=0):
try:
events = pickle.loads(cache_filteredevents.content())
cal_events = pickle.loads(cache_calevents.content())
debug('Cached event (filtered) information is used: total %d events' % len(events))
debug('Cached event (filtered) information is used: total {0} events'.format(len(events)))
dirty = 0
except (pickle.UnpicklingError, IOError, EOFError, ValueError):
debug('Picke error at fetching cached events (filtered)')
......@@ -1227,7 +1232,7 @@ def loadEvents(datefrom='', dateto='', nocache=0):
break
clone_num += 1
clone_id = 'c%d' % clone_num
clone_id = 'c{0}'.format(clone_num)
events[clone_id] = cur_event.copy()
events[clone_id]['id'] = clone_id
......@@ -1270,7 +1275,7 @@ def loadEvents(datefrom='', dateto='', nocache=0):
break
clone_num += 1
clone_id = 'c%d' % clone_num
clone_id = 'c{0}'.format(clone_num)
events[clone_id] = cur_event.copy()
events[clone_id]['id'] = clone_id
......@@ -1325,7 +1330,7 @@ def loadEvents(datefrom='', dateto='', nocache=0):
break
clone_num += 1
clone_id = 'c%d' % clone_num
clone_id = 'c{0}'.format(clone_num)
events[clone_id] = cur_event.copy()
events[clone_id]['id'] = clone_id
......@@ -1364,7 +1369,7 @@ def loadEvents(datefrom='', dateto='', nocache=0):
break
clone_num += 1
clone_id = 'c%d' % clone_num
clone_id = 'c{0}'.format(clone_num)
events[clone_id] = cur_event.copy()
events[clone_id]['id'] = clone_id
......@@ -1397,7 +1402,7 @@ def loadEvents(datefrom='', dateto='', nocache=0):
new_enddate = formatdateobject(recurred_enddate)
clone_num += 1
clone_id = 'c%d' % clone_num
clone_id = 'c{0}'.format(clone_num)
events[clone_id] = cur_event.copy()
events[clone_id]['id'] = clone_id
......@@ -1434,8 +1439,8 @@ def loadEvents(datefrom='', dateto='', nocache=0):
Globs.labels = labels
debug(u'Total %d events are loaded finally.' % len(events))
debug(u'Total %d labels are loaded finally.' % len(labels))
debug(u'Total {0} events are loaded finally.'.format(len(events)))
debug(u'Total {0} labels are loaded finally.'.format(len(labels)))
return events, cal_events, labels
......@@ -1484,7 +1489,7 @@ def loadEventsFromWikiPages():
today = datetime.datetime.fromtimestamp(time.time())
datediff = today - cp_date
timedelta_days = datediff.days
debug('Time from page list cache built = %s' % datediff)
debug('Time from page list cache built = {0}'.format(datediff))
if Globs.page_action == 'refresh' or cache_pages.needsUpdate(arena._text_filename()) or timedelta_days >= 1:
......@@ -1497,10 +1502,10 @@ def loadEventsFromWikiPages():
formatter.pagelink(1, pagename=page.page_name)
eventpages.append(page.page_name)
cache_pages.update('\n'.join(eventpages).encode('utf-8'))
debug('New page list is built: %d pages' % len(eventpages))
debug('New page list is built: {0} pages'.format(len(eventpages)))
else:
eventpages = cache_pages.content().decode('utf-8').split('\n')
debug('Cached page list is used: %d pages' % len(eventpages))
debug('Cached page list is used: {0} pages'.format(len(eventpages)))
if not Globs.page_action == 'refresh':
# check the cache validity
......@@ -1539,11 +1544,11 @@ def loadEventsFromWikiPages():
page_content = p.get_raw_body()
eventrecords, labelrecords = getEventRecordFromPage(page_content, e_ref)
debug_records[e_ref] = '%d events are fetched from %s' % (len(eventrecords), e_ref)
debug_records[e_ref] = u'{0} events are fetched from {1}'.format(len(eventrecords), e_ref)
# XXXXX
#debug('events: %s' % eventrecords)
#debug('labels: %s' % labelrecords)
#debug('events: {0}'.format(eventrecords))
#debug('labels: {0}'.format(labelrecords))
cache_eventrecords.update(pickle.dumps(eventrecords, PICKLE_PROTOCOL))
cache_labelrecords.update(pickle.dumps(labelrecords, PICKLE_PROTOCOL))
......@@ -1558,13 +1563,13 @@ def loadEventsFromWikiPages():
labelrecords = pickle.loads(cache_labelrecords.content())
Globs.errormsg = pickle.loads(cache_errmsg.content())
debug_records[e_ref] = '%d cached eventrecords are used from %s' % (len(eventrecords), e_ref)
debug_records[e_ref] = u'{0} cached eventrecords are used from {1}'.format(len(eventrecords), e_ref)
except (pickle.UnpicklingError, IOError, EOFError, ValueError):
dirty = 1
page_content = p.get_raw_body()
eventrecords, labelrecords = getEventRecordFromPage(page_content, e_ref)
debug_records[e_ref] = '%d eventrecords are fetched from %s due to pickle error' % (len(eventrecords), e_ref)
debug_records[e_ref] = u'{0} eventrecords are fetched from {1} due to pickle error'.format(len(eventrecords), e_ref)
cache_eventrecords.update(pickle.dumps(eventrecords, PICKLE_PROTOCOL))
cache_labelrecords.update(pickle.dumps(labelrecords, PICKLE_PROTOCOL))
......@@ -1589,7 +1594,7 @@ def loadEventsFromWikiPages():
cached_event_loaded = 1
debug('Cached event information is used: total %d events' % len(events))
debug('Cached event information is used: total {0} events'.format(len(events)))
except (pickle.UnpicklingError, IOError, EOFError, ValueError):
events = {}
......@@ -1617,14 +1622,14 @@ def loadEventsFromWikiPages():
if not labels.has_key(c_id):
labels[c_id] = label
else:
stored_errmsg += u'<li>%s\n' % geterrormsg('redefined_label', label['refer'], label['name'])
stored_errmsg += u'<li>{0}\n'.format(geterrormsg('redefined_label', label['refer'], label['name']))
# after generating updated events, update the cache
cache_events.update(pickle.dumps(events, PICKLE_PROTOCOL))
cache_labels.update(pickle.dumps(labels, PICKLE_PROTOCOL))
cache_errmsglist.update(pickle.dumps(stored_errmsg, PICKLE_PROTOCOL))
debug('Event information is newly built: total %d events' % len(events))
debug('Event information is newly built: total {0} events'.format(len(events)))
Globs.errormsg = stored_errmsg
......@@ -1751,7 +1756,7 @@ def getEventRecordFromPage(pagecontent, referpage):
if not eventdetail:
continue
#debug('Examininng "%s" event from %s ..' % (eventtitle, referpage))
#debug('Examininng "{0}" event from {1} ..'.format(eventtitle, referpage))
try:
e_start_date, e_start_time, e_end_date, e_end_time, e_bgcolor, e_label, e_description, e_recur_freq, e_recur_type, e_recur_until = geteventfield(eventdetail)
......@@ -1774,7 +1779,7 @@ def getEventRecordFromPage(pagecontent, referpage):
e_description = page_description
e_num += 1
e_id = 'e_%s_%d' % (referpage, e_num)
e_id = u'e_{0}_{1}'.format(referpage, e_num)
eventitem['id'] = e_id
eventitem['title'] = eventtitle
......@@ -1802,13 +1807,13 @@ def getEventRecordFromPage(pagecontent, referpage):
eventitem['time_len'] = 0
except EventcalError, errmsgcode:
debug('Failed to add "%s" event from %s ..' % (eventtitle, referpage))
debug('Failed to add "{0}" event from {1} ..'.format(eventtitle, referpage))
errormsg( geterrormsg(errmsgcode.value, referpage, eventtitle, e_headid) )
continue
eventrecords.append(eventitem)
#debug('Added "%s" event from %s ..' % (eventtitle, referpage))
#debug('Added "{0}" event from {1} ..'.format(eventtitle, referpage))
return eventrecords, labelrecords
......@@ -2051,7 +2056,7 @@ def geteventfield(detail):
# yyyy/mm/dd: 2006/05/10; 06/05/10,
if match.group('startdate1'):
if len(match.group('startyear1')) == 2:
startyear = '20%s' % match.group('startyear1')
startyear = '20{0}'.format(match.group('startyear1'))
else:
startyear = match.group('startyear1')
......@@ -2061,7 +2066,7 @@ def geteventfield(detail):
# M dd, yyyy: May 10, 2006; Jan 10th, 2006; Jan 10, 06
elif match.group('startdate2'):
if len(match.group('startyear2')) == 2:
startyear = '20%s' % match.group('startyear2')
startyear = '20{0}'.format(match.group('startyear2'))
else:
startyear = match.group('startyear2')
......@@ -2074,7 +2079,7 @@ def geteventfield(detail):
# yyyymmdd: 20060510, 060510
elif match.group('startdate3'):
if len(match.group('startyear3')) == 2:
startyear = '20%s' % match.group('startyear3')
startyear = '20{0}'.format(match.group('startyear3'))
else:
startyear = match.group('startyear3')
......@@ -2088,7 +2093,7 @@ def geteventfield(detail):
passed = 0
if passed:
startdate = '%d/%02d/%02d' % (int(startyear), int(startmonth), int(startday))
startdate = '{0}/{1:02d}/{2:02d}'.format(int(startyear), int(startmonth), int(startday))
else:
startdate = ''
......@@ -2143,7 +2148,7 @@ def geteventfield(detail):
passed = 0
if passed:
starttime = '%02d:%02d' % (int(starthour), int(startmin))
starttime = '{0:02d}:{1:02d}'.format(int(starthour), int(startmin))
else:
starttime = ''
......@@ -2166,7 +2171,7 @@ def geteventfield(detail):
# yyyy/mm/dd: 2006/05/10; 06/05/10,
if match.group('enddate1'):
if len(match.group('endyear1')) == 2:
endyear = '20%s' % match.group('endyear1')
endyear = '20{0}'.format(match.group('endyear1'))
else:
endyear = match.group('endyear1')
......@@ -2176,7 +2181,7 @@ def geteventfield(detail):
# M dd, yyyy: May 10, 2006; Jan 10th, 2006; Jan 10, 06
elif match.group('enddate2'):
if len(match.group('endyear2')) == 2:
endyear = '20%s' % match.group('endyear2')
endyear = '20{0}'.format(match.group('endyear2'))
else:
endyear = match.group('endyear2')
......@@ -2189,7 +2194,7 @@ def geteventfield(detail):
# yyyymmdd: 20060510, 060510
elif match.group('enddate3'):
if len(match.group('endyear3')) == 2:
endyear = '20%s' % match.group('endyear3')
endyear = '20{0}'.format(match.group('endyear3'))
else:
endyear = match.group('endyear3')
......@@ -2203,7 +2208,7 @@ def geteventfield(detail):
passed = 0
if passed:
enddate = '%d/%02d/%02d' % (int(endyear), int(endmonth), int(endday))
enddate = '{0}/{1:02d}/{2:02d}'.format(int(endyear), int(endmonth), int(endday))
else:
enddate = ''
......@@ -2258,7 +2263,7 @@ def geteventfield(detail):
passed = 0
if passed:
endtime = '%02d:%02d' % (int(endhour), int(endmin))
endtime = '{0:02d}:{1:02d}'.format(int(endhour), int(endmin))
else:
endtime = ''
......@@ -2338,7 +2343,7 @@ def geteventfield(detail):
# yyyy/mm/dd: 2006/05/10; 06/05/10,
if match.group('enddate1'):
if len(match.group('endyear1')) == 2:
endyear = '20%s' % match.group('endyear1')
endyear = '20{0}'.format(match.group('endyear1'))
else:
endyear = match.group('endyear1')
......@@ -2348,7 +2353,7 @@ def geteventfield(detail):
# M dd, yyyy: May 10, 2006; Jan 10th, 2006; Jan 10, 06
elif match.group('enddate2'):
if len(match.group('endyear2')) == 2:
endyear = '20%s' % match.group('endyear2')
endyear = '20{0}'.format(match.group('endyear2'))
else:
endyear = match.group('endyear2')
......@@ -2361,7 +2366,7 @@ def geteventfield(detail):
# yyyymmdd: 20060510, 060510
elif match.group('enddate3'):
if len(match.group('endyear3')) == 2:
endyear = '20%s' % match.group('endyear3')
endyear = '20{0}'.format(match.group('endyear3'))
else:
endyear = match.group('endyear3')
......@@ -2371,7 +2376,7 @@ def geteventfield(detail):
else:
raise EventcalError('invalid_recur_until')
recur_until = '%d/%02d/%02d' % (int(endyear), int(endmonth), int(endday))
recur_until = '{0}/{1:02d}/{2:02d}'.format(int(endyear), int(endmonth), int(endday))
else:
raise EventcalError('invalid_recur_until')
......@@ -2433,8 +2438,8 @@ def geteventfield(detail):
raise EventcalError('endtime_precede')
# format time
starttime = u'%02d%02d' %(shour, smin)
endtime = u'%02d%02d' %(ehour, emin)
starttime = u'{0:02d}{1:02d}'.format(shour, smin)
endtime = u'{0:02d}{1:02d}'.format(ehour, emin)
# check recurrent data
event_len = diffday(startdate, enddate)
......@@ -2517,7 +2522,7 @@ def showeventcalendar(year, month):
for wkday in r7:
wday = _(wkdays[wkday])
html_header_weekdays.append( calhead_weekday(wday, 'head_weekday') )
html_header_weekdays = ' <tr>\r\n%s\r\n</tr>\r\n' % u'\r\n'.join(html_header_weekdays)
html_header_weekdays = ' <tr>\r\n{0}\r\n</tr>\r\n'.format(u'\r\n'.join(html_header_weekdays))
# pending events for next row
next_pending = []
......@@ -2538,14 +2543,14 @@ def showeventcalendar(year, month):
html_week_rows = []
# set ranges of events
datefrom = u'%04d%02d21' % (prev_month.year, prev_month.month)
dateto = u'%04d%02d06' % (next_month.year, next_month.month)
datefrom = u'{0:04d}{1:02d}21'.format(prev_month.year, prev_month.month)
dateto = u'{0:04d}{1:02d}06'.format(next_month.year, next_month.month)
# read all the events
events, cal_events, labels = loadEvents(datefrom, dateto)
#debug(u' events: %s' % events)
#debug(u' cal_events: %s' % cal_events)
#debug(u' events: {0}'.format(events))
#debug(u' cal_events: {0}'.format(cal_events))
for week in monthcal:
......@@ -2567,7 +2572,7 @@ def showeventcalendar(year, month):
else:
html_headday_cols.append( calhead_day(year, month, day, wkday) )
html_headday_row = ' <tr>\r\n%s\r\n</tr>\r\n' % u'\r\n'.join(html_headday_cols)
html_headday_row = ' <tr>\r\n{0}\r\n</tr>\r\n'.format(u'\r\n'.join(html_headday_cols))
html_week_rows.append(html_headday_row)
# dummy rows
......@@ -2581,7 +2586,7 @@ def showeventcalendar(year, month):
html_headdummy_cols.append( calshow_blankbox('head_dummy') )
html_headdummy_cols = u'\r\n'.join(html_headdummy_cols)
html_week_rows.append(' <tr>\r\n%s </tr>\r\n' % html_headdummy_cols)
html_week_rows.append(' <tr>\r\n{0} </tr>\r\n'.format(html_headdummy_cols))
# pending events for next row
pending = next_pending
......@@ -2721,7 +2726,7 @@ def showeventcalendar(year, month):
# ignore the previous entry
break
else:
html_events_rows.append(' <tr>\r\n%s </tr>\r\n' % u'\r\n'.join(html_events_cols))
html_events_rows.append(u' <tr>\r\n{0} </tr>\r\n'.format(u'\r\n'.join(html_events_cols)))
# show dummy blank slots for week height
left_blank_rows = 2 - len(html_events_rows)
......@@ -2737,7 +2742,7 @@ def showeventcalendar(year, month):
else:
html_events_cols.append( calshow_blankbox('cal_noevent') )
html_events_rows.append(' <tr>\r\n%s </tr>\r\n' % u'\r\n'.join(html_events_cols))
html_events_rows.append(u' <tr>\r\n{0} </tr>\r\n'.format(u'\r\n'.join(html_events_cols)))
# close the week slots
......@@ -2749,7 +2754,7 @@ def showeventcalendar(year, month):
else:
html_events_cols.append( calshow_blankbox('cal_last_noevent') )
html_events_rows.append(' <tr>\r\n%s </tr>\r\n' % u'\r\n'.join(html_events_cols))
html_events_rows.append(u' <tr>\r\n{0} </tr>\r\n'.format(u'\r\n'.join(html_events_cols)))
html_events_rows = u'\r\n'.join(html_events_rows)
html_week_rows.append(html_events_rows)
......@@ -2758,10 +2763,10 @@ def showeventcalendar(year, month):
html_cal_table = [
u'\r\n<div id="eventcalendar">',
u'<table class="eventcalendar" %s>' % Params.monthlywidth,
u'%s' % html_header_curyearmonth,
u'%s' % html_header_weekdays,
u'%s' % html_calendar_rows,
u'<table class="eventcalendar" {0}>'.format(Params.monthlywidth),
u'{0}'.format(html_header_curyearmonth),
u'{0}'.format(html_header_weekdays),
u'{0}'.format(html_calendar_rows),
u'</table>',
u'</div>',
]
......@@ -2796,14 +2801,14 @@ def showdailyeventcalendar(year, month, day):
next_month = cur_month_end + day_delta
# set ranges of events
datefrom = u'%04d%02d21' % (prev_month.year, prev_month.month)
dateto = u'%04d%02d06' % (next_month.year, next_month.month)
datefrom = u'{0:04d}{1:02d}21'.format(prev_month.year, prev_month.month)
dateto = u'{0:04d}{1:02d}06'.format(next_month.year, next_month.month)
# read all the events
events, cal_events, labels = loadEvents(datefrom, dateto)