Index: EventCalendar.py
===================================================================
--- EventCalendar.py	(revision 244)
+++ EventCalendar.py	(working copy)
@@ -200,7 +200,7 @@
     page_action = ''
     form_vals = {}
     events = None
-    labels = None
+    labels = {}
 
 
 class Params:
@@ -239,7 +239,7 @@
     
     # INITIALIZATION ----------------------------------------
     setglobalvalues(macro)
-    getparams(args)
+    getparams(request, args)
     
     # allowed actions
     allowed_action = ['monthly', 'list', 'simple', 'upcoming', 'daily', 'weekly']
@@ -316,7 +316,7 @@
 
 
 
-def getparams(args):
+def getparams(request, args):
     # process arguments
     
     params = {}
@@ -693,7 +693,7 @@
     if Params.showpagelist:
         source_pages = []
     
-        events, cal_events, labels = loadEvents()
+        events, cal_events = loadEvents()
     
         for eid in events.keys():
             event = events[eid]
@@ -810,7 +810,7 @@
     html_list_header = cal_listhead()
     
     # read all the events
-    events, cal_events, labels = loadEvents()
+    events, cal_events = loadEvents()
     
     # sort events
     sorted_eventids = events.keys()
@@ -883,7 +883,7 @@
     dateto = u'%04d%02d%02d' % (next_range.year, next_range.month, next_range.day)
     
     # read all the events (no cache)
-    events, cal_events, labels = loadEvents(datefrom, dateto, 1)
+    events, cal_events = loadEvents(datefrom, dateto, 1)
     
     nowtime = formattimeobject(Globs.now)
     
@@ -1118,11 +1118,10 @@
     debug('Loading event information.')
     
     events = {}
-    labels = {}
     cal_events = {}
     raw_events = {}
     
-    raw_events, labels = loadEventsFromWikiPages()
+    raw_events = loadEventsFromWikiPages()
     
     # handling cal_events
     if datefrom or dateto:
@@ -1418,26 +1417,21 @@
         events = raw_events
         
         # store event list into global variables in order to sort them
-        Globs.events = events
+        Globs.events = raw_events
     
-    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 %d labels are loaded finally.' % len(Globs.labels))
     
-    return events, cal_events, labels
+    return events, cal_events
 
 
 
 def loadEventsFromWikiPages():
     
     events = {}
-    labels = {}
     cached_event_loaded = 0
     dirty = 0
     
-    eventrecord_list = []
-    labelrecord_list = []
     eventpages = []
     stored_errmsg = ''
     
@@ -1563,8 +1557,16 @@
                     cache_labelrecords.update(pickle.dumps(labelrecords, PICKLE_PROTOCOL))
                     cache_errmsg.update(pickle.dumps(Globs.errormsg, PICKLE_PROTOCOL))
     
-            eventrecord_list.append(eventrecords)
-            labelrecord_list.append(labelrecords)
+            for evtrecord in eventrecords:
+                e_id = evtrecord['id']
+                events[e_id] = evtrecord
+
+            for label in labelrecords:
+                c_id = label['name']
+                if not Globs.labels.has_key(c_id):
+                    Globs.labels[c_id] = label
+                elif label['refer'] !=  Globs.labels[c_id]['refer'] :
+                    stored_errmsg += u'<li>%s\n' % geterrormsg('redefined_label', label['refer'], label['name'])
             
             stored_errmsg += Globs.errormsg
             Globs.errormsg = ''
@@ -1577,7 +1579,7 @@
         
         try:
             events = pickle.loads(cache_events.content())
-            labels = pickle.loads(cache_labels.content())
+            Globs.labels = pickle.loads(cache_labels.content())
             stored_errmsg = pickle.loads(cache_errmsglist.content())
             
             cached_event_loaded = 1
@@ -1586,7 +1588,7 @@
             
         except (pickle.UnpicklingError, IOError, EOFError, ValueError):
             events = {}
-            labels = {}
+            Globs.labels = {}
             stored_errmsg = ''
             
             debug('Picke error at fetching cached events')
@@ -1599,22 +1601,9 @@
         for page_name in eventpages:
             debug(debug_records[page_name])
 
-        for eventrecords in eventrecord_list:
-            for evtrecord in eventrecords:
-                e_id = evtrecord['id']
-                events[e_id] = evtrecord
-        
-        for labelrecords in labelrecord_list:
-            for label in labelrecords:
-                c_id = label['name']
-                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'])
-        
         # after generating updated events, update the cache
         cache_events.update(pickle.dumps(events, PICKLE_PROTOCOL))
-        cache_labels.update(pickle.dumps(labels, PICKLE_PROTOCOL))
+        cache_labels.update(pickle.dumps(Globs.labels, PICKLE_PROTOCOL))
         cache_errmsglist.update(pickle.dumps(stored_errmsg, PICKLE_PROTOCOL))
         
         debug('Event information is newly built: total %d events' % len(events))
@@ -1623,7 +1612,7 @@
     
     # end of updating events block    
     
-    return events, labels
+    return events
     
 
 
@@ -2037,7 +2026,9 @@
     ##################### retrieve startdate
     match = pattern_startdate.search(detail)
     
-    if match:
+    startdate = ''
+    starttime = ''
+    if match :
     
         if match.group('startdate'):
             passed = 1
@@ -2082,11 +2073,6 @@
             
             if passed:
                 startdate = '%d/%02d/%02d' % (int(startyear), int(startmonth), int(startday))
-            else:
-                startdate = ''
-                
-        else:
-            startdate = ''
             
         if match.group('starttime'):
             passed = 1
@@ -2137,11 +2123,7 @@
             
             if passed:
                 starttime = '%02d:%02d' % (int(starthour), int(startmin))
-            else:
-                starttime = ''
         
-        else:
-            starttime = ''
             
         if not startdate:
             raise EventcalError('invalid_start')
@@ -2152,6 +2134,8 @@
     ##################### retrieve enddate
     match = pattern_enddate.search(detail)
     
+    enddate = ''
+    endtime = ''
     if match:
     
         if match.group('enddate'):
@@ -2197,11 +2181,6 @@
             
             if passed:
                 enddate = '%d/%02d/%02d' % (int(endyear), int(endmonth), int(endday))
-            else:
-                enddate = ''
-                
-        else:
-            enddate = ''
         
         if match.group('endtime'):
             passed = 1
@@ -2252,57 +2231,44 @@
                 
             if passed:
                 endtime = '%02d:%02d' % (int(endhour), int(endmin))
-            else:
-                endtime = ''
-                
-        else:
-            endtime = ''
 
         if not (enddate or endtime):
             raise EventcalError('invalid_end')
 
-    else:
-        enddate = ''
-        endtime = '' 
+    ##################### retrieve label
+    match = pattern_label.search(detail)
+    
+    label = ''
+    if match:
+        if match.group('name'):
+            label = match.group('name')
+        else:
+            errormsgcode('invalid_label')
 
-
     ##################### retrieve bgcolor
     match = pattern_bgcolor.search(detail)
     
+    bgcolor = ''
     if match:
         if match.group('bgcolor'):
             bgcolor = match.group('bgcolor')
         else:
             errormsgcode('invalid_bgcolor')
-            bgcolor = ''
-            
-    else:
-        bgcolor = ''
+    elif label != '' and Globs.labels:
+        labels = Globs.labels
 
-    ##################### retrieve label
-    match = pattern_label.search(detail)
-    
-    if match:
-        if match.group('name'):
-            label = match.group('name')
-        else:
-            errormsgcode('invalid_label')
-            label = ''
-            
-    else:
-        label = ''
+        if labels.has_key(label):
+            bgcolor = labels[label]['bgcolor']
 
     ##################### retrieve description
     match = pattern_description.search(detail)
     
+    description = ''
     if match:
         if match.group('description'):
             description = match.group('description')
         else:
             errormsgcode('empty_description')
-            description = ''
-    else:
-        description = ''
         
     ##################### retrieve recurrence
     match = pattern_recur.search(detail)
@@ -2534,7 +2500,7 @@
     dateto = u'%04d%02d06' % (next_month.year, next_month.month)
     
     # read all the events
-    events, cal_events, labels = loadEvents(datefrom, dateto)
+    events, cal_events = loadEvents(datefrom, dateto)
     
     #debug(u'  events: %s' % events)
     #debug(u'  cal_events: %s' % cal_events)
@@ -2792,7 +2758,7 @@
     dateto = u'%04d%02d06' % (next_month.year, next_month.month)
     
     # read all the events
-    events, cal_events, labels = loadEvents(datefrom, dateto)
+    events, cal_events = loadEvents(datefrom, dateto)
     
     #debug(u'  events: %s' % events)
     #debug(u'  cal_events: %s' % cal_events)
@@ -3023,7 +2989,7 @@
     dateto = u'%04d%02d06' % (next_month.year, next_month.month)
     
     # read all the events
-    events, cal_events, labels = loadEvents(datefrom, dateto)
+    events, cal_events = loadEvents(datefrom, dateto)
     
     #debug(u'  events: %s' % events)
     #debug(u'  cal_events: %s' % cal_events)
@@ -3361,7 +3327,7 @@
     dateto = u'%04d%02d06' % (next_month.year, next_month.month)
     
     # read all the events
-    events, cal_events, labels = loadEvents(datefrom, dateto)
+    events, cal_events = loadEvents(datefrom, dateto)
     
     maketip_js = []
     
@@ -3736,14 +3702,6 @@
     description = event['description']
     bgcolor = event['bgcolor']
     
-    if not bgcolor:
-        if Globs.labels:
-            labels = Globs.labels
-            # for backward compatibility
-            if event.has_key('label'):
-                if labels.has_key(event['label']):
-                    bgcolor = labels[event['label']]['bgcolor']
-    
     year, month, day = getdatefield(cur_date)
     
     if bgcolor:
@@ -3789,13 +3747,6 @@
     description = event['description']
     bgcolor = event['bgcolor']
     
-    if not bgcolor:
-        labels = Globs.labels
-        # for backward compatibility
-        if event.has_key('label'):
-            if labels.has_key(event['label']):
-                bgcolor = labels[event['label']]['bgcolor']
-    
     year, month, day = getdatefield(cur_date)
     
     if bgcolor:
@@ -3840,13 +3791,6 @@
     bgcolor = event['bgcolor']
     time_len = event['time_len']
     
-    if not bgcolor:
-        labels = Globs.labels
-        # for backward compatibility
-        if event.has_key('label'):
-            if labels.has_key(event['label']):
-                bgcolor = labels[event['label']]['bgcolor']
-    
     if bgcolor:
         bgcolor = 'background-color: %s;' % bgcolor
     else:
@@ -3880,13 +3824,6 @@
     bgcolor = event['bgcolor']
     time_len = event['time_len']
     
-    if not bgcolor:
-        labels = Globs.labels
-        # for backward compatibility
-        if event.has_key('label'):
-            if labels.has_key(event['label']):
-                bgcolor = labels[event['label']]['bgcolor']
-    
     if bgcolor:
         bgcolor = 'background-color: %s;' % bgcolor
     else:
@@ -3933,13 +3870,6 @@
     
     year, month, day = getdatefield(cur_date)
     
-    if not bgcolor:
-        labels = Globs.labels
-        # for backward compatibility
-        if event.has_key('label'):
-            if labels.has_key(event['label']):
-                bgcolor = labels[event['label']]['bgcolor']
-    
     if bgcolor:
         bgcolor = 'background-color: %s;' % bgcolor
     else:
