Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 5191:fe52cab8f5b5
issue2550932 - html_calendar produces templating errors for bad date strings
Changed code to trap and ignore unparsible dates. The calendar starts
with today highlighted.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 25 Feb 2017 22:21:15 -0500 |
| parents | 89b1870b1bc9 |
| children | 302e3a1a7190 |
comparison
equal
deleted
inserted
replaced
| 5190:89b1870b1bc9 | 5191:fe52cab8f5b5 |
|---|---|
| 3029 date_str = request.form.getfirst("date", current_date) | 3029 date_str = request.form.getfirst("date", current_date) |
| 3030 display = request.form.getfirst("display", date_str) | 3030 display = request.form.getfirst("display", date_str) |
| 3031 template = request.form.getfirst("@template", "calendar") | 3031 template = request.form.getfirst("@template", "calendar") |
| 3032 form = request.form.getfirst("form") | 3032 form = request.form.getfirst("form") |
| 3033 property = request.form.getfirst("property") | 3033 property = request.form.getfirst("property") |
| 3034 curr_date = date.Date(date_str) # to highlight | 3034 curr_date = "" |
| 3035 display = date.Date(display) # to show | 3035 try: |
| 3036 # date_str and display can be set to an invalid value | |
| 3037 # if user submits a value like "d4" and gets an edit error. | |
| 3038 # If either or both invalid just ignore that we can't parse it | |
| 3039 # and assign them to today. | |
| 3040 curr_date = date.Date(date_str) # to highlight | |
| 3041 display = date.Date(display) # to show | |
| 3042 except ValueError: | |
| 3043 # we couldn't parse the date | |
| 3044 # just let the calendar display | |
| 3045 curr_date = current_date | |
| 3046 display = current_date | |
| 3036 day = display.day | 3047 day = display.day |
| 3037 | 3048 |
| 3038 # for navigation | 3049 # for navigation |
| 3039 try: | 3050 try: |
| 3040 date_prev_month = display + date.Interval("-1m") | 3051 date_prev_month = display + date.Interval("-1m") |
