imip-agent

Change of imipweb/event.py

492:ada21f67eb6c
imipweb/event.py
     1.1 --- a/imipweb/event.py	Sun Apr 05 18:55:24 2015 +0200
     1.2 +++ b/imipweb/event.py	Sun Apr 05 21:26:40 2015 +0200
     1.3 @@ -217,7 +217,7 @@
     1.4  
     1.5              dtend_enabled = str(index) in all_dtend_enabled
     1.6              dttimes_enabled = str(index) in all_dttimes_enabled
     1.7 -            period, errors = self.handle_period_controls(start_values, end_values, dtend_enabled, dttimes_enabled)
     1.8 +            period, errors = self.handle_period_controls(start_values, end_values, dtend_enabled, dttimes_enabled, index)
     1.9  
    1.10              if errors:
    1.11                  return None, errors
    1.12 @@ -226,19 +226,21 @@
    1.13  
    1.14          return periods, None
    1.15  
    1.16 -    def handle_period_controls(self, start_values, end_values, dtend_enabled, dttimes_enabled):
    1.17 +    def handle_period_controls(self, start_values, end_values, dtend_enabled, dttimes_enabled, index=None):
    1.18  
    1.19          """
    1.20          Handle datetime controls for a particular period, described by the given
    1.21          'start_values' and 'end_values', with 'dtend_enabled' and
    1.22          'dttimes_enabled' affecting the usage of the provided values.
    1.23 +
    1.24 +        If 'index' is specified, incorporate it into any error indicator.
    1.25          """
    1.26  
    1.27          t = self.handle_date_control_values(start_values, dttimes_enabled)
    1.28          if t:
    1.29              dtstart, dtstart_attr = t
    1.30          else:
    1.31 -            return None, ["dtstart"]
    1.32 +            return None, [index is not None and ("dtstart", index) or "dtstart"]
    1.33  
    1.34          # Handle specified end datetimes.
    1.35  
    1.36 @@ -252,7 +254,7 @@
    1.37                  if not isinstance(dtend, datetime):
    1.38                      dtend += timedelta(1)
    1.39              else:
    1.40 -                return None, ["dtend"]
    1.41 +                return None, [index is not None and ("dtend", index) or "dtend"]
    1.42  
    1.43          # Otherwise, treat the end date as the start date. Datetimes are
    1.44          # handled by making the event occupy the rest of the day.
    1.45 @@ -265,7 +267,10 @@
    1.46                  dtend = get_start_of_day(dtend, attr["TZID"])
    1.47  
    1.48          if dtstart > dtend:
    1.49 -            return None, ["dtstart", "dtend"]
    1.50 +            return None, [
    1.51 +                index is not None and ("dtstart", index) or "dtstart",
    1.52 +                index is not None and ("dtend", index) or "dtend"
    1.53 +                ]
    1.54  
    1.55          return ((dtstart, dtstart_attr), (dtend, dtend_attr)), None
    1.56  
    1.57 @@ -529,11 +534,12 @@
    1.58                  page.input(name="ignore", type="submit", value="Do nothing for now")
    1.59                  page.p.close()
    1.60  
    1.61 -    def show_object_on_page(self, uid, obj, error=None):
    1.62 +    def show_object_on_page(self, uid, obj, errors=None):
    1.63  
    1.64          """
    1.65          Show the calendar object with the given 'uid' and representation 'obj'
    1.66 -        on the current page. If 'error' is given, show a suitable message.
    1.67 +        on the current page. If 'errors' is given, show a suitable message for
    1.68 +        the different errors provided.
    1.69          """
    1.70  
    1.71          page = self.page
    1.72 @@ -588,7 +594,7 @@
    1.73                  continue
    1.74  
    1.75              page.tr()
    1.76 -            page.th(label, class_="objectheading %s%s" % (field, error and field in error and " error" or ""), rowspan=rowspan)
    1.77 +            page.th(label, class_="objectheading %s%s" % (field, errors and field in errors and " error" or ""), rowspan=rowspan)
    1.78  
    1.79              # Handle datetimes specially.
    1.80  
    1.81 @@ -679,7 +685,7 @@
    1.82          page.tbody.close()
    1.83          page.table.close()
    1.84  
    1.85 -        self.show_recurrences(obj)
    1.86 +        self.show_recurrences(obj, errors)
    1.87          self.show_conflicting_events(uid, obj)
    1.88          self.show_request_controls(obj)
    1.89  
    1.90 @@ -740,9 +746,13 @@
    1.91  
    1.92          page.td.close()
    1.93  
    1.94 -    def show_recurrences(self, obj):
    1.95 +    def show_recurrences(self, obj, errors=None):
    1.96  
    1.97 -        "Show recurrences for the object having the given representation 'obj'."
    1.98 +        """
    1.99 +        Show recurrences for the object having the given representation 'obj'.
   1.100 +        If 'errors' is given, show a suitable message for the different errors
   1.101 +        provided.
   1.102 +        """
   1.103  
   1.104          page = self.page
   1.105  
   1.106 @@ -790,18 +800,17 @@
   1.107  
   1.108                  self.show_object_datetime_controls(p.start, p.end, index)
   1.109  
   1.110 -                # NOTE: Need to customise the TH classes according to errors and
   1.111 -                # NOTE: index information.
   1.112 -
   1.113                  page.table(cellspacing=5, cellpadding=5, class_="recurrence")
   1.114                  page.caption("Occurrence")
   1.115                  page.tbody()
   1.116                  page.tr()
   1.117 -                page.th("Start", class_="objectheading start")
   1.118 +                error = errors and ("dtstart", index) in errors and " error" or ""
   1.119 +                page.th("Start", class_="objectheading start%s" % error)
   1.120                  self.show_recurrence_controls(obj, index, p.start, p.end, p.origin, recurrenceid, recurrenceids, True)
   1.121                  page.tr.close()
   1.122                  page.tr()
   1.123 -                page.th("End", class_="objectheading end")
   1.124 +                error = errors and ("dtend", index) in errors and " error" or ""
   1.125 +                page.th("End", class_="objectheading end%s" % error)
   1.126                  self.show_recurrence_controls(obj, index, p.start, p.end, p.origin, recurrenceid, recurrenceids, False)
   1.127                  page.tr.close()
   1.128                  page.tbody.close()
   1.129 @@ -1095,13 +1104,13 @@
   1.130          if not obj:
   1.131              return False
   1.132  
   1.133 -        error = self.handle_request(uid, recurrenceid, obj)
   1.134 +        errors = self.handle_request(uid, recurrenceid, obj)
   1.135  
   1.136 -        if not error:
   1.137 +        if not errors:
   1.138              return True
   1.139  
   1.140          self.new_page(title="Event")
   1.141 -        self.show_object_on_page(uid, obj, error)
   1.142 +        self.show_object_on_page(uid, obj, errors)
   1.143  
   1.144          return True
   1.145