The problem I am currently facing is that the code works as it should if a box that was originally displayed checked is unchecked by the user, but does not respond correctly if a box that was unchecked is checked by the user. The bizarre thing is that the newly checked box is correctly detected, and the first debugging flash duly appears when the form reloads. This flash also correctly reports that the relevant fields['pattern'][n] value is 0. However, the test a couple of lines below, which should succeed (since the value is not equal to one), fails, and changed is not set to True (and the second debugging flash does not appear). Can anyone make any sense out of this?
Code: Select all
if 'Repeat' in request.form:
count=0
for daynum in range(0,7):
fldname='Day_'+ str(daynum)
if fldname in request.form:
flash(fldname + ': ' + str(fields['pattern'][daynum])) # added for debugging
mypattern.set_day(daynum)
count += 1
if fields['pattern'][daynum] != 1:
changed=True
flash('changed should be True') # added for debugging
elif fields['pattern'][daynum] == 1:
mypattern.reset_day(daynum)
changed=True
if count == 0:
errors=True
flash('Repeating actions must repeat on at least one day of the week')
else:
action.pattern=mypattern.encode()