1.1 --- a/actions/EventAggregatorNewEvent.py Wed Mar 17 01:36:28 2010 +0100
1.2 +++ b/actions/EventAggregatorNewEvent.py Mon Mar 22 00:27:34 2010 +0100
1.3 @@ -15,6 +15,11 @@
1.4 from MoinMoin.PageEditor import PageEditor
1.5 import EventAggregatorSupport
1.6
1.7 +try:
1.8 + import pytz
1.9 +except ImportError:
1.10 + pytz = None
1.11 +
1.12 Dependencies = ['pages']
1.13
1.14 # Action class and supporting functions.
1.15 @@ -41,9 +46,18 @@
1.16 request = self.request
1.17 form = request.form
1.18
1.19 - # Handle advanced and basic forms.
1.20 + # Handle advanced and basic forms, and enable/disable certain fields.
1.21
1.22 show_advanced = form.get("advanced") and not form.get("basic")
1.23 + show_end_date = form.get("end-day") and not form.get("hide-end-date") or form.get("show-end-date")
1.24 + show_times = (form.get("start-hour") or form.get("end-hour")) and not form.get("hide-times") or form.get("show-times")
1.25 +
1.26 + show_zone_regime = form.get("regime") and not form.get("show-offsets") and \
1.27 + not form.get("hide-zone") or form.get("show-regime")
1.28 + show_zone_offsets = form.get("start-offset") and not form.get("show-regime") and \
1.29 + not form.get("hide-zone") or form.get("show-offsets")
1.30 +
1.31 + show_zones = show_zone_regime or show_zone_offsets
1.32
1.33 # Prepare the category list.
1.34
1.35 @@ -79,45 +93,13 @@
1.36 del topics[i]
1.37 break
1.38
1.39 - # Initialise hour and minute lists.
1.40 -
1.41 - start_hour_list = []
1.42 - start_hour_list.append('<option value=""></option>')
1.43 - start_minute_list = []
1.44 - start_minute_list.append('<option value=""></option>')
1.45 - end_hour_list = []
1.46 - end_hour_list.append('<option value=""></option>')
1.47 - end_minute_list = []
1.48 - end_minute_list.append('<option value=""></option>')
1.49 -
1.50 - start_hour = self._get_input(form, "start-hour")
1.51 - end_hour = self._get_input(form, "end-hour")
1.52 - start_minute = self._get_input(form, "start-minute")
1.53 - end_minute = self._get_input(form, "end-minute")
1.54 -
1.55 - # Prepare hour and minute lists, selecting specified values.
1.56 -
1.57 - for hour in range(0, 24):
1.58 - selected = self._get_selected(hour, start_hour)
1.59 - start_hour_list.append('<option value="%02d" %s>%02d</option>' % (hour, selected, hour))
1.60 - selected = self._get_selected(hour, end_hour)
1.61 - end_hour_list.append('<option value="%02d" %s>%02d</option>' % (hour, selected, hour))
1.62 -
1.63 - for minute in range(0, 60):
1.64 - selected = self._get_selected(minute, start_minute)
1.65 - start_minute_list.append('<option value="%02d" %s>%02d</option>' % (minute, selected, minute))
1.66 - selected = self._get_selected(minute, end_minute)
1.67 - end_minute_list.append('<option value="%02d" %s>%02d</option>' % (minute, selected, minute))
1.68 -
1.69 # Initialise month lists.
1.70
1.71 start_month_list = []
1.72 - start_month_list.append('<option value=""></option>')
1.73 end_month_list = []
1.74 - end_month_list.append('<option value=""></option>')
1.75
1.76 - start_month = self._get_input(form, "start-month", 0)
1.77 - end_month = self._get_input(form, "end-month", 0)
1.78 + start_month = self._get_input(form, "start-month", EventAggregatorSupport.getCurrentMonth())
1.79 + end_month = self._get_input(form, "end-month", start_month)
1.80
1.81 # Prepare month lists, selecting specified months.
1.82
1.83 @@ -128,6 +110,20 @@
1.84 selected = self._get_selected(month, end_month)
1.85 end_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, month_label))
1.86
1.87 + # Initialise regime lists.
1.88 +
1.89 + regime_list = []
1.90 + regime_list.append('<option value=""></option>')
1.91 +
1.92 + regime = form.get("regime", [None])[0]
1.93 +
1.94 + # Prepare regime lists, selecting specified regimes.
1.95 +
1.96 + if pytz is not None:
1.97 + for pytz_regime in pytz.common_timezones:
1.98 + selected = self._get_selected(pytz_regime, regime)
1.99 + regime_list.append('<option value="%s" %s>%s</option>' % (pytz_regime, selected, pytz_regime))
1.100 +
1.101 # Permitting configuration of the template name.
1.102
1.103 template_default = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate")
1.104 @@ -138,24 +134,38 @@
1.105 "category_list" : "\n".join(category_list),
1.106
1.107 "start_month_list" : "\n".join(start_month_list),
1.108 - "start_hour_list" : "\n".join(start_hour_list),
1.109 - "start_minute_list" : "\n".join(start_minute_list),
1.110 + "end_month_list" : "\n".join(end_month_list),
1.111 +
1.112 + "regime_list" : "\n".join(regime_list),
1.113 + "use_regime_label" : _("Using local time"),
1.114
1.115 - "end_month_list" : "\n".join(end_month_list),
1.116 - "end_hour_list" : "\n".join(end_hour_list),
1.117 - "end_minute_list" : "\n".join(end_minute_list),
1.118 + "show_end_date_label" : _("Specify end date"),
1.119 + "hide_end_date_label" : _("End event on same day"),
1.120 +
1.121 + "show_times_label" : _("Specify times"),
1.122 + "hide_times_label" : _("No start and end times"),
1.123 +
1.124 + "show_offsets_label" : _("Specify UTC offsets"),
1.125 + "show_regime_label" : _("Specify location"),
1.126 + "hide_zone_label" : _("Make times apply everywhere"),
1.127
1.128 "start_label" : _("Start date (day, month, year)"),
1.129 "start_day_default" : form.get("start-day", [""])[0],
1.130 "start_year_default" : form.get("start-year", [""])[0] or EventAggregatorSupport.getCurrentYear(),
1.131 "start_time_label" : _("Start time (hour, minute, second)"),
1.132 + "start_hour_default" : form.get("start-hour", [""])[0],
1.133 + "start_minute_default" : form.get("start-minute", [""])[0],
1.134 "start_second_default" : form.get("start-second", [""])[0],
1.135 + "start_offset_default" : form.get("start-offset", [""])[0],
1.136
1.137 "end_label" : _("End date (day, month, year) - if different"),
1.138 - "end_day_default" : form.get("end-day", [""])[0],
1.139 - "end_year_default" : form.get("end-year", [""])[0],
1.140 + "end_day_default" : form.get("end-day", [""])[0] or form.get("start-day", [""])[0],
1.141 + "end_year_default" : form.get("end-year", [""])[0] or form.get("start-year", [""])[0],
1.142 "end_time_label" : _("End time (hour, minute, second)"),
1.143 + "end_hour_default" : form.get("end-hour", [""])[0],
1.144 + "end_minute_default" : form.get("end-minute", [""])[0],
1.145 "end_second_default" : form.get("end-second", [""])[0],
1.146 + "end_offset_default" : form.get("end-offset", [""])[0] or form.get("start-offset", [""])[0],
1.147
1.148 "title_label" : _("Event title/summary"),
1.149 "title_default" : form.get("title", [""])[0],
1.150 @@ -176,7 +186,7 @@
1.151 "parent_default" : form.get("parent", [""])[0],
1.152
1.153 "advanced_label" : _("Show advanced options"),
1.154 - "basic_label" : _("Show basic options"),
1.155 + "basic_label" : _("Hide advanced options"),
1.156 }
1.157
1.158 # Prepare the output HTML.
1.159 @@ -185,35 +195,28 @@
1.160 <table>
1.161 <tr>
1.162 <td class="label"><label>%(title_label)s</label></td>
1.163 - <td>
1.164 + <td colspan="2">
1.165 <input name="title" type="text" size="40" value="%(title_default)s" />
1.166 </td>
1.167 </tr>
1.168 <tr>
1.169 <td class="label"><label>%(start_label)s</label></td>
1.170 - <td>
1.171 + <td colspan="2" style="white-space: nowrap">
1.172 <input name="start-day" type="text" value="%(start_day_default)s" size="2" />
1.173 <select name="start-month">
1.174 %(start_month_list)s
1.175 </select>
1.176 <input name="start-year" type="text" value="%(start_year_default)s" size="4" />
1.177 </td>
1.178 - </tr>
1.179 - <tr>
1.180 - <td class="label"><label>%(start_time_label)s</label></td>
1.181 - <td>
1.182 - <select name="start-hour">
1.183 - %(start_hour_list)s
1.184 - </select>
1.185 - <select name="start-minute">
1.186 - %(start_minute_list)s
1.187 - </select>
1.188 - <input name="start-second" type="text" value="%(start_second_default)s" size="2" />
1.189 - </td>
1.190 - </tr>
1.191 + </tr>''' % d
1.192 +
1.193 + # End date controls.
1.194 +
1.195 + if show_end_date:
1.196 + html += '''
1.197 <tr>
1.198 <td class="label"><label>%(end_label)s</label></td>
1.199 - <td>
1.200 + <td colspan="2" style="white-space: nowrap">
1.201 <input name="end-day" type="text" value="%(end_day_default)s" size="2" />
1.202 <select name="end-month">
1.203 %(end_month_list)s
1.204 @@ -222,33 +225,156 @@
1.205 </td>
1.206 </tr>
1.207 <tr>
1.208 - <td class="label"><label>%(end_time_label)s</label></td>
1.209 + <td class="label">
1.210 + <input name="hide-end-date" type="submit" value="%(hide_end_date_label)s" />
1.211 + </td>
1.212 + </tr>''' % d
1.213 + else:
1.214 + html += '''
1.215 + <tr>
1.216 + <td class="label">
1.217 + <input name="show-end-date" type="submit" value="%(show_end_date_label)s" />
1.218 + </td>
1.219 + </tr>''' % d
1.220 +
1.221 + # Generic time information.
1.222 +
1.223 + if show_times:
1.224 +
1.225 + # Start time controls.
1.226 +
1.227 + html += '''
1.228 + <tr>
1.229 + <td class="label"><label>%(start_time_label)s</label></td>
1.230 + <td style="white-space: nowrap">
1.231 + <input name="start-hour" type="text" value="%(start_hour_default)s" size="2" maxlength="2" />
1.232 + <input name="start-minute" type="text" value="%(start_minute_default)s" size="2" maxlength="2" />
1.233 + <input name="start-second" type="text" value="%(start_second_default)s" size="2" maxlength="2" />
1.234 + </td>''' % d
1.235 +
1.236 + # Offset information displayed.
1.237 +
1.238 + if show_zone_offsets:
1.239 + html += '''
1.240 <td>
1.241 - <select name="end-hour">
1.242 - %(end_hour_list)s
1.243 + UTC <input name="start-offset" type="text" value="%(start_offset_default)s" size="6" maxlength="6" />
1.244 + </td>''' % d
1.245 +
1.246 + # Regime information displayed.
1.247 +
1.248 + elif show_zone_regime:
1.249 + html += '''
1.250 + <td>
1.251 + %(use_regime_label)s
1.252 + </td>''' % d
1.253 +
1.254 + html += '''
1.255 + </tr>'''
1.256 +
1.257 + # End time controls.
1.258 +
1.259 + html += '''
1.260 + <tr>
1.261 + <td class="label"><label>%(end_time_label)s</label></td>
1.262 + <td style="white-space: nowrap">
1.263 + <input name="end-hour" type="text" value="%(end_hour_default)s" size="2" maxlength="2" />
1.264 + <input name="end-minute" type="text" value="%(end_minute_default)s" size="2" maxlength="2" />
1.265 + <input name="end-second" type="text" value="%(end_second_default)s" size="2" maxlength="2" />
1.266 + </td>''' % d
1.267 +
1.268 + # Offset information displayed.
1.269 +
1.270 + if show_zone_offsets:
1.271 + html += '''
1.272 + <td>
1.273 + UTC <input name="end-offset" type="text" value="%(end_offset_default)s" size="6" maxlength="6" />
1.274 + </td>''' % d
1.275 +
1.276 + # Regime information displayed.
1.277 +
1.278 + elif show_zone_regime:
1.279 + html += '''
1.280 + <td>
1.281 + <select name="regime">
1.282 + %(regime_list)s
1.283 </select>
1.284 - <select name="end-minute">
1.285 - %(end_minute_list)s
1.286 - </select>
1.287 - <input name="end-second" type="text" value="%(end_second_default)s" size="2" />
1.288 - </td>
1.289 + </td>''' % d
1.290 +
1.291 + # Controls for removing times.
1.292 +
1.293 + html += '''
1.294 </tr>
1.295 <tr>
1.296 + <td class="label">
1.297 + <input name="hide-times" type="submit" value="%(hide_times_label)s" />
1.298 + </td>
1.299 + <td></td>''' % d
1.300 +
1.301 + # Time zone controls.
1.302 +
1.303 + if show_zones:
1.304 +
1.305 + # Offset information displayed.
1.306 +
1.307 + if show_zone_offsets:
1.308 + html += '''
1.309 + <td>
1.310 + <input name="show-regime" type="submit" value="%(show_regime_label)s" />''' % d
1.311 +
1.312 + # Regime information displayed.
1.313 +
1.314 + elif show_zone_regime:
1.315 + html += '''
1.316 + <td>
1.317 + <input name="show-offsets" type="submit" value="%(show_offsets_label)s" />''' % d
1.318 +
1.319 + # To remove zone information.
1.320 +
1.321 + html += '''
1.322 + <input name="hide-zone" type="submit" value="%(hide_zone_label)s" />
1.323 + </td>''' % d
1.324 +
1.325 + # No time zone information shown.
1.326 +
1.327 + else:
1.328 + html += '''
1.329 + <td>
1.330 + <input name="show-regime" type="submit" value="%(show_regime_label)s" />
1.331 + <input name="show-offsets" type="submit" value="%(show_offsets_label)s" />
1.332 + </td>''' % d
1.333 +
1.334 + html += '''
1.335 + </tr>'''
1.336 +
1.337 + # Controls for adding times.
1.338 +
1.339 + else:
1.340 + html += '''
1.341 + <tr>
1.342 + <td class="label">
1.343 + <input name="show-times" type="submit" value="%(show_times_label)s" />
1.344 + </td>
1.345 + </tr>''' % d
1.346 +
1.347 +
1.348 + # Various basic controls.
1.349 +
1.350 + html += '''
1.351 + <tr>
1.352 <td class="label"><label>%(description_label)s</label></td>
1.353 - <td>
1.354 + <td colspan="2">
1.355 <input name="description" type="text" size="40" value="%(description_default)s" />
1.356 </td>
1.357 </tr>
1.358 <tr>
1.359 <td class="label"><label>%(location_label)s</label></td>
1.360 - <td>
1.361 + <td colspan="2">
1.362 <input name="location" type="text" size="40" value="%(location_default)s" />
1.363 </td>
1.364 </tr>
1.365 <tr>
1.366 - <tr>
1.367 <td class="label"><label>%(link_label)s</label></td>
1.368 - <td>
1.369 + <td colspan="2">
1.370 <input name="link" type="text" size="40" value="%(link_default)s" />
1.371 </td>
1.372 </tr>''' % d
1.373 @@ -261,7 +387,7 @@
1.374 html += '''
1.375 <tr>
1.376 <td class="label"><label>%(topics_label)s</label></td>
1.377 - <td>
1.378 + <td colspan="2">
1.379 <input name="topics" type="text" size="20" value="%(topic)s" />
1.380 <input name="remove-topic-%(topic_number)s" type="submit" value="%(remove_topic_label)s" />
1.381 </td>
1.382 @@ -270,7 +396,7 @@
1.383 html += '''
1.384 <tr>
1.385 <td></td>
1.386 - <td>
1.387 + <td colspan="2">
1.388 <input name="add-topic" type="submit" value="%(add_topic_label)s" />
1.389 </td>
1.390 </tr>''' % d
1.391 @@ -281,14 +407,14 @@
1.392 html += '''
1.393 <tr>
1.394 <td></td>
1.395 - <td>
1.396 + <td colspan="2">
1.397 <input name="basic" type="submit" value="%(basic_label)s" />
1.398 <input name="advanced" type="hidden" value="true" />
1.399 </td>
1.400 </tr>
1.401 <tr>
1.402 <td class="label"><label>%(category_label)s</label></td>
1.403 - <td class="content">
1.404 + <td colspan="2" class="content">
1.405 <select multiple="multiple" name="category">
1.406 %(category_list)s
1.407 </select>
1.408 @@ -296,19 +422,19 @@
1.409 </tr>
1.410 <tr>
1.411 <td class="label"><label>%(template_label)s</label></td>
1.412 - <td>
1.413 + <td colspan="2">
1.414 <input name="template" type="text" size="40" value="%(template_default)s" />
1.415 </td>
1.416 </tr>
1.417 <tr>
1.418 <td class="label"><label>%(parent_label)s</label></td>
1.419 - <td>
1.420 + <td colspan="2">
1.421 <input name="parent" type="text" size="40" value="%(parent_default)s" />
1.422 </td>
1.423 </tr>
1.424 <tr>
1.425 <td></td>
1.426 - <td class="buttons">
1.427 + <td colspan="2" class="buttons">
1.428 %(buttons_html)s
1.429 </td>
1.430 </tr>
1.431 @@ -317,7 +443,7 @@
1.432 html += '''
1.433 <tr>
1.434 <td></td>
1.435 - <td>
1.436 + <td colspan="2">
1.437 <input name="advanced" type="submit" value="%(advanced_label)s" />
1.438 %(category_list)s
1.439 <input name="parent" type="hidden" value="%(parent_default)s" />
1.440 @@ -326,7 +452,7 @@
1.441 </tr>
1.442 <tr>
1.443 <td></td>
1.444 - <td class="buttons">
1.445 + <td colspan="2" class="buttons">
1.446 %(buttons_html)s
1.447 </td>
1.448 </tr>
1.449 @@ -377,8 +503,12 @@
1.450 link = form.get("link", [None])[0]
1.451 topics = form.get("topics", [])
1.452
1.453 - start_zone = form.get("start-zone", [None])[0]
1.454 - end_zone = form.get("end-zone", [None])[0]
1.455 + regime = form.get("regime", [None])[0]
1.456 + start_offset = form.get("start-offset", [None])[0]
1.457 + end_offset = form.get("end-offset", [None])[0]
1.458 +
1.459 + start_zone = regime or start_offset
1.460 + end_zone = regime or end_offset
1.461
1.462 # Validate certain fields.
1.463