switch to using .txt suffix. rename all your files!

This commit is contained in:
Ville Rantanen
2023-11-30 10:02:05 +02:00
parent 62479844cf
commit 070235c452

View File

@@ -89,7 +89,7 @@ def get_shop_date(id):
for row in cur.fetchall(): for row in cur.fetchall():
if id == row[0]: if id == row[0]:
data_dir = os.path.join(DATADIR, get_username(row[2])) data_dir = os.path.join(DATADIR, get_username(row[2]))
data_file = os.path.join(data_dir, row[1] + ".md") data_file = os.path.join(data_dir, row[1] + ".txt")
if os.path.exists(data_file): if os.path.exists(data_file):
date = datetime.datetime.fromtimestamp(os.path.getmtime(data_file)).strftime("%m/%d %H:%M") date = datetime.datetime.fromtimestamp(os.path.getmtime(data_file)).strftime("%m/%d %H:%M")
return date return date
@@ -101,7 +101,7 @@ def get_shop_backup_date(id):
for row in cur.fetchall(): for row in cur.fetchall():
if id == row[0]: if id == row[0]:
data_dir = os.path.join(DATADIR, get_username(row[2])) data_dir = os.path.join(DATADIR, get_username(row[2]))
data_file = os.path.join(data_dir, row[1] + ".md.bkp") data_file = os.path.join(data_dir, row[1] + ".txt.bkp")
if os.path.exists(data_file): if os.path.exists(data_file):
date = datetime.datetime.fromtimestamp(os.path.getmtime(data_file)).strftime("%m/%d %H:%M") date = datetime.datetime.fromtimestamp(os.path.getmtime(data_file)).strftime("%m/%d %H:%M")
return date return date
@@ -120,7 +120,7 @@ def scan_for_new_documents(id):
continue continue
existing.append(row[1]) existing.append(row[1])
for row in os.listdir(data_dir): for row in os.listdir(data_dir):
if row.endswith(".md"): if row.endswith(".txt"):
if row[:-3] not in existing: if row[:-3] not in existing:
non_existing.append(row[:-3]) non_existing.append(row[:-3])
for shop in non_existing: for shop in non_existing:
@@ -206,7 +206,7 @@ def show_shop(shopid):
if not has_access: if not has_access:
return redirect(url_for("list_shops")) return redirect(url_for("list_shops"))
data_dir = os.path.join(DATADIR, get_username(row[2])) data_dir = os.path.join(DATADIR, get_username(row[2]))
data_file = os.path.join(data_dir, row[1] + ".md") data_file = os.path.join(data_dir, row[1] + ".txt")
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 = []
@@ -285,7 +285,7 @@ def add_items():
shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0] shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0]
ownername = get_username(ownerid) ownername = get_username(ownerid)
data_dir = os.path.join(DATADIR, ownername) data_dir = os.path.join(DATADIR, ownername)
data_file = os.path.join(data_dir, shopname + ".md") data_file = os.path.join(data_dir, shopname + ".txt")
count = 0 count = 0
contents_file = open(data_file, "at") contents_file = open(data_file, "at")
for row in request.form["add_md"].split("\n"): for row in request.form["add_md"].split("\n"):
@@ -307,7 +307,7 @@ def edit_md():
shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0] shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0]
ownername = get_username(ownerid) ownername = get_username(ownerid)
data_dir = os.path.join(DATADIR, ownername) data_dir = os.path.join(DATADIR, ownername)
data_file = os.path.join(data_dir, shopname + ".md") data_file = os.path.join(data_dir, shopname + ".txt")
backup = data_file + ".bkp" backup = data_file + ".bkp"
copyfile(data_file, backup) copyfile(data_file, backup)
contents_file = open(data_file, "wt") contents_file = open(data_file, "wt")
@@ -330,7 +330,7 @@ def restore_md():
shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0] shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0]
ownername = get_username(ownerid) ownername = get_username(ownerid)
data_dir = os.path.join(DATADIR, ownername) data_dir = os.path.join(DATADIR, ownername)
data_file = os.path.join(data_dir, shopname + ".md") data_file = os.path.join(data_dir, shopname + ".txt")
backup = data_file + ".bkp" backup = data_file + ".bkp"
backup_tmp = data_file + ".tmp" backup_tmp = data_file + ".tmp"
if not os.path.exists(backup): if not os.path.exists(backup):
@@ -365,7 +365,7 @@ def toggle_item():
if req_row == None: if req_row == None:
return redirect(url_for("show_shop", shopid=shopid)) return redirect(url_for("show_shop", shopid=shopid))
data_dir = os.path.join(DATADIR, ownername) data_dir = os.path.join(DATADIR, ownername)
data_file = os.path.join(data_dir, shopname + ".md") data_file = os.path.join(data_dir, shopname + ".txt")
backup = data_file + ".bkp" backup = data_file + ".bkp"
contents_file = open(data_file, "rt") contents_file = open(data_file, "rt")
contents = contents_file.read().split("\n") contents = contents_file.read().split("\n")
@@ -398,7 +398,7 @@ def remove_toggled():
shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0] shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0]
ownername = get_username(ownerid) ownername = get_username(ownerid)
data_dir = os.path.join(DATADIR, ownername) data_dir = os.path.join(DATADIR, ownername)
data_file = os.path.join(data_dir, shopname + ".md") data_file = os.path.join(data_dir, shopname + ".txt")
backup = data_file + ".bkp" backup = data_file + ".bkp"
contents_file = open(data_file, "rt") contents_file = open(data_file, "rt")
contents = [] contents = []
@@ -438,7 +438,7 @@ def add_shop():
g.db.execute("insert into shops (shop,owner) values (?, ?)", [shopname, session["user"]]) g.db.execute("insert into shops (shop,owner) values (?, ?)", [shopname, session["user"]])
g.db.commit() g.db.commit()
new_dir = os.path.join(DATADIR, get_username(session["user"])) new_dir = os.path.join(DATADIR, get_username(session["user"]))
new_file = os.path.join(new_dir, shopname + ".md") new_file = os.path.join(new_dir, shopname + ".txt")
if not os.path.exists(new_dir): if not os.path.exists(new_dir):
os.mkdir(new_dir) os.mkdir(new_dir)
open(new_file, "at") open(new_file, "at")
@@ -507,7 +507,7 @@ def remove_shop():
shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0] shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0]
ownername = get_username(ownerid) ownername = get_username(ownerid)
data_dir = os.path.join(DATADIR, ownername) data_dir = os.path.join(DATADIR, ownername)
data_file = os.path.join(data_dir, shopname + ".md") data_file = os.path.join(data_dir, shopname + ".txt")
if session.get("user") != ownerid: if session.get("user") != ownerid:
flash("Not your shop!") flash("Not your shop!")
return redirect(url_for("show_shop", shopid=shopid)) return redirect(url_for("show_shop", shopid=shopid))