Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 8285:2bf0c4e7795e
fix: issue2551390 - Replace text input/calendar popup with native date input
Docs, code and test changes for the changeover to a native date
element.
See issue for details.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 18 Jan 2025 12:23:23 -0500 |
| parents | 669dfccca898 |
| children | 6445e63bb423 |
comparison
equal
deleted
inserted
replaced
| 8284:92dad05379f9 | 8285:2bf0c4e7795e |
|---|---|
| 2250 ret = ret - interval | 2250 ret = ret - interval |
| 2251 | 2251 |
| 2252 return DateHTMLProperty(self._client, self._classname, self._nodeid, | 2252 return DateHTMLProperty(self._client, self._classname, self._nodeid, |
| 2253 self._prop, self._formname, ret) | 2253 self._prop, self._formname, ret) |
| 2254 | 2254 |
| 2255 def field(self, size=30, default=None, format=_marker, popcal=True, | 2255 |
| 2256 def field_time(self, size=30, default=None, format=_marker, popcal=None, | |
| 2257 **kwargs): | |
| 2258 | |
| 2259 kwargs.setdefault("type", "datetime-local") | |
| 2260 field = self.field(size=size, default=default, format=format, | |
| 2261 popcal=popcal, **kwargs) | |
| 2262 return field | |
| 2263 | |
| 2264 def field(self, size=30, default=None, format=_marker, popcal=None, | |
| 2256 **kwargs): | 2265 **kwargs): |
| 2257 """Render a form edit field for the property | 2266 """Render a form edit field for the property |
| 2258 | 2267 |
| 2259 If not editable, just display the value via plain(). | 2268 If not editable, just display the value via plain(). |
| 2260 | 2269 |
| 2266 if not self.is_edit_ok(): | 2275 if not self.is_edit_ok(): |
| 2267 if format is self._marker: | 2276 if format is self._marker: |
| 2268 return self.plain(escape=1) | 2277 return self.plain(escape=1) |
| 2269 else: | 2278 else: |
| 2270 return self.pretty(format) | 2279 return self.pretty(format) |
| 2280 | |
| 2281 kwargs.setdefault("type", "date") | |
| 2282 | |
| 2283 if kwargs["type"] in ["date", "datetime-local"]: | |
| 2284 acceptable_formats = { | |
| 2285 "date": "%Y-%m-%d", | |
| 2286 "datetime-local": "%Y-%m-%dT%H:%M:%S" | |
| 2287 } | |
| 2288 | |
| 2289 if format is not self._marker: # user set format | |
| 2290 if format != acceptable_formats[kwargs["type"]]: | |
| 2291 # format is incompatible with date type | |
| 2292 kwargs['type'] = "text" | |
| 2293 if popcal is not False: | |
| 2294 popcal = True | |
| 2295 logger.warning(self._( | |
| 2296 "Format '%(format)s' prevents use of modern " | |
| 2297 "date input. Remove format from field() call in " | |
| 2298 "template %(class)s.%(template)s. " | |
| 2299 "Using text input.") % { | |
| 2300 "format": format, | |
| 2301 "class": self._client.classname, | |
| 2302 "template": self._client.template | |
| 2303 }) | |
| 2304 | |
| 2305 """ | |
| 2306 raise ValueError(self._( | |
| 2307 "When using input type of '%(field_type)s', the " | |
| 2308 "format must not be set, or must be " | |
| 2309 "'%(format_string)s' to match RFC3339 date " | |
| 2310 "or date-time. Current format is '%(format)s'.") % { | |
| 2311 "field_type": kwargs["type"], | |
| 2312 "format_string": | |
| 2313 acceptable_formats[kwargs["type"]], | |
| 2314 "format": format, | |
| 2315 })""" | |
| 2316 else: | |
| 2317 # https://developer.mozilla.org/en-US/docs/Web/HTML/Date_and_time_formats#local_date_and_time_strings | |
| 2318 # match date-time format in | |
| 2319 # https://www.rfc-editor.org/rfc/rfc3339 | |
| 2320 format = acceptable_formats[kwargs['type']] | |
| 2271 | 2321 |
| 2272 value = self._value | 2322 value = self._value |
| 2273 | 2323 |
| 2274 if value is None: | 2324 if value is None: |
| 2275 if default is None: | 2325 if default is None: |
