untick all entries
This commit is contained in:
19
shop.py
19
shop.py
@@ -249,8 +249,6 @@ def restore_md():
|
||||
flash('Backup restored')
|
||||
return redirect(url_for('show_shop',shopid=shopid))
|
||||
|
||||
|
||||
|
||||
@app.route('/toggle', methods=['POST'])
|
||||
def toggle_item():
|
||||
if not session.get('logged_in'):
|
||||
@@ -266,23 +264,30 @@ def toggle_item():
|
||||
if key=='toggleAll':
|
||||
# Special meaning: toggle all rows
|
||||
req_row=-1
|
||||
if key=='unTickAll':
|
||||
# Special meaning: untick all rows
|
||||
req_row=-2
|
||||
if req_row==None:
|
||||
return redirect(url_for('show_shop',shopid=shopid))
|
||||
data_dir=os.path.join(DATADIR, ownername)
|
||||
data_file=os.path.join(data_dir, shopname+".md")
|
||||
backup=data_file+".bkp"
|
||||
contents_file=open(data_file,'rt')
|
||||
contents=contents_file.read().decode('utf-8').split("\n")
|
||||
contents_file.close()
|
||||
changed=False
|
||||
for i,row in enumerate(contents):
|
||||
if i==req_row or req_row==-1:
|
||||
if '[ ]' in row:
|
||||
contents[i]=row.replace('[ ]','[x]')
|
||||
if i==req_row or req_row<0:
|
||||
if req_row!=-2: # no ticking if unticking all
|
||||
if '[ ]' in row:
|
||||
contents[i]=row.replace('[ ]','[x]')
|
||||
if '[x]' in row:
|
||||
contents[i]=row.replace('[x]','[ ]')
|
||||
if row!=contents[i]:
|
||||
changed=True
|
||||
if row!=contents[i]:
|
||||
changed=True
|
||||
if changed:
|
||||
if req_row==-1 or req_row==-2:
|
||||
copyfile(data_file, backup)
|
||||
contents_file=open(data_file,'wt')
|
||||
contents_file.write("\n".join(contents).encode('utf-8'))
|
||||
contents_file.close()
|
||||
|
||||
Reference in New Issue
Block a user