utf stuff, fixing toggling

This commit is contained in:
q
2016-07-04 10:04:27 +03:00
parent 20d5e087cb
commit 44a6ab2d27
3 changed files with 28 additions and 22 deletions

18
shop.py
View File

@@ -120,8 +120,8 @@ def show_shop(shopid):
data_dir=os.path.join(DATADIR, get_username(row[2]))
data_file=os.path.join(data_dir, row[1]+".md")
entries=[]
content=open(data_file, 'rt').read()
for i,row in enumerate(open( data_file, 'rt').read().split("\n")):
content=open(data_file, 'rt').read().decode('utf-8')
for i,row in enumerate(open( data_file, 'rt').read().decode('utf-8').split("\n")):
# any parsing magick would be here
if row=="":
continue
@@ -130,7 +130,7 @@ def show_shop(shopid):
if "[ ]" in row or "[x]" in row:
icon=u"\u2714"
extra_class=""
row=urlify(row)
row=urlify(row).encode('ascii', 'xmlcharrefreplace')
entries.append( dict(row=i, text=row, icon=icon, extra_class=extra_class) )
shared_to=[]
cur = g.db.execute('select * from shares')
@@ -176,7 +176,7 @@ def add_items():
if row.strip()=="":
continue
count+=1
contents_file.write("[ ] %s\n"%row.strip())
contents_file.write("[ ] %s\n"%row.strip().encode('utf-8'))
contents_file.close()
flash('Added %d items'%(count))
return redirect(url_for('show_shop',shopid=shopid))
@@ -195,7 +195,7 @@ def edit_md():
copyfile(data_file, backup)
contents_file=open(data_file,'wt')
for row in request.form['edit_md'].split("\n"):
contents_file.write("%s\n"%row)
contents_file.write("%s\n"%row.encode('utf-8'))
contents_file.close()
flash('Saved new file.')
return redirect(url_for('show_shop',shopid=shopid))
@@ -218,7 +218,7 @@ def toggle_item():
data_dir=os.path.join(DATADIR, ownername)
data_file=os.path.join(data_dir, shopname+".md")
contents_file=open(data_file,'rt')
contents=contents_file.read().split("\n")
contents=contents_file.read().decode('utf-8').split("\n")
contents_file.close()
changed=False
for i,row in enumerate(contents):
@@ -232,7 +232,7 @@ def toggle_item():
break
if changed:
contents_file=open(data_file,'wt')
contents_file.write("\n".join(contents))
contents_file.write("\n".join(contents).encode('utf-8'))
contents_file.close()
#~ flash('successfully posted %s (%d)'%(row,req_row))
return redirect(url_for('show_shop',shopid=shopid))
@@ -250,14 +250,14 @@ def remove_toggled():
contents_file=open(data_file,'rt')
contents=[]
changed=False
for i,row in enumerate(contents_file.read().split("\n")):
for i,row in enumerate(contents_file.read().decode('utf-8').split("\n")):
if '[x]' not in row:
contents.append(row)
changed=True
contents_file.close()
if changed:
contents_file=open(data_file,'wt')
contents_file.write("\n".join(contents))
contents_file.write("\n".join(contents).encode('utf-8'))
contents_file.close()
#~ flash('successfully posted %s (%d)'%(row,req_row))
return redirect(url_for('show_shop',shopid=shopid))