paul@46 | 1 | # -*- coding: iso-8859-1 -*- |
paul@46 | 2 | """ |
paul@46 | 3 | MoinMoin - EventAggregatorNewEvent Action |
paul@46 | 4 | |
paul@327 | 5 | @copyright: 2008, 2009, 2010, 2011, 2012 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@238 | 16 | from MoinMoin import config |
paul@168 | 17 | from EventAggregatorSupport import * |
paul@327 | 18 | import re |
paul@137 | 19 | |
paul@99 | 20 | try: |
paul@99 | 21 | import pytz |
paul@99 | 22 | except ImportError: |
paul@99 | 23 | pytz = None |
paul@99 | 24 | |
paul@46 | 25 | Dependencies = ['pages'] |
paul@46 | 26 | |
paul@46 | 27 | # Action class and supporting functions. |
paul@46 | 28 | |
paul@168 | 29 | class EventAggregatorNewEvent(ActionBase, ActionSupport): |
paul@46 | 30 | |
paul@46 | 31 | "An event creation dialogue requesting various parameters." |
paul@46 | 32 | |
paul@46 | 33 | def get_form_html(self, buttons_html): |
paul@46 | 34 | _ = self._ |
paul@46 | 35 | request = self.request |
paul@109 | 36 | form = self.get_form() |
paul@46 | 37 | |
paul@99 | 38 | # Handle advanced and basic forms, and enable/disable certain fields. |
paul@73 | 39 | |
paul@73 | 40 | show_advanced = form.get("advanced") and not form.get("basic") |
paul@99 | 41 | show_end_date = form.get("end-day") and not form.get("hide-end-date") or form.get("show-end-date") |
paul@99 | 42 | show_times = (form.get("start-hour") or form.get("end-hour")) and not form.get("hide-times") or form.get("show-times") |
paul@294 | 43 | show_location = form.get("show-location") or form.get("new-location") and not form.get("hide-location") |
paul@327 | 44 | choose_page_name = form.get("page-name") and not form.get("auto-page-name") or form.get("choose-page-name") |
paul@327 | 45 | |
paul@327 | 46 | # Define the overridden page name, if appropriate. |
paul@327 | 47 | |
paul@327 | 48 | page_name = choose_page_name and form.get("page-name", ["@PARENT@/@TITLE@"])[0] or "" |
paul@73 | 49 | |
paul@73 | 50 | # Prepare the category list. |
paul@73 | 51 | |
paul@46 | 52 | category_list = [] |
paul@48 | 53 | category_pagenames = form.get("category", []) |
paul@48 | 54 | |
paul@168 | 55 | for category_name, category_pagename in getCategoryMapping(getCategories(request), request): |
paul@46 | 56 | |
paul@48 | 57 | selected = self._get_selected_for_list(category_pagename, category_pagenames) |
paul@73 | 58 | |
paul@73 | 59 | # In the advanced view, populate a menu. |
paul@73 | 60 | |
paul@73 | 61 | if show_advanced: |
paul@137 | 62 | category_list.append('<option value="%s" %s>%s</option>' % ( |
paul@137 | 63 | escattr(category_pagename), selected, escape(category_name))) |
paul@73 | 64 | |
paul@73 | 65 | # In the basic view, use hidden fields. |
paul@73 | 66 | |
paul@73 | 67 | elif selected: |
paul@137 | 68 | category_list.append('<input value="%s" name="category" type="hidden" />' % escattr(category_pagename)) |
paul@46 | 69 | |
paul@92 | 70 | # Prepare the topics list. |
paul@92 | 71 | |
paul@92 | 72 | topics = form.get("topics", []) |
paul@92 | 73 | |
paul@92 | 74 | if form.get("add-topic"): |
paul@92 | 75 | topics.append("") |
paul@92 | 76 | else: |
paul@92 | 77 | for i in range(0, len(topics)): |
paul@92 | 78 | if form.get("remove-topic-%d" % i): |
paul@92 | 79 | del topics[i] |
paul@92 | 80 | break |
paul@92 | 81 | |
paul@46 | 82 | # Initialise month lists. |
paul@46 | 83 | |
paul@114 | 84 | start_month_list, end_month_list = self.get_month_lists(default_as_current=1) |
paul@114 | 85 | start_year_default, end_year_default = self.get_year_defaults(default_as_current=1) |
paul@46 | 86 | |
paul@294 | 87 | # Initialise the locations list. |
paul@294 | 88 | |
paul@294 | 89 | locations_page = getLocationsPage(request) |
paul@294 | 90 | locations = getWikiDict(locations_page, request) |
paul@294 | 91 | |
paul@294 | 92 | locations_list = [] |
paul@294 | 93 | locations_list.append('<option value=""></option>') |
paul@294 | 94 | |
paul@294 | 95 | location = (form.get("location") or form.get("new-location") or [""])[0] |
paul@294 | 96 | |
paul@294 | 97 | # Prepare the locations list, selecting the specified location. |
paul@294 | 98 | |
paul@294 | 99 | if locations: |
paul@294 | 100 | locations_list += self.get_option_list(location, locations) or [] |
paul@294 | 101 | |
paul@294 | 102 | locations_list.sort() |
paul@294 | 103 | |
paul@294 | 104 | # Initialise the time regime from the location. |
paul@294 | 105 | |
paul@295 | 106 | start_regime = form.get("start-regime", [None])[0] |
paul@295 | 107 | end_regime = form.get("end-regime", [None])[0] |
paul@294 | 108 | |
paul@295 | 109 | if not start_regime: |
paul@295 | 110 | start_regime = Location(location, locations).getTimeRegime() |
paul@295 | 111 | end_regime = end_regime or start_regime |
paul@294 | 112 | |
paul@99 | 113 | # Initialise regime lists. |
paul@99 | 114 | |
paul@295 | 115 | start_regime_list = [] |
paul@295 | 116 | start_regime_list.append('<option value="">%s</option>' % escape(_("<The event location (if known)>"))) |
paul@295 | 117 | end_regime_list = [] |
paul@295 | 118 | end_regime_list.append('<option value="">%s</option>' % escape(_("<Same as start time>"))) |
paul@99 | 119 | |
paul@99 | 120 | # Prepare regime lists, selecting specified regimes. |
paul@99 | 121 | |
paul@99 | 122 | if pytz is not None: |
paul@295 | 123 | start_regime_list += self.get_option_list(start_regime, pytz.common_timezones) |
paul@295 | 124 | end_regime_list += self.get_option_list(end_regime, pytz.common_timezones) |
paul@294 | 125 | |
paul@294 | 126 | # Show time zone-related information depending on various fields. |
paul@294 | 127 | |
paul@294 | 128 | show_zone_regime = ( |
paul@295 | 129 | form.get("start-regime") # have a regime |
paul@294 | 130 | and not form.get("show-offsets") # are not switching to offsets |
paul@294 | 131 | and not form.get("hide-zone") # are not removing zone information |
paul@294 | 132 | or form.get("show-regime") # are switching to a regime |
paul@295 | 133 | or form.get("show-times") and start_regime # are showing times with a regime |
paul@294 | 134 | ) |
paul@294 | 135 | show_zone_offsets = ( |
paul@294 | 136 | form.get("start-offset") # have an offset |
paul@294 | 137 | and not form.get("show-regime") # are not switching to a regime |
paul@294 | 138 | and not form.get("hide-zone") # are not removing zone information |
paul@294 | 139 | or form.get("show-offsets") # are switching to offsets |
paul@294 | 140 | ) |
paul@294 | 141 | |
paul@294 | 142 | show_zones = show_zone_regime or show_zone_offsets |
paul@99 | 143 | |
paul@49 | 144 | # Permitting configuration of the template name. |
paul@49 | 145 | |
paul@49 | 146 | template_default = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate") |
paul@49 | 147 | |
paul@329 | 148 | # Help page location. |
paul@329 | 149 | |
paul@329 | 150 | help_page_name = getattr(request.cfg, "event_aggregator_new_event_help", "HelpOnEventAggregatorNewEvent") |
paul@329 | 151 | help_page_url = Page(request, help_page_name).url(request) |
paul@329 | 152 | |
paul@329 | 153 | # Substitution of parameters. |
paul@329 | 154 | |
paul@46 | 155 | d = { |
paul@49 | 156 | "buttons_html" : buttons_html, |
paul@239 | 157 | "form_trigger" : escattr(self.form_trigger), |
paul@239 | 158 | "form_cancel" : escattr(self.form_cancel), |
paul@239 | 159 | |
paul@137 | 160 | "category_label" : escape(_("Categories")), |
paul@49 | 161 | "category_list" : "\n".join(category_list), |
paul@96 | 162 | |
paul@49 | 163 | "start_month_list" : "\n".join(start_month_list), |
paul@99 | 164 | "end_month_list" : "\n".join(end_month_list), |
paul@99 | 165 | |
paul@295 | 166 | "start_regime_list" : "\n".join(start_regime_list), |
paul@295 | 167 | "end_regime_list" : "\n".join(end_regime_list), |
paul@294 | 168 | "use_regime_label" : escape(_("Using local time in...")), |
paul@96 | 169 | |
paul@137 | 170 | "show_end_date_label" : escape(_("Specify end date")), |
paul@137 | 171 | "hide_end_date_label" : escape(_("End event on same day")), |
paul@99 | 172 | |
paul@137 | 173 | "show_times_label" : escape(_("Specify times")), |
paul@137 | 174 | "hide_times_label" : escape(_("No start and end times")), |
paul@99 | 175 | |
paul@137 | 176 | "show_offsets_label" : escape(_("Specify UTC offsets")), |
paul@294 | 177 | "show_regime_label" : escape(_("Use local time")), |
paul@137 | 178 | "hide_zone_label" : escape(_("Make times apply everywhere")), |
paul@96 | 179 | |
paul@137 | 180 | "start_label" : escape(_("Start date (day, month, year)")), |
paul@137 | 181 | "start_day_default" : escattr(form.get("start-day", [""])[0]), |
paul@148 | 182 | "start_year_default" : escattr(start_year_default), |
paul@137 | 183 | "start_time_label" : escape(_("Start time (hour, minute, second)")), |
paul@137 | 184 | "start_hour_default" : escattr(form.get("start-hour", [""])[0]), |
paul@137 | 185 | "start_minute_default" : escattr(form.get("start-minute", [""])[0]), |
paul@137 | 186 | "start_second_default" : escattr(form.get("start-second", [""])[0]), |
paul@137 | 187 | "start_offset_default" : escattr(form.get("start-offset", [""])[0]), |
paul@96 | 188 | |
paul@137 | 189 | "end_label" : escape(_("End date (day, month, year) - if different")), |
paul@243 | 190 | "end_day_default" : escattr(form.get("end-day", [""])[0].strip() or form.get("start-day", [""])[0]), |
paul@148 | 191 | "end_year_default" : escattr(end_year_default), |
paul@137 | 192 | "end_time_label" : escape(_("End time (hour, minute, second)")), |
paul@137 | 193 | "end_hour_default" : escattr(form.get("end-hour", [""])[0]), |
paul@137 | 194 | "end_minute_default" : escattr(form.get("end-minute", [""])[0]), |
paul@137 | 195 | "end_second_default" : escattr(form.get("end-second", [""])[0]), |
paul@243 | 196 | "end_offset_default" : escattr(form.get("end-offset", [""])[0].strip() or form.get("start-offset", [""])[0]), |
paul@96 | 197 | |
paul@137 | 198 | "title_label" : escape(_("Event title/summary")), |
paul@137 | 199 | "title_default" : escattr(form.get("title", [""])[0]), |
paul@327 | 200 | "choose_page_name_label": escape(_("Choose page name")), |
paul@327 | 201 | "auto_page_name_label" : escape(_("Auto page name")), |
paul@327 | 202 | "page_name_label" : escape(_("Page name")), |
paul@327 | 203 | "page_name_default" : escattr(form.get("page-name", [page_name])[0]), |
paul@137 | 204 | "description_label" : escape(_("Event description")), |
paul@137 | 205 | "description_default" : escattr(form.get("description", [""])[0]), |
paul@294 | 206 | |
paul@137 | 207 | "location_label" : escape(_("Event location")), |
paul@294 | 208 | "locations_list" : "\n".join(locations_list), |
paul@294 | 209 | "show_location_label" : escattr(_("Specify a different location")), |
paul@294 | 210 | "hide_location_label" : escattr(_("Choose a known location")), |
paul@294 | 211 | "new_location" : escattr(form.get("new-location", [location])[0]), |
paul@294 | 212 | |
paul@230 | 213 | "latitude_label" : escape(_("Latitude")), |
paul@230 | 214 | "latitude_default" : escattr(form.get("latitude", [""])[0]), |
paul@230 | 215 | "longitude_label" : escape(_("Longitude")), |
paul@230 | 216 | "longitude_default" : escattr(form.get("longitude", [""])[0]), |
paul@243 | 217 | "link_label" : escape(_("External URL")), |
paul@137 | 218 | "link_default" : escattr(form.get("link", [""])[0]), |
paul@96 | 219 | |
paul@137 | 220 | "topics_label" : escape(_("Topics")), |
paul@137 | 221 | "add_topic_label" : escape(_("Add topic")), |
paul@137 | 222 | "remove_topic_label" : escape(_("Remove topic")), |
paul@96 | 223 | |
paul@137 | 224 | "template_label" : escape(_("Event template")), |
paul@243 | 225 | "template_default" : escattr(form.get("template", [""])[0].strip() or template_default), |
paul@137 | 226 | "parent_label" : escape(_("Parent page")), |
paul@137 | 227 | "parent_default" : escattr(form.get("parent", [""])[0]), |
paul@96 | 228 | |
paul@137 | 229 | "advanced_label" : escape(_("Show advanced options")), |
paul@137 | 230 | "basic_label" : escape(_("Hide advanced options")), |
paul@329 | 231 | |
paul@329 | 232 | "help_page_url" : escattr(help_page_url), |
paul@329 | 233 | "help_page_label" : escape(_("Help on creating events")), |
paul@46 | 234 | } |
paul@46 | 235 | |
paul@73 | 236 | # Prepare the output HTML. |
paul@73 | 237 | |
paul@73 | 238 | html = ''' |
paul@238 | 239 | <input name="update-form-only" value="false" type="hidden" /> |
paul@46 | 240 | <table> |
paul@46 | 241 | <tr> |
paul@46 | 242 | <td class="label"><label>%(title_label)s</label></td> |
paul@99 | 243 | <td colspan="2"> |
paul@48 | 244 | <input name="title" type="text" size="40" value="%(title_default)s" /> |
paul@48 | 245 | </td> |
paul@294 | 246 | </tr>''' % d |
paul@294 | 247 | |
paul@327 | 248 | # Page name options. |
paul@327 | 249 | |
paul@327 | 250 | if choose_page_name: |
paul@327 | 251 | html += ''' |
paul@327 | 252 | <tr> |
paul@327 | 253 | <td class="label"><label>%(page_name_label)s</label></td> |
paul@327 | 254 | <td colspan="2"> |
paul@327 | 255 | <input name="page-name" type="text" size="40" value="%(page_name_default)s" /> |
paul@327 | 256 | </td> |
paul@327 | 257 | <tr> |
paul@327 | 258 | <td class="label"> |
paul@327 | 259 | <input name="auto-page-name" type="submit" value="%(auto_page_name_label)s" /> |
paul@327 | 260 | </td> |
paul@327 | 261 | </tr>''' % d |
paul@327 | 262 | else: |
paul@327 | 263 | html += ''' |
paul@327 | 264 | <tr> |
paul@327 | 265 | <td class="label"> |
paul@327 | 266 | <input name="choose-page-name" type="submit" value="%(choose_page_name_label)s" /> |
paul@327 | 267 | </td> |
paul@327 | 268 | </tr>''' % d |
paul@327 | 269 | |
paul@294 | 270 | # Location options. |
paul@294 | 271 | |
paul@294 | 272 | html += ''' |
paul@294 | 273 | <tr> |
paul@294 | 274 | <td class="label"><label>%(location_label)s</label></td> |
paul@294 | 275 | <td colspan="2">''' % d |
paul@294 | 276 | |
paul@294 | 277 | if not show_location: |
paul@294 | 278 | html += ''' |
paul@294 | 279 | <select name="location"> |
paul@294 | 280 | %(locations_list)s |
paul@294 | 281 | </select> |
paul@294 | 282 | <input name="show-location" type="submit" value="%(show_location_label)s" />''' % d |
paul@294 | 283 | |
paul@294 | 284 | else: |
paul@294 | 285 | html += ''' |
paul@294 | 286 | <input name="new-location" type="text" size="30" value="%(new_location)s" /> |
paul@294 | 287 | <input name="hide-location" type="submit" value="%(hide_location_label)s" />''' % d |
paul@294 | 288 | |
paul@294 | 289 | html += ''' |
paul@294 | 290 | </td> |
paul@294 | 291 | </tr>''' % d |
paul@294 | 292 | |
paul@294 | 293 | # Latitude and longitude. |
paul@294 | 294 | |
paul@294 | 295 | if show_location: |
paul@294 | 296 | html += ''' |
paul@294 | 297 | <tr> |
paul@294 | 298 | <td class="label"><label>%(latitude_label)s</label></td> |
paul@294 | 299 | <td colspan="2"> |
paul@294 | 300 | <input name="latitude" type="text" size="40" value="%(latitude_default)s" /> |
paul@294 | 301 | </td> |
paul@48 | 302 | </tr> |
paul@46 | 303 | <tr> |
paul@294 | 304 | <td class="label"><label>%(longitude_label)s</label></td> |
paul@294 | 305 | <td colspan="2"> |
paul@294 | 306 | <input name="longitude" type="text" size="40" value="%(longitude_default)s" /> |
paul@294 | 307 | </td> |
paul@294 | 308 | </tr>''' % d |
paul@294 | 309 | |
paul@294 | 310 | # Start date controls. |
paul@294 | 311 | |
paul@294 | 312 | html += ''' |
paul@294 | 313 | <tr> |
paul@46 | 314 | <td class="label"><label>%(start_label)s</label></td> |
paul@99 | 315 | <td colspan="2" style="white-space: nowrap"> |
paul@46 | 316 | <input name="start-day" type="text" value="%(start_day_default)s" size="2" /> |
paul@46 | 317 | <select name="start-month"> |
paul@46 | 318 | %(start_month_list)s |
paul@46 | 319 | </select> |
paul@46 | 320 | <input name="start-year" type="text" value="%(start_year_default)s" size="4" /> |
paul@46 | 321 | </td> |
paul@99 | 322 | </tr>''' % d |
paul@99 | 323 | |
paul@99 | 324 | # End date controls. |
paul@99 | 325 | |
paul@99 | 326 | if show_end_date: |
paul@99 | 327 | html += ''' |
paul@96 | 328 | <tr> |
paul@46 | 329 | <td class="label"><label>%(end_label)s</label></td> |
paul@99 | 330 | <td colspan="2" style="white-space: nowrap"> |
paul@46 | 331 | <input name="end-day" type="text" value="%(end_day_default)s" size="2" /> |
paul@46 | 332 | <select name="end-month"> |
paul@46 | 333 | %(end_month_list)s |
paul@46 | 334 | </select> |
paul@46 | 335 | <input name="end-year" type="text" value="%(end_year_default)s" size="4" /> |
paul@46 | 336 | </td> |
paul@46 | 337 | </tr> |
paul@46 | 338 | <tr> |
paul@99 | 339 | <td class="label"> |
paul@99 | 340 | <input name="hide-end-date" type="submit" value="%(hide_end_date_label)s" /> |
paul@99 | 341 | </td> |
paul@99 | 342 | </tr>''' % d |
paul@99 | 343 | else: |
paul@99 | 344 | html += ''' |
paul@99 | 345 | <tr> |
paul@99 | 346 | <td class="label"> |
paul@99 | 347 | <input name="show-end-date" type="submit" value="%(show_end_date_label)s" /> |
paul@99 | 348 | </td> |
paul@99 | 349 | </tr>''' % d |
paul@99 | 350 | |
paul@99 | 351 | # Generic time information. |
paul@99 | 352 | |
paul@99 | 353 | if show_times: |
paul@99 | 354 | |
paul@99 | 355 | # Start time controls. |
paul@99 | 356 | |
paul@99 | 357 | html += ''' |
paul@99 | 358 | <tr> |
paul@295 | 359 | <td class="label event-time-selection"><label>%(start_time_label)s</label></td> |
paul@295 | 360 | <td style="white-space: nowrap" class="event-time-selection"> |
paul@99 | 361 | <input name="start-hour" type="text" value="%(start_hour_default)s" size="2" maxlength="2" /> |
paul@99 | 362 | <input name="start-minute" type="text" value="%(start_minute_default)s" size="2" maxlength="2" /> |
paul@99 | 363 | <input name="start-second" type="text" value="%(start_second_default)s" size="2" maxlength="2" /> |
paul@99 | 364 | </td>''' % d |
paul@99 | 365 | |
paul@99 | 366 | # Offset information displayed. |
paul@99 | 367 | |
paul@99 | 368 | if show_zone_offsets: |
paul@99 | 369 | html += ''' |
paul@295 | 370 | <td class="event-zone-selection"> |
paul@99 | 371 | UTC <input name="start-offset" type="text" value="%(start_offset_default)s" size="6" maxlength="6" /> |
paul@99 | 372 | </td>''' % d |
paul@99 | 373 | |
paul@99 | 374 | # Regime information displayed. |
paul@99 | 375 | |
paul@99 | 376 | elif show_zone_regime: |
paul@99 | 377 | html += ''' |
paul@295 | 378 | <td class="event-regime-selection"> |
paul@294 | 379 | <label>%(use_regime_label)s</label><br/> |
paul@295 | 380 | <select name="start-regime"> |
paul@295 | 381 | %(start_regime_list)s |
paul@294 | 382 | </select> |
paul@99 | 383 | </td>''' % d |
paul@99 | 384 | |
paul@99 | 385 | html += ''' |
paul@99 | 386 | </tr>''' |
paul@99 | 387 | |
paul@99 | 388 | # End time controls. |
paul@99 | 389 | |
paul@99 | 390 | html += ''' |
paul@99 | 391 | <tr> |
paul@295 | 392 | <td class="label event-time-selection"><label>%(end_time_label)s</label></td> |
paul@295 | 393 | <td style="white-space: nowrap" class="event-time-selection"> |
paul@99 | 394 | <input name="end-hour" type="text" value="%(end_hour_default)s" size="2" maxlength="2" /> |
paul@99 | 395 | <input name="end-minute" type="text" value="%(end_minute_default)s" size="2" maxlength="2" /> |
paul@99 | 396 | <input name="end-second" type="text" value="%(end_second_default)s" size="2" maxlength="2" /> |
paul@99 | 397 | </td>''' % d |
paul@99 | 398 | |
paul@99 | 399 | # Offset information displayed. |
paul@99 | 400 | |
paul@99 | 401 | if show_zone_offsets: |
paul@99 | 402 | html += ''' |
paul@295 | 403 | <td class="event-zone-selection"> |
paul@99 | 404 | UTC <input name="end-offset" type="text" value="%(end_offset_default)s" size="6" maxlength="6" /> |
paul@99 | 405 | </td>''' % d |
paul@99 | 406 | |
paul@295 | 407 | # Regime information displayed. |
paul@295 | 408 | |
paul@295 | 409 | elif show_zone_regime: |
paul@295 | 410 | html += ''' |
paul@295 | 411 | <td class="event-regime-selection event-end-time"> |
paul@295 | 412 | <select name="end-regime"> |
paul@295 | 413 | %(end_regime_list)s |
paul@295 | 414 | </select> |
paul@295 | 415 | </td>''' % d |
paul@295 | 416 | |
paul@99 | 417 | # Controls for removing times. |
paul@99 | 418 | |
paul@99 | 419 | html += ''' |
paul@96 | 420 | </tr> |
paul@96 | 421 | <tr> |
paul@99 | 422 | <td class="label"> |
paul@99 | 423 | <input name="hide-times" type="submit" value="%(hide_times_label)s" /> |
paul@99 | 424 | </td> |
paul@294 | 425 | <td></td> |
paul@294 | 426 | <td>''' % d |
paul@99 | 427 | |
paul@99 | 428 | # Time zone controls. |
paul@99 | 429 | |
paul@99 | 430 | if show_zones: |
paul@99 | 431 | |
paul@99 | 432 | # To remove zone information. |
paul@99 | 433 | |
paul@99 | 434 | html += ''' |
paul@294 | 435 | <input name="hide-zone" type="submit" value="%(hide_zone_label)s" />''' % d |
paul@99 | 436 | |
paul@99 | 437 | # No time zone information shown. |
paul@99 | 438 | |
paul@99 | 439 | else: |
paul@99 | 440 | html += ''' |
paul@99 | 441 | <input name="show-regime" type="submit" value="%(show_regime_label)s" /> |
paul@294 | 442 | <input name="show-offsets" type="submit" value="%(show_offsets_label)s" />''' % d |
paul@99 | 443 | |
paul@99 | 444 | html += ''' |
paul@294 | 445 | </td> |
paul@99 | 446 | </tr>''' |
paul@99 | 447 | |
paul@99 | 448 | # Controls for adding times. |
paul@99 | 449 | |
paul@99 | 450 | else: |
paul@99 | 451 | html += ''' |
paul@99 | 452 | <tr> |
paul@99 | 453 | <td class="label"> |
paul@99 | 454 | <input name="show-times" type="submit" value="%(show_times_label)s" /> |
paul@99 | 455 | </td> |
paul@99 | 456 | </tr>''' % d |
paul@99 | 457 | |
paul@99 | 458 | |
paul@99 | 459 | # Various basic controls. |
paul@99 | 460 | |
paul@99 | 461 | html += ''' |
paul@99 | 462 | <tr> |
paul@49 | 463 | <td class="label"><label>%(description_label)s</label></td> |
paul@99 | 464 | <td colspan="2"> |
paul@49 | 465 | <input name="description" type="text" size="40" value="%(description_default)s" /> |
paul@49 | 466 | </td> |
paul@92 | 467 | </tr> |
paul@92 | 468 | <tr> |
paul@92 | 469 | <td class="label"><label>%(link_label)s</label></td> |
paul@99 | 470 | <td colspan="2"> |
paul@92 | 471 | <input name="link" type="text" size="40" value="%(link_default)s" /> |
paul@92 | 472 | </td> |
paul@73 | 473 | </tr>''' % d |
paul@73 | 474 | |
paul@92 | 475 | # Topics. |
paul@92 | 476 | |
paul@92 | 477 | for i, topic in enumerate(topics): |
paul@137 | 478 | d["topic"] = escattr(topic) |
paul@92 | 479 | d["topic_number"] = i |
paul@92 | 480 | html += ''' |
paul@92 | 481 | <tr> |
paul@92 | 482 | <td class="label"><label>%(topics_label)s</label></td> |
paul@99 | 483 | <td colspan="2"> |
paul@92 | 484 | <input name="topics" type="text" size="20" value="%(topic)s" /> |
paul@92 | 485 | <input name="remove-topic-%(topic_number)s" type="submit" value="%(remove_topic_label)s" /> |
paul@92 | 486 | </td> |
paul@92 | 487 | </tr>''' % d |
paul@92 | 488 | |
paul@92 | 489 | html += ''' |
paul@92 | 490 | <tr> |
paul@92 | 491 | <td></td> |
paul@99 | 492 | <td colspan="2"> |
paul@92 | 493 | <input name="add-topic" type="submit" value="%(add_topic_label)s" /> |
paul@92 | 494 | </td> |
paul@92 | 495 | </tr>''' % d |
paul@92 | 496 | |
paul@92 | 497 | # Advanced options. |
paul@92 | 498 | |
paul@73 | 499 | if show_advanced: |
paul@73 | 500 | html += ''' |
paul@73 | 501 | <tr> |
paul@73 | 502 | <td></td> |
paul@99 | 503 | <td colspan="2"> |
paul@73 | 504 | <input name="basic" type="submit" value="%(basic_label)s" /> |
paul@73 | 505 | <input name="advanced" type="hidden" value="true" /> |
paul@73 | 506 | </td> |
paul@73 | 507 | </tr> |
paul@73 | 508 | <tr> |
paul@73 | 509 | <td class="label"><label>%(category_label)s</label></td> |
paul@99 | 510 | <td colspan="2" class="content"> |
paul@73 | 511 | <select multiple="multiple" name="category"> |
paul@73 | 512 | %(category_list)s |
paul@73 | 513 | </select> |
paul@73 | 514 | </td> |
paul@49 | 515 | </tr> |
paul@49 | 516 | <tr> |
paul@49 | 517 | <td class="label"><label>%(template_label)s</label></td> |
paul@99 | 518 | <td colspan="2"> |
paul@49 | 519 | <input name="template" type="text" size="40" value="%(template_default)s" /> |
paul@49 | 520 | </td> |
paul@49 | 521 | </tr> |
paul@49 | 522 | <tr> |
paul@55 | 523 | <td class="label"><label>%(parent_label)s</label></td> |
paul@99 | 524 | <td colspan="2"> |
paul@55 | 525 | <input name="parent" type="text" size="40" value="%(parent_default)s" /> |
paul@55 | 526 | </td> |
paul@55 | 527 | </tr> |
paul@55 | 528 | <tr> |
paul@46 | 529 | <td></td> |
paul@99 | 530 | <td colspan="2" class="buttons"> |
paul@46 | 531 | %(buttons_html)s |
paul@46 | 532 | </td> |
paul@46 | 533 | </tr> |
paul@73 | 534 | </table>''' % d |
paul@73 | 535 | else: |
paul@73 | 536 | html += ''' |
paul@73 | 537 | <tr> |
paul@73 | 538 | <td></td> |
paul@99 | 539 | <td colspan="2"> |
paul@73 | 540 | <input name="advanced" type="submit" value="%(advanced_label)s" /> |
paul@73 | 541 | %(category_list)s |
paul@73 | 542 | <input name="parent" type="hidden" value="%(parent_default)s" /> |
paul@73 | 543 | <input name="template" type="hidden" value="%(template_default)s" /> |
paul@73 | 544 | </td> |
paul@73 | 545 | </tr> |
paul@73 | 546 | <tr> |
paul@73 | 547 | <td></td> |
paul@99 | 548 | <td colspan="2" class="buttons"> |
paul@73 | 549 | %(buttons_html)s |
paul@73 | 550 | </td> |
paul@73 | 551 | </tr> |
paul@329 | 552 | <tr> |
paul@329 | 553 | <td></td> |
paul@329 | 554 | <td colspan="2"> |
paul@329 | 555 | <a href="%(help_page_url)s" target="_blank">%(help_page_label)s</a> |
paul@329 | 556 | </td> |
paul@329 | 557 | </tr> |
paul@238 | 558 | </table> |
paul@238 | 559 | <script type="text/javascript"> |
paul@238 | 560 | function replaceDialog(url, button) { |
paul@238 | 561 | var form = findForm(); |
paul@238 | 562 | var dialog = findDialog(document); |
paul@238 | 563 | if (form != null && dialog != null) { |
paul@238 | 564 | var xmlhttp = new XMLHttpRequest(); |
paul@238 | 565 | xmlhttp.open("POST", url, false); |
paul@238 | 566 | xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
paul@238 | 567 | |
paul@238 | 568 | var requestBody = encodeURIComponent(button.name) + "=" + encodeURIComponent(button.value); |
paul@238 | 569 | for (var i = 0; i < form.elements.length; i++) { |
paul@238 | 570 | var element = form.elements[i]; |
paul@238 | 571 | if (element.type != "submit") { |
paul@238 | 572 | requestBody += "&" + encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value); |
paul@238 | 573 | } |
paul@238 | 574 | } |
paul@238 | 575 | xmlhttp.send(requestBody); |
paul@238 | 576 | |
paul@238 | 577 | var newDialog = xmlhttp.responseText; |
paul@238 | 578 | |
paul@238 | 579 | if (newDialog != null) { |
paul@238 | 580 | dialog.parentNode.innerHTML = newDialog; |
paul@238 | 581 | initForm(); |
paul@238 | 582 | return false; |
paul@238 | 583 | } |
paul@238 | 584 | } |
paul@238 | 585 | } |
paul@238 | 586 | |
paul@238 | 587 | function findDialog(d) { |
paul@238 | 588 | var elements = d.getElementsByTagName("div"); |
paul@238 | 589 | for (var i = 0; i < elements.length; i++) { |
paul@238 | 590 | var element = elements[i]; |
paul@238 | 591 | var cls = element.getAttribute("class"); |
paul@238 | 592 | if (cls == "dialog") { |
paul@238 | 593 | return element; |
paul@238 | 594 | } |
paul@238 | 595 | } |
paul@238 | 596 | return null; |
paul@238 | 597 | } |
paul@238 | 598 | |
paul@238 | 599 | function findForm() { |
paul@238 | 600 | for (var i = 0; i < document.forms.length; i++) { |
paul@238 | 601 | var form = document.forms[i]; |
paul@238 | 602 | if (form["update-form-only"] != null) { |
paul@238 | 603 | return form; |
paul@238 | 604 | } |
paul@238 | 605 | } |
paul@238 | 606 | return null; |
paul@238 | 607 | } |
paul@238 | 608 | |
paul@238 | 609 | function initForm() { |
paul@238 | 610 | var form = findForm(); |
paul@238 | 611 | var url = form.getAttribute("action"); |
paul@238 | 612 | form["update-form-only"].value = "true"; |
paul@238 | 613 | for (var i = 0; i < form.length; i++) { |
paul@238 | 614 | var element = form[i]; |
paul@239 | 615 | if (element.type == "submit" && element.name != "%(form_trigger)s" && element.name != "%(form_cancel)s") { |
paul@238 | 616 | element.setAttribute("onclick", "return replaceDialog('" + url + "', this);"); |
paul@238 | 617 | } |
paul@238 | 618 | } |
paul@238 | 619 | } |
paul@238 | 620 | |
paul@238 | 621 | initForm(); |
paul@238 | 622 | </script>''' % d |
paul@73 | 623 | |
paul@73 | 624 | return html |
paul@46 | 625 | |
paul@46 | 626 | def do_action(self): |
paul@46 | 627 | |
paul@46 | 628 | "Create the new event." |
paul@46 | 629 | |
paul@46 | 630 | _ = self._ |
paul@109 | 631 | form = self.get_form() |
paul@46 | 632 | |
paul@46 | 633 | # If no title exists in the request, an error message is returned. |
paul@46 | 634 | |
paul@46 | 635 | title = form.get("title", [None])[0] |
paul@49 | 636 | template = form.get("template", [None])[0] |
paul@46 | 637 | |
paul@46 | 638 | if not title: |
paul@46 | 639 | return 0, _("No event title specified.") |
paul@46 | 640 | |
paul@49 | 641 | if not template: |
paul@49 | 642 | return 0, _("No page template specified.") |
paul@49 | 643 | |
paul@46 | 644 | return self.create_event(self.request) |
paul@46 | 645 | |
paul@238 | 646 | def render_msg(self, msg, msgtype): |
paul@238 | 647 | |
paul@238 | 648 | """ |
paul@238 | 649 | Render 'msg' and 'msgtype'. If 'msgtype' is "dialog" then the form is |
paul@238 | 650 | rendered, and if only part of the form is being requested, the output |
paul@238 | 651 | will be only the form HTML fragment and not the entire page. |
paul@238 | 652 | """ |
paul@238 | 653 | |
paul@238 | 654 | # Either render the form as a fragment of a page. |
paul@238 | 655 | |
paul@243 | 656 | form = self.get_form() |
paul@243 | 657 | update_form_only = form.get("update-form-only", ["false"])[0] == "true" |
paul@243 | 658 | action_attempted = form.has_key(self.form_trigger) |
paul@243 | 659 | |
paul@243 | 660 | if msgtype == "dialog" and update_form_only and not action_attempted: |
paul@238 | 661 | send_headers = get_send_headers(self.request) |
paul@238 | 662 | send_headers(["Content-Type: text/html; charset=%s" % config.charset]) |
paul@238 | 663 | self.request.write(msg.render()) |
paul@238 | 664 | |
paul@238 | 665 | # Or render the message/form within an entire page. |
paul@238 | 666 | |
paul@238 | 667 | else: |
paul@238 | 668 | ActionBase.render_msg(self, msg, msgtype) |
paul@238 | 669 | |
paul@238 | 670 | def render_success(self, msg, msgtype): |
paul@46 | 671 | |
paul@46 | 672 | """ |
paul@46 | 673 | Render neither 'msg' nor 'msgtype' since redirection should occur |
paul@46 | 674 | instead. |
paul@46 | 675 | """ |
paul@46 | 676 | |
paul@46 | 677 | pass |
paul@46 | 678 | |
paul@46 | 679 | def create_event(self, request): |
paul@46 | 680 | |
paul@46 | 681 | "Create an event page using the 'request'." |
paul@46 | 682 | |
paul@46 | 683 | _ = request.getText |
paul@109 | 684 | form = self.get_form() |
paul@46 | 685 | |
paul@48 | 686 | category_pagenames = form.get("category", []) |
paul@49 | 687 | description = form.get("description", [None])[0] |
paul@304 | 688 | location = (form.get("location") or form.get("new-location") or [""])[0] |
paul@230 | 689 | latitude = form.get("latitude", [None])[0] |
paul@230 | 690 | longitude = form.get("longitude", [None])[0] |
paul@92 | 691 | link = form.get("link", [None])[0] |
paul@92 | 692 | topics = form.get("topics", []) |
paul@92 | 693 | |
paul@295 | 694 | start_regime = form.get("start-regime", [None])[0] |
paul@295 | 695 | end_regime = form.get("end-regime", form.get("start-regime", [None]))[0] |
paul@99 | 696 | start_offset = form.get("start-offset", [None])[0] |
paul@99 | 697 | end_offset = form.get("end-offset", [None])[0] |
paul@99 | 698 | |
paul@295 | 699 | start_zone = start_regime or start_offset |
paul@295 | 700 | end_zone = end_regime or end_offset |
paul@96 | 701 | |
paul@327 | 702 | page_name = form.get("page-name", [None])[0] |
paul@327 | 703 | |
paul@92 | 704 | # Validate certain fields. |
paul@46 | 705 | |
paul@243 | 706 | title = form.get("title", [""])[0].strip() |
paul@243 | 707 | template = form.get("template", [""])[0].strip() |
paul@243 | 708 | parent = form.get("parent", [""])[0].strip() |
paul@243 | 709 | |
paul@243 | 710 | if not title: |
paul@243 | 711 | return 0, _("No event title specified.") |
paul@243 | 712 | if not template: |
paul@243 | 713 | return 0, _("No event template specified.") |
paul@49 | 714 | |
paul@96 | 715 | try: |
paul@97 | 716 | start_day = self._get_input(form, "start-day") |
paul@97 | 717 | start_month = self._get_input(form, "start-month") |
paul@97 | 718 | start_year = self._get_input(form, "start-year") |
paul@97 | 719 | |
paul@97 | 720 | if not start_day or not start_month or not start_year: |
paul@97 | 721 | return 0, _("A start date must be specified.") |
paul@97 | 722 | |
paul@48 | 723 | end_day = self._get_input(form, "end-day", start_day) |
paul@48 | 724 | end_month = self._get_input(form, "end-month", start_month) |
paul@48 | 725 | end_year = self._get_input(form, "end-year", start_year) |
paul@46 | 726 | |
paul@48 | 727 | except (TypeError, ValueError): |
paul@46 | 728 | return 0, _("Days and years must be numbers yielding a valid date!") |
paul@46 | 729 | |
paul@96 | 730 | try: |
paul@96 | 731 | start_hour = self._get_input(form, "start-hour") |
paul@96 | 732 | start_minute = self._get_input(form, "start-minute") |
paul@96 | 733 | start_second = self._get_input(form, "start-second") |
paul@96 | 734 | |
paul@96 | 735 | end_hour = self._get_input(form, "end-hour") |
paul@96 | 736 | end_minute = self._get_input(form, "end-minute") |
paul@96 | 737 | end_second = self._get_input(form, "end-second") |
paul@49 | 738 | |
paul@96 | 739 | except (TypeError, ValueError): |
paul@96 | 740 | return 0, _("Hours, minutes and seconds must be numbers yielding a valid time!") |
paul@96 | 741 | |
paul@168 | 742 | start_date = DateTime( |
paul@96 | 743 | (start_year, start_month, start_day, start_hour, start_minute, start_second, start_zone) |
paul@96 | 744 | ) |
paul@96 | 745 | start_date.constrain() |
paul@96 | 746 | |
paul@168 | 747 | end_date = DateTime( |
paul@96 | 748 | (end_year, end_month, end_day, end_hour, end_minute, end_second, end_zone) |
paul@96 | 749 | ) |
paul@96 | 750 | end_date.constrain() |
paul@46 | 751 | |
paul@78 | 752 | # An elementary date ordering check. |
paul@78 | 753 | |
paul@96 | 754 | 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 | 755 | start_date, end_date = end_date, start_date |
paul@78 | 756 | |
paul@88 | 757 | event_details = { |
paul@96 | 758 | "start" : str(start_date), "end" : str(end_date), |
paul@88 | 759 | "title" : title, "summary" : title, |
paul@92 | 760 | "description" : description, "location" : location, "link" : link, |
paul@92 | 761 | "topics" : [topic for topic in topics if topic] |
paul@88 | 762 | } |
paul@88 | 763 | |
paul@230 | 764 | if latitude and longitude: |
paul@230 | 765 | event_details["geo"] = latitude, longitude |
paul@230 | 766 | |
paul@46 | 767 | # Copy the template. |
paul@49 | 768 | |
paul@88 | 769 | template_page = PageEditor(request, template) |
paul@46 | 770 | |
paul@88 | 771 | if not template_page.exists(): |
paul@49 | 772 | return 0, _("Event template not available.") |
paul@49 | 773 | |
paul@55 | 774 | # Use any parent page information. |
paul@55 | 775 | |
paul@168 | 776 | full_title = getFullPageName(parent, title) |
paul@55 | 777 | |
paul@327 | 778 | if page_name: |
paul@327 | 779 | |
paul@327 | 780 | # Allow parameters in the page name. This permits a degree of |
paul@327 | 781 | # interoperability with MonthCalendar. |
paul@327 | 782 | |
paul@327 | 783 | page_name = page_name.replace("@PAGE@", request.page.page_name) |
paul@327 | 784 | page_name = page_name.replace("@DATE@", str(start_date.as_date())) |
paul@327 | 785 | page_name = page_name.replace("@STARTDATE@", str(start_date.as_date())) |
paul@327 | 786 | page_name = page_name.replace("@ENDDATE@", str(end_date.as_date())) |
paul@327 | 787 | page_name = page_name.replace("@PARENT@", parent) |
paul@327 | 788 | page_name = page_name.replace("@TITLE@", title) |
paul@327 | 789 | |
paul@327 | 790 | # Normalise any page hierarchy separators. |
paul@327 | 791 | |
paul@327 | 792 | page_name = re.sub("/+", "/", page_name) |
paul@327 | 793 | |
paul@327 | 794 | else: |
paul@327 | 795 | page_name = full_title |
paul@327 | 796 | |
paul@47 | 797 | # Load the new page and replace the event details in the body. |
paul@46 | 798 | |
paul@327 | 799 | new_page = PageEditor(request, page_name) |
paul@46 | 800 | |
paul@46 | 801 | if new_page.exists(): |
paul@46 | 802 | return 0, _("The specified page already exists. Please choose another name.") |
paul@46 | 803 | |
paul@255 | 804 | # Complete the new page and return its body. |
paul@67 | 805 | |
paul@255 | 806 | body = fillEventPageFromTemplate(template_page, new_page, event_details, category_pagenames) |
paul@46 | 807 | |
paul@255 | 808 | # Open the page editor on the new page. |
paul@255 | 809 | # NOTE: Replacing the revision in the request to prevent Moin from |
paul@255 | 810 | # NOTE: attempting to use the queued changes page's revision. |
paul@255 | 811 | # NOTE: Replacing the action and page in the request to avoid issues |
paul@255 | 812 | # NOTE: with editing tickets. |
paul@46 | 813 | |
paul@255 | 814 | request.rev = 0 |
paul@255 | 815 | request.action = "edit" |
paul@255 | 816 | request.page = new_page |
paul@255 | 817 | new_page.sendEditor(preview=body, staytop=True) |
paul@255 | 818 | |
paul@255 | 819 | # Return success. |
paul@255 | 820 | |
paul@46 | 821 | return 1, None |
paul@46 | 822 | |
paul@46 | 823 | # Action function. |
paul@46 | 824 | |
paul@46 | 825 | def execute(pagename, request): |
paul@46 | 826 | EventAggregatorNewEvent(pagename, request).render() |
paul@46 | 827 | |
paul@46 | 828 | # vim: tabstop=4 expandtab shiftwidth=4 |