paul@46 | 1 | # -*- coding: iso-8859-1 -*- |
paul@46 | 2 | """ |
paul@46 | 3 | MoinMoin - EventAggregatorNewEvent Action |
paul@46 | 4 | |
paul@137 | 5 | @copyright: 2008, 2009, 2010, 2011 by Paul Boddie <paul@boddie.org.uk> |
paul@46 | 6 | @copyright: 2000-2004 Juergen Hermann <jh@web.de>, |
paul@46 | 7 | 2003-2008 MoinMoin:ThomasWaldmann, |
paul@46 | 8 | 2004-2006 MoinMoin:AlexanderSchremmer, |
paul@46 | 9 | 2007 MoinMoin:ReimarBauer. |
paul@46 | 10 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@46 | 11 | """ |
paul@46 | 12 | |
paul@46 | 13 | from MoinMoin.action import ActionBase |
paul@46 | 14 | from MoinMoin.Page import Page |
paul@46 | 15 | from MoinMoin.PageEditor import PageEditor |
paul@46 | 16 | import EventAggregatorSupport |
paul@46 | 17 | |
paul@137 | 18 | escape = EventAggregatorSupport.escape |
paul@137 | 19 | escattr = EventAggregatorSupport.escattr |
paul@137 | 20 | |
paul@99 | 21 | try: |
paul@99 | 22 | import pytz |
paul@99 | 23 | except ImportError: |
paul@99 | 24 | pytz = None |
paul@99 | 25 | |
paul@46 | 26 | Dependencies = ['pages'] |
paul@46 | 27 | |
paul@46 | 28 | # Action class and supporting functions. |
paul@46 | 29 | |
paul@46 | 30 | class EventAggregatorNewEvent(ActionBase): |
paul@46 | 31 | |
paul@46 | 32 | "An event creation dialogue requesting various parameters." |
paul@46 | 33 | |
paul@48 | 34 | def _get_selected(self, value, input_value): |
paul@48 | 35 | return input_value is not None and value == input_value and 'selected="selected"' or '' |
paul@46 | 36 | |
paul@48 | 37 | def _get_selected_for_list(self, value, input_values): |
paul@48 | 38 | return value in input_values and 'selected="selected"' or '' |
paul@48 | 39 | |
paul@96 | 40 | def _get_input(self, form, name, default=None): |
paul@96 | 41 | value = form.get(name, [None])[0] |
paul@96 | 42 | if not value: # true if 0 obtained |
paul@96 | 43 | return default |
paul@96 | 44 | else: |
paul@96 | 45 | return int(value) |
paul@46 | 46 | |
paul@46 | 47 | def get_form_html(self, buttons_html): |
paul@46 | 48 | _ = self._ |
paul@46 | 49 | request = self.request |
paul@46 | 50 | form = request.form |
paul@46 | 51 | |
paul@99 | 52 | # Handle advanced and basic forms, and enable/disable certain fields. |
paul@73 | 53 | |
paul@73 | 54 | show_advanced = form.get("advanced") and not form.get("basic") |
paul@99 | 55 | show_end_date = form.get("end-day") and not form.get("hide-end-date") or form.get("show-end-date") |
paul@99 | 56 | show_times = (form.get("start-hour") or form.get("end-hour")) and not form.get("hide-times") or form.get("show-times") |
paul@99 | 57 | |
paul@99 | 58 | show_zone_regime = form.get("regime") and not form.get("show-offsets") and \ |
paul@99 | 59 | not form.get("hide-zone") or form.get("show-regime") |
paul@99 | 60 | show_zone_offsets = form.get("start-offset") and not form.get("show-regime") and \ |
paul@99 | 61 | not form.get("hide-zone") or form.get("show-offsets") |
paul@99 | 62 | |
paul@99 | 63 | show_zones = show_zone_regime or show_zone_offsets |
paul@73 | 64 | |
paul@73 | 65 | # Prepare the category list. |
paul@73 | 66 | |
paul@46 | 67 | category_list = [] |
paul@48 | 68 | category_pagenames = form.get("category", []) |
paul@48 | 69 | |
paul@46 | 70 | for category_name, category_pagename in \ |
paul@46 | 71 | EventAggregatorSupport.getCategoryMapping( |
paul@46 | 72 | EventAggregatorSupport.getCategories(request), |
paul@46 | 73 | request): |
paul@46 | 74 | |
paul@48 | 75 | selected = self._get_selected_for_list(category_pagename, category_pagenames) |
paul@73 | 76 | |
paul@73 | 77 | # In the advanced view, populate a menu. |
paul@73 | 78 | |
paul@73 | 79 | if show_advanced: |
paul@137 | 80 | category_list.append('<option value="%s" %s>%s</option>' % ( |
paul@137 | 81 | escattr(category_pagename), selected, escape(category_name))) |
paul@73 | 82 | |
paul@73 | 83 | # In the basic view, use hidden fields. |
paul@73 | 84 | |
paul@73 | 85 | elif selected: |
paul@137 | 86 | category_list.append('<input value="%s" name="category" type="hidden" />' % escattr(category_pagename)) |
paul@46 | 87 | |
paul@92 | 88 | # Prepare the topics list. |
paul@92 | 89 | |
paul@92 | 90 | topics = form.get("topics", []) |
paul@92 | 91 | |
paul@92 | 92 | if form.get("add-topic"): |
paul@92 | 93 | topics.append("") |
paul@92 | 94 | else: |
paul@92 | 95 | for i in range(0, len(topics)): |
paul@92 | 96 | if form.get("remove-topic-%d" % i): |
paul@92 | 97 | del topics[i] |
paul@92 | 98 | break |
paul@92 | 99 | |
paul@46 | 100 | # Initialise month lists. |
paul@46 | 101 | |
paul@46 | 102 | start_month_list = [] |
paul@46 | 103 | end_month_list = [] |
paul@46 | 104 | |
paul@105 | 105 | start_month = self._get_input(form, "start-month", EventAggregatorSupport.getCurrentMonth().month()) |
paul@99 | 106 | end_month = self._get_input(form, "end-month", start_month) |
paul@46 | 107 | |
paul@46 | 108 | # Prepare month lists, selecting specified months. |
paul@46 | 109 | |
paul@46 | 110 | for month in range(1, 13): |
paul@46 | 111 | month_label = _(EventAggregatorSupport.getMonthLabel(month)) |
paul@46 | 112 | selected = self._get_selected(month, start_month) |
paul@137 | 113 | start_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, escape(month_label))) |
paul@46 | 114 | selected = self._get_selected(month, end_month) |
paul@137 | 115 | end_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, escape(month_label))) |
paul@46 | 116 | |
paul@99 | 117 | # Initialise regime lists. |
paul@99 | 118 | |
paul@99 | 119 | regime_list = [] |
paul@99 | 120 | regime_list.append('<option value=""></option>') |
paul@99 | 121 | |
paul@99 | 122 | regime = form.get("regime", [None])[0] |
paul@99 | 123 | |
paul@99 | 124 | # Prepare regime lists, selecting specified regimes. |
paul@99 | 125 | |
paul@99 | 126 | if pytz is not None: |
paul@99 | 127 | for pytz_regime in pytz.common_timezones: |
paul@99 | 128 | selected = self._get_selected(pytz_regime, regime) |
paul@137 | 129 | regime_list.append('<option value="%s" %s>%s</option>' % (escattr(pytz_regime), selected, escape(pytz_regime))) |
paul@99 | 130 | |
paul@49 | 131 | # Permitting configuration of the template name. |
paul@49 | 132 | |
paul@49 | 133 | template_default = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate") |
paul@49 | 134 | |
paul@46 | 135 | d = { |
paul@49 | 136 | "buttons_html" : buttons_html, |
paul@137 | 137 | "category_label" : escape(_("Categories")), |
paul@49 | 138 | "category_list" : "\n".join(category_list), |
paul@96 | 139 | |
paul@49 | 140 | "start_month_list" : "\n".join(start_month_list), |
paul@99 | 141 | "end_month_list" : "\n".join(end_month_list), |
paul@99 | 142 | |
paul@99 | 143 | "regime_list" : "\n".join(regime_list), |
paul@137 | 144 | "use_regime_label" : escape(_("Using local time")), |
paul@96 | 145 | |
paul@137 | 146 | "show_end_date_label" : escape(_("Specify end date")), |
paul@137 | 147 | "hide_end_date_label" : escape(_("End event on same day")), |
paul@99 | 148 | |
paul@137 | 149 | "show_times_label" : escape(_("Specify times")), |
paul@137 | 150 | "hide_times_label" : escape(_("No start and end times")), |
paul@99 | 151 | |
paul@137 | 152 | "show_offsets_label" : escape(_("Specify UTC offsets")), |
paul@137 | 153 | "show_regime_label" : escape(_("Specify location")), |
paul@137 | 154 | "hide_zone_label" : escape(_("Make times apply everywhere")), |
paul@96 | 155 | |
paul@137 | 156 | "start_label" : escape(_("Start date (day, month, year)")), |
paul@137 | 157 | "start_day_default" : escattr(form.get("start-day", [""])[0]), |
paul@137 | 158 | "start_year_default" : escattr(form.get("start-year", [""])[0] or EventAggregatorSupport.getCurrentYear()), |
paul@137 | 159 | "start_time_label" : escape(_("Start time (hour, minute, second)")), |
paul@137 | 160 | "start_hour_default" : escattr(form.get("start-hour", [""])[0]), |
paul@137 | 161 | "start_minute_default" : escattr(form.get("start-minute", [""])[0]), |
paul@137 | 162 | "start_second_default" : escattr(form.get("start-second", [""])[0]), |
paul@137 | 163 | "start_offset_default" : escattr(form.get("start-offset", [""])[0]), |
paul@96 | 164 | |
paul@137 | 165 | "end_label" : escape(_("End date (day, month, year) - if different")), |
paul@137 | 166 | "end_day_default" : escattr(form.get("end-day", [""])[0] or form.get("start-day", [""])[0]), |
paul@137 | 167 | "end_year_default" : escattr(form.get("end-year", [""])[0] or form.get("start-year", [""])[0]), |
paul@137 | 168 | "end_time_label" : escape(_("End time (hour, minute, second)")), |
paul@137 | 169 | "end_hour_default" : escattr(form.get("end-hour", [""])[0]), |
paul@137 | 170 | "end_minute_default" : escattr(form.get("end-minute", [""])[0]), |
paul@137 | 171 | "end_second_default" : escattr(form.get("end-second", [""])[0]), |
paul@137 | 172 | "end_offset_default" : escattr(form.get("end-offset", [""])[0] or form.get("start-offset", [""])[0]), |
paul@96 | 173 | |
paul@137 | 174 | "title_label" : escape(_("Event title/summary")), |
paul@137 | 175 | "title_default" : escattr(form.get("title", [""])[0]), |
paul@137 | 176 | "description_label" : escape(_("Event description")), |
paul@137 | 177 | "description_default" : escattr(form.get("description", [""])[0]), |
paul@137 | 178 | "location_label" : escape(_("Event location")), |
paul@137 | 179 | "location_default" : escattr(form.get("location", [""])[0]), |
paul@137 | 180 | "link_label" : escape(_("Event URL")), |
paul@137 | 181 | "link_default" : escattr(form.get("link", [""])[0]), |
paul@96 | 182 | |
paul@137 | 183 | "topics_label" : escape(_("Topics")), |
paul@137 | 184 | "add_topic_label" : escape(_("Add topic")), |
paul@137 | 185 | "remove_topic_label" : escape(_("Remove topic")), |
paul@96 | 186 | |
paul@137 | 187 | "template_label" : escape(_("Event template")), |
paul@137 | 188 | "template_default" : escattr(form.get("template", [""])[0] or template_default), |
paul@137 | 189 | "parent_label" : escape(_("Parent page")), |
paul@137 | 190 | "parent_default" : escattr(form.get("parent", [""])[0]), |
paul@96 | 191 | |
paul@137 | 192 | "advanced_label" : escape(_("Show advanced options")), |
paul@137 | 193 | "basic_label" : escape(_("Hide advanced options")), |
paul@46 | 194 | } |
paul@46 | 195 | |
paul@73 | 196 | # Prepare the output HTML. |
paul@73 | 197 | |
paul@73 | 198 | html = ''' |
paul@46 | 199 | <table> |
paul@46 | 200 | <tr> |
paul@46 | 201 | <td class="label"><label>%(title_label)s</label></td> |
paul@99 | 202 | <td colspan="2"> |
paul@48 | 203 | <input name="title" type="text" size="40" value="%(title_default)s" /> |
paul@48 | 204 | </td> |
paul@48 | 205 | </tr> |
paul@46 | 206 | <tr> |
paul@46 | 207 | <td class="label"><label>%(start_label)s</label></td> |
paul@99 | 208 | <td colspan="2" style="white-space: nowrap"> |
paul@46 | 209 | <input name="start-day" type="text" value="%(start_day_default)s" size="2" /> |
paul@46 | 210 | <select name="start-month"> |
paul@46 | 211 | %(start_month_list)s |
paul@46 | 212 | </select> |
paul@46 | 213 | <input name="start-year" type="text" value="%(start_year_default)s" size="4" /> |
paul@46 | 214 | </td> |
paul@99 | 215 | </tr>''' % d |
paul@99 | 216 | |
paul@99 | 217 | # End date controls. |
paul@99 | 218 | |
paul@99 | 219 | if show_end_date: |
paul@99 | 220 | html += ''' |
paul@96 | 221 | <tr> |
paul@46 | 222 | <td class="label"><label>%(end_label)s</label></td> |
paul@99 | 223 | <td colspan="2" style="white-space: nowrap"> |
paul@46 | 224 | <input name="end-day" type="text" value="%(end_day_default)s" size="2" /> |
paul@46 | 225 | <select name="end-month"> |
paul@46 | 226 | %(end_month_list)s |
paul@46 | 227 | </select> |
paul@46 | 228 | <input name="end-year" type="text" value="%(end_year_default)s" size="4" /> |
paul@46 | 229 | </td> |
paul@46 | 230 | </tr> |
paul@46 | 231 | <tr> |
paul@99 | 232 | <td class="label"> |
paul@99 | 233 | <input name="hide-end-date" type="submit" value="%(hide_end_date_label)s" /> |
paul@99 | 234 | </td> |
paul@99 | 235 | </tr>''' % d |
paul@99 | 236 | else: |
paul@99 | 237 | html += ''' |
paul@99 | 238 | <tr> |
paul@99 | 239 | <td class="label"> |
paul@99 | 240 | <input name="show-end-date" type="submit" value="%(show_end_date_label)s" /> |
paul@99 | 241 | </td> |
paul@99 | 242 | </tr>''' % d |
paul@99 | 243 | |
paul@99 | 244 | # Generic time information. |
paul@99 | 245 | |
paul@99 | 246 | if show_times: |
paul@99 | 247 | |
paul@99 | 248 | # Start time controls. |
paul@99 | 249 | |
paul@99 | 250 | html += ''' |
paul@99 | 251 | <tr> |
paul@99 | 252 | <td class="label"><label>%(start_time_label)s</label></td> |
paul@99 | 253 | <td style="white-space: nowrap"> |
paul@99 | 254 | <input name="start-hour" type="text" value="%(start_hour_default)s" size="2" maxlength="2" /> |
paul@99 | 255 | <input name="start-minute" type="text" value="%(start_minute_default)s" size="2" maxlength="2" /> |
paul@99 | 256 | <input name="start-second" type="text" value="%(start_second_default)s" size="2" maxlength="2" /> |
paul@99 | 257 | </td>''' % d |
paul@99 | 258 | |
paul@99 | 259 | # Offset information displayed. |
paul@99 | 260 | |
paul@99 | 261 | if show_zone_offsets: |
paul@99 | 262 | html += ''' |
paul@96 | 263 | <td> |
paul@99 | 264 | UTC <input name="start-offset" type="text" value="%(start_offset_default)s" size="6" maxlength="6" /> |
paul@99 | 265 | </td>''' % d |
paul@99 | 266 | |
paul@99 | 267 | # Regime information displayed. |
paul@99 | 268 | |
paul@99 | 269 | elif show_zone_regime: |
paul@99 | 270 | html += ''' |
paul@99 | 271 | <td> |
paul@99 | 272 | %(use_regime_label)s |
paul@99 | 273 | </td>''' % d |
paul@99 | 274 | |
paul@99 | 275 | html += ''' |
paul@99 | 276 | </tr>''' |
paul@99 | 277 | |
paul@99 | 278 | # End time controls. |
paul@99 | 279 | |
paul@99 | 280 | html += ''' |
paul@99 | 281 | <tr> |
paul@99 | 282 | <td class="label"><label>%(end_time_label)s</label></td> |
paul@99 | 283 | <td style="white-space: nowrap"> |
paul@99 | 284 | <input name="end-hour" type="text" value="%(end_hour_default)s" size="2" maxlength="2" /> |
paul@99 | 285 | <input name="end-minute" type="text" value="%(end_minute_default)s" size="2" maxlength="2" /> |
paul@99 | 286 | <input name="end-second" type="text" value="%(end_second_default)s" size="2" maxlength="2" /> |
paul@99 | 287 | </td>''' % d |
paul@99 | 288 | |
paul@99 | 289 | # Offset information displayed. |
paul@99 | 290 | |
paul@99 | 291 | if show_zone_offsets: |
paul@99 | 292 | html += ''' |
paul@99 | 293 | <td> |
paul@99 | 294 | UTC <input name="end-offset" type="text" value="%(end_offset_default)s" size="6" maxlength="6" /> |
paul@99 | 295 | </td>''' % d |
paul@99 | 296 | |
paul@99 | 297 | # Regime information displayed. |
paul@99 | 298 | |
paul@99 | 299 | elif show_zone_regime: |
paul@99 | 300 | html += ''' |
paul@99 | 301 | <td> |
paul@99 | 302 | <select name="regime"> |
paul@99 | 303 | %(regime_list)s |
paul@96 | 304 | </select> |
paul@99 | 305 | </td>''' % d |
paul@99 | 306 | |
paul@99 | 307 | # Controls for removing times. |
paul@99 | 308 | |
paul@99 | 309 | html += ''' |
paul@96 | 310 | </tr> |
paul@96 | 311 | <tr> |
paul@99 | 312 | <td class="label"> |
paul@99 | 313 | <input name="hide-times" type="submit" value="%(hide_times_label)s" /> |
paul@99 | 314 | </td> |
paul@99 | 315 | <td></td>''' % d |
paul@99 | 316 | |
paul@99 | 317 | # Time zone controls. |
paul@99 | 318 | |
paul@99 | 319 | if show_zones: |
paul@99 | 320 | |
paul@99 | 321 | # Offset information displayed. |
paul@99 | 322 | |
paul@99 | 323 | if show_zone_offsets: |
paul@99 | 324 | html += ''' |
paul@99 | 325 | <td> |
paul@99 | 326 | <input name="show-regime" type="submit" value="%(show_regime_label)s" />''' % d |
paul@99 | 327 | |
paul@99 | 328 | # Regime information displayed. |
paul@99 | 329 | |
paul@99 | 330 | elif show_zone_regime: |
paul@99 | 331 | html += ''' |
paul@99 | 332 | <td> |
paul@99 | 333 | <input name="show-offsets" type="submit" value="%(show_offsets_label)s" />''' % d |
paul@99 | 334 | |
paul@99 | 335 | # To remove zone information. |
paul@99 | 336 | |
paul@99 | 337 | html += ''' |
paul@99 | 338 | <input name="hide-zone" type="submit" value="%(hide_zone_label)s" /> |
paul@99 | 339 | </td>''' % d |
paul@99 | 340 | |
paul@99 | 341 | # No time zone information shown. |
paul@99 | 342 | |
paul@99 | 343 | else: |
paul@99 | 344 | html += ''' |
paul@99 | 345 | <td> |
paul@99 | 346 | <input name="show-regime" type="submit" value="%(show_regime_label)s" /> |
paul@99 | 347 | <input name="show-offsets" type="submit" value="%(show_offsets_label)s" /> |
paul@99 | 348 | </td>''' % d |
paul@99 | 349 | |
paul@99 | 350 | html += ''' |
paul@99 | 351 | </tr>''' |
paul@99 | 352 | |
paul@99 | 353 | # Controls for adding times. |
paul@99 | 354 | |
paul@99 | 355 | else: |
paul@99 | 356 | html += ''' |
paul@99 | 357 | <tr> |
paul@99 | 358 | <td class="label"> |
paul@99 | 359 | <input name="show-times" type="submit" value="%(show_times_label)s" /> |
paul@99 | 360 | </td> |
paul@99 | 361 | </tr>''' % d |
paul@99 | 362 | |
paul@99 | 363 | |
paul@99 | 364 | # Various basic controls. |
paul@99 | 365 | |
paul@99 | 366 | html += ''' |
paul@99 | 367 | <tr> |
paul@49 | 368 | <td class="label"><label>%(description_label)s</label></td> |
paul@99 | 369 | <td colspan="2"> |
paul@49 | 370 | <input name="description" type="text" size="40" value="%(description_default)s" /> |
paul@49 | 371 | </td> |
paul@92 | 372 | </tr> |
paul@92 | 373 | <tr> |
paul@92 | 374 | <td class="label"><label>%(location_label)s</label></td> |
paul@99 | 375 | <td colspan="2"> |
paul@92 | 376 | <input name="location" type="text" size="40" value="%(location_default)s" /> |
paul@92 | 377 | </td> |
paul@92 | 378 | </tr> |
paul@92 | 379 | <tr> |
paul@92 | 380 | <td class="label"><label>%(link_label)s</label></td> |
paul@99 | 381 | <td colspan="2"> |
paul@92 | 382 | <input name="link" type="text" size="40" value="%(link_default)s" /> |
paul@92 | 383 | </td> |
paul@73 | 384 | </tr>''' % d |
paul@73 | 385 | |
paul@92 | 386 | # Topics. |
paul@92 | 387 | |
paul@92 | 388 | for i, topic in enumerate(topics): |
paul@137 | 389 | d["topic"] = escattr(topic) |
paul@92 | 390 | d["topic_number"] = i |
paul@92 | 391 | html += ''' |
paul@92 | 392 | <tr> |
paul@92 | 393 | <td class="label"><label>%(topics_label)s</label></td> |
paul@99 | 394 | <td colspan="2"> |
paul@92 | 395 | <input name="topics" type="text" size="20" value="%(topic)s" /> |
paul@92 | 396 | <input name="remove-topic-%(topic_number)s" type="submit" value="%(remove_topic_label)s" /> |
paul@92 | 397 | </td> |
paul@92 | 398 | </tr>''' % d |
paul@92 | 399 | |
paul@92 | 400 | html += ''' |
paul@92 | 401 | <tr> |
paul@92 | 402 | <td></td> |
paul@99 | 403 | <td colspan="2"> |
paul@92 | 404 | <input name="add-topic" type="submit" value="%(add_topic_label)s" /> |
paul@92 | 405 | </td> |
paul@92 | 406 | </tr>''' % d |
paul@92 | 407 | |
paul@92 | 408 | # Advanced options. |
paul@92 | 409 | |
paul@73 | 410 | if show_advanced: |
paul@73 | 411 | html += ''' |
paul@73 | 412 | <tr> |
paul@73 | 413 | <td></td> |
paul@99 | 414 | <td colspan="2"> |
paul@73 | 415 | <input name="basic" type="submit" value="%(basic_label)s" /> |
paul@73 | 416 | <input name="advanced" type="hidden" value="true" /> |
paul@73 | 417 | </td> |
paul@73 | 418 | </tr> |
paul@73 | 419 | <tr> |
paul@73 | 420 | <td class="label"><label>%(category_label)s</label></td> |
paul@99 | 421 | <td colspan="2" class="content"> |
paul@73 | 422 | <select multiple="multiple" name="category"> |
paul@73 | 423 | %(category_list)s |
paul@73 | 424 | </select> |
paul@73 | 425 | </td> |
paul@49 | 426 | </tr> |
paul@49 | 427 | <tr> |
paul@49 | 428 | <td class="label"><label>%(template_label)s</label></td> |
paul@99 | 429 | <td colspan="2"> |
paul@49 | 430 | <input name="template" type="text" size="40" value="%(template_default)s" /> |
paul@49 | 431 | </td> |
paul@49 | 432 | </tr> |
paul@49 | 433 | <tr> |
paul@55 | 434 | <td class="label"><label>%(parent_label)s</label></td> |
paul@99 | 435 | <td colspan="2"> |
paul@55 | 436 | <input name="parent" type="text" size="40" value="%(parent_default)s" /> |
paul@55 | 437 | </td> |
paul@55 | 438 | </tr> |
paul@55 | 439 | <tr> |
paul@46 | 440 | <td></td> |
paul@99 | 441 | <td colspan="2" class="buttons"> |
paul@46 | 442 | %(buttons_html)s |
paul@46 | 443 | </td> |
paul@46 | 444 | </tr> |
paul@73 | 445 | </table>''' % d |
paul@73 | 446 | else: |
paul@73 | 447 | html += ''' |
paul@73 | 448 | <tr> |
paul@73 | 449 | <td></td> |
paul@99 | 450 | <td colspan="2"> |
paul@73 | 451 | <input name="advanced" type="submit" value="%(advanced_label)s" /> |
paul@73 | 452 | %(category_list)s |
paul@73 | 453 | <input name="parent" type="hidden" value="%(parent_default)s" /> |
paul@73 | 454 | <input name="template" type="hidden" value="%(template_default)s" /> |
paul@73 | 455 | </td> |
paul@73 | 456 | </tr> |
paul@73 | 457 | <tr> |
paul@73 | 458 | <td></td> |
paul@99 | 459 | <td colspan="2" class="buttons"> |
paul@73 | 460 | %(buttons_html)s |
paul@73 | 461 | </td> |
paul@73 | 462 | </tr> |
paul@73 | 463 | </table>''' % d |
paul@73 | 464 | |
paul@73 | 465 | return html |
paul@46 | 466 | |
paul@46 | 467 | def do_action(self): |
paul@46 | 468 | |
paul@46 | 469 | "Create the new event." |
paul@46 | 470 | |
paul@46 | 471 | _ = self._ |
paul@46 | 472 | form = self.request.form |
paul@46 | 473 | |
paul@46 | 474 | # If no title exists in the request, an error message is returned. |
paul@46 | 475 | |
paul@46 | 476 | title = form.get("title", [None])[0] |
paul@49 | 477 | template = form.get("template", [None])[0] |
paul@46 | 478 | |
paul@46 | 479 | if not title: |
paul@46 | 480 | return 0, _("No event title specified.") |
paul@46 | 481 | |
paul@49 | 482 | if not template: |
paul@49 | 483 | return 0, _("No page template specified.") |
paul@49 | 484 | |
paul@46 | 485 | return self.create_event(self.request) |
paul@46 | 486 | |
paul@46 | 487 | def render_success(self, msg, msgtype=None): |
paul@46 | 488 | |
paul@46 | 489 | """ |
paul@46 | 490 | Render neither 'msg' nor 'msgtype' since redirection should occur |
paul@46 | 491 | instead. |
paul@46 | 492 | NOTE: msgtype is optional because MoinMoin 1.5.x does not support it. |
paul@46 | 493 | """ |
paul@46 | 494 | |
paul@46 | 495 | pass |
paul@46 | 496 | |
paul@46 | 497 | def create_event(self, request): |
paul@46 | 498 | |
paul@46 | 499 | "Create an event page using the 'request'." |
paul@46 | 500 | |
paul@46 | 501 | _ = request.getText |
paul@47 | 502 | form = request.form |
paul@46 | 503 | |
paul@48 | 504 | category_pagenames = form.get("category", []) |
paul@49 | 505 | description = form.get("description", [None])[0] |
paul@92 | 506 | location = form.get("location", [None])[0] |
paul@92 | 507 | link = form.get("link", [None])[0] |
paul@92 | 508 | topics = form.get("topics", []) |
paul@92 | 509 | |
paul@99 | 510 | regime = form.get("regime", [None])[0] |
paul@99 | 511 | start_offset = form.get("start-offset", [None])[0] |
paul@99 | 512 | end_offset = form.get("end-offset", [None])[0] |
paul@99 | 513 | |
paul@99 | 514 | start_zone = regime or start_offset |
paul@99 | 515 | end_zone = regime or end_offset |
paul@96 | 516 | |
paul@92 | 517 | # Validate certain fields. |
paul@46 | 518 | |
paul@46 | 519 | try: |
paul@49 | 520 | title = form["title"][0] |
paul@49 | 521 | template = form["template"][0] |
paul@55 | 522 | parent = form["parent"][0] |
paul@96 | 523 | except (KeyError, IndexError): |
paul@96 | 524 | return 0, _("Event title or template missing.") |
paul@49 | 525 | |
paul@96 | 526 | try: |
paul@97 | 527 | start_day = self._get_input(form, "start-day") |
paul@97 | 528 | start_month = self._get_input(form, "start-month") |
paul@97 | 529 | start_year = self._get_input(form, "start-year") |
paul@97 | 530 | |
paul@97 | 531 | if not start_day or not start_month or not start_year: |
paul@97 | 532 | return 0, _("A start date must be specified.") |
paul@97 | 533 | |
paul@48 | 534 | end_day = self._get_input(form, "end-day", start_day) |
paul@48 | 535 | end_month = self._get_input(form, "end-month", start_month) |
paul@48 | 536 | end_year = self._get_input(form, "end-year", start_year) |
paul@46 | 537 | |
paul@48 | 538 | except (TypeError, ValueError): |
paul@46 | 539 | return 0, _("Days and years must be numbers yielding a valid date!") |
paul@46 | 540 | |
paul@96 | 541 | try: |
paul@96 | 542 | start_hour = self._get_input(form, "start-hour") |
paul@96 | 543 | start_minute = self._get_input(form, "start-minute") |
paul@96 | 544 | start_second = self._get_input(form, "start-second") |
paul@96 | 545 | |
paul@96 | 546 | end_hour = self._get_input(form, "end-hour") |
paul@96 | 547 | end_minute = self._get_input(form, "end-minute") |
paul@96 | 548 | end_second = self._get_input(form, "end-second") |
paul@49 | 549 | |
paul@96 | 550 | except (TypeError, ValueError): |
paul@96 | 551 | return 0, _("Hours, minutes and seconds must be numbers yielding a valid time!") |
paul@96 | 552 | |
paul@96 | 553 | start_date = EventAggregatorSupport.DateTime( |
paul@96 | 554 | (start_year, start_month, start_day, start_hour, start_minute, start_second, start_zone) |
paul@96 | 555 | ) |
paul@96 | 556 | start_date.constrain() |
paul@96 | 557 | |
paul@96 | 558 | end_date = EventAggregatorSupport.DateTime( |
paul@96 | 559 | (end_year, end_month, end_day, end_hour, end_minute, end_second, end_zone) |
paul@96 | 560 | ) |
paul@96 | 561 | end_date.constrain() |
paul@46 | 562 | |
paul@78 | 563 | # An elementary date ordering check. |
paul@78 | 564 | |
paul@96 | 565 | if (start_date.as_date() != end_date.as_date() or start_date.has_time() and end_date.has_time()) and start_date > end_date: |
paul@78 | 566 | start_date, end_date = end_date, start_date |
paul@78 | 567 | |
paul@88 | 568 | event_details = { |
paul@96 | 569 | "start" : str(start_date), "end" : str(end_date), |
paul@88 | 570 | "title" : title, "summary" : title, |
paul@92 | 571 | "description" : description, "location" : location, "link" : link, |
paul@92 | 572 | "topics" : [topic for topic in topics if topic] |
paul@88 | 573 | } |
paul@88 | 574 | |
paul@46 | 575 | # Copy the template. |
paul@49 | 576 | |
paul@88 | 577 | template_page = PageEditor(request, template) |
paul@46 | 578 | |
paul@88 | 579 | if not template_page.exists(): |
paul@49 | 580 | return 0, _("Event template not available.") |
paul@49 | 581 | |
paul@55 | 582 | # Use any parent page information. |
paul@55 | 583 | |
paul@88 | 584 | full_title = EventAggregatorSupport.getFullPageName(parent, title) |
paul@55 | 585 | |
paul@47 | 586 | # Load the new page and replace the event details in the body. |
paul@46 | 587 | |
paul@64 | 588 | new_page = PageEditor(request, full_title) |
paul@46 | 589 | |
paul@46 | 590 | if new_page.exists(): |
paul@46 | 591 | return 0, _("The specified page already exists. Please choose another name.") |
paul@46 | 592 | |
paul@88 | 593 | # Complete the new page. |
paul@67 | 594 | |
paul@88 | 595 | EventAggregatorSupport.fillEventPageFromTemplate(template_page, |
paul@88 | 596 | new_page, event_details, category_pagenames) |
paul@46 | 597 | |
paul@46 | 598 | # Redirect and return success. |
paul@46 | 599 | |
paul@47 | 600 | query = {'action' : 'edit'} |
paul@46 | 601 | request.http_redirect(new_page.url(request, query)) |
paul@46 | 602 | return 1, None |
paul@46 | 603 | |
paul@46 | 604 | # Action function. |
paul@46 | 605 | |
paul@46 | 606 | def execute(pagename, request): |
paul@46 | 607 | EventAggregatorNewEvent(pagename, request).render() |
paul@46 | 608 | |
paul@46 | 609 | # vim: tabstop=4 expandtab shiftwidth=4 |