moving to p3
This commit is contained in:
19
shop.py
19
shop.py
@@ -35,7 +35,7 @@ def connect_db():
|
|||||||
return sqlite3.connect(app.config['DATABASE'])
|
return sqlite3.connect(app.config['DATABASE'])
|
||||||
|
|
||||||
def password_hash(s):
|
def password_hash(s):
|
||||||
return hashlib.sha224(s).hexdigest()
|
return hashlib.sha224(s.encode('utf8')).hexdigest()
|
||||||
|
|
||||||
def get_username(id):
|
def get_username(id):
|
||||||
cur = g.db.execute('select * from users')
|
cur = g.db.execute('select * from users')
|
||||||
@@ -105,6 +105,7 @@ def scan_for_new_documents(id):
|
|||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
def markdown_parse(s):
|
def markdown_parse(s):
|
||||||
|
s = s.decode('utf8')
|
||||||
s=BOLDFINDER.sub(r'*<span class="md_bold">\1</span>*',s)
|
s=BOLDFINDER.sub(r'*<span class="md_bold">\1</span>*',s)
|
||||||
s=CODEFINDER.sub(r'`<span class="md_code">\1</span>`',s)
|
s=CODEFINDER.sub(r'`<span class="md_code">\1</span>`',s)
|
||||||
return s
|
return s
|
||||||
@@ -147,8 +148,8 @@ def show_shop(shopid):
|
|||||||
if not os.path.exists(data_file):
|
if not os.path.exists(data_file):
|
||||||
open(data_file, 'wt').close()
|
open(data_file, 'wt').close()
|
||||||
entries=[]
|
entries=[]
|
||||||
content=open(data_file, 'rt').read().decode('utf-8')
|
content=open(data_file, 'rt').read()#.decode('utf-8')
|
||||||
for i,row in enumerate(open( data_file, 'rt').read().decode('utf-8').split("\n")):
|
for i,row in enumerate(open( data_file, 'rt').read().split("\n")):
|
||||||
# any parsing magick would be here
|
# any parsing magick would be here
|
||||||
row=row.rstrip()
|
row=row.rstrip()
|
||||||
if row=="":
|
if row=="":
|
||||||
@@ -227,7 +228,7 @@ def add_items():
|
|||||||
if row.strip()=="":
|
if row.strip()=="":
|
||||||
continue
|
continue
|
||||||
count+=1
|
count+=1
|
||||||
contents_file.write("[ ] %s\n"%row.strip().encode('utf-8'))
|
contents_file.write("[ ] %s\n"%row.strip())
|
||||||
contents_file.close()
|
contents_file.close()
|
||||||
flash('Added %d items'%(count))
|
flash('Added %d items'%(count))
|
||||||
return redirect(url_for('show_shop',shopid=shopid))
|
return redirect(url_for('show_shop',shopid=shopid))
|
||||||
@@ -249,7 +250,7 @@ def edit_md():
|
|||||||
while contents_list[-1].strip()=='':
|
while contents_list[-1].strip()=='':
|
||||||
contents_list.pop()
|
contents_list.pop()
|
||||||
for row in contents_list:
|
for row in contents_list:
|
||||||
contents_file.write("%s\n"%row.encode('utf-8'))
|
contents_file.write("%s\n"%(row,))
|
||||||
contents_file.close()
|
contents_file.close()
|
||||||
flash('Saved new file.')
|
flash('Saved new file.')
|
||||||
return redirect(url_for('show_shop',shopid=shopid))
|
return redirect(url_for('show_shop',shopid=shopid))
|
||||||
@@ -299,7 +300,7 @@ def toggle_item():
|
|||||||
data_file=os.path.join(data_dir, shopname+".md")
|
data_file=os.path.join(data_dir, shopname+".md")
|
||||||
backup=data_file+".bkp"
|
backup=data_file+".bkp"
|
||||||
contents_file=open(data_file,'rt')
|
contents_file=open(data_file,'rt')
|
||||||
contents=contents_file.read().decode('utf-8').split("\n")
|
contents=contents_file.read().split("\n")
|
||||||
contents_file.close()
|
contents_file.close()
|
||||||
changed=False
|
changed=False
|
||||||
for i,row in enumerate(contents):
|
for i,row in enumerate(contents):
|
||||||
@@ -315,7 +316,7 @@ def toggle_item():
|
|||||||
if req_row==-1 or req_row==-2:
|
if req_row==-1 or req_row==-2:
|
||||||
copyfile(data_file, backup)
|
copyfile(data_file, backup)
|
||||||
contents_file=open(data_file,'wt')
|
contents_file=open(data_file,'wt')
|
||||||
contents_file.write("\n".join(contents).encode('utf-8'))
|
contents_file.write("\n".join(contents))
|
||||||
contents_file.close()
|
contents_file.close()
|
||||||
return redirect(url_for('show_shop',shopid=shopid))
|
return redirect(url_for('show_shop',shopid=shopid))
|
||||||
|
|
||||||
@@ -333,7 +334,7 @@ def remove_toggled():
|
|||||||
contents_file=open(data_file,'rt')
|
contents_file=open(data_file,'rt')
|
||||||
contents=[]
|
contents=[]
|
||||||
changed=False
|
changed=False
|
||||||
for i,row in enumerate(contents_file.read().decode('utf-8').split("\n")):
|
for i,row in enumerate(contents_file.read().split("\n")):
|
||||||
if '[x]' not in row:
|
if '[x]' not in row:
|
||||||
contents.append(row)
|
contents.append(row)
|
||||||
else:
|
else:
|
||||||
@@ -342,7 +343,7 @@ def remove_toggled():
|
|||||||
if changed:
|
if changed:
|
||||||
copyfile(data_file, backup)
|
copyfile(data_file, backup)
|
||||||
contents_file=open(data_file,'wt')
|
contents_file=open(data_file,'wt')
|
||||||
contents_file.write("\n".join(contents).encode('utf-8'))
|
contents_file.write("\n".join(contents))
|
||||||
contents_file.close()
|
contents_file.close()
|
||||||
#~ flash('successfully posted %s (%d)'%(row,req_row))
|
#~ flash('successfully posted %s (%d)'%(row,req_row))
|
||||||
return redirect(url_for('show_shop',shopid=shopid))
|
return redirect(url_for('show_shop',shopid=shopid))
|
||||||
|
|||||||
Reference in New Issue
Block a user