<commit_before>#!/usr/local/bin/python3
#  ^^^ this is bad practice, DON'T do as I did!
import cgitb  # debugging
import cgi
import footer
import header
from htmlify import *
from assets import *


print("Content-Type: text/html;charset=utf-8\n")
cgitb.enable()  # enable debugging
dataForm = cgi.FieldStorage()
locations = getLocations()

try:
	loggedIn = authenticate(dataForm.getvalue("password"))
	if loggedIn:
		print('<meta http-equiv="set-cookie" content="password=' + cgi.escape(dataForm.getvalue("password")) + '";>')
except AttributeError:  # password == None
	loggedIn = checkCookieLogin()
except (FileNotFoundError, PermissionError):
	dispHTML("p", contents="Error in login: Config file missing or invalid perms set!")
	loggedIn = False
except IndexError as e:
	dispHTML("p", contents="Error in login: Config file incorrectly formatted!")
	loggedIn = False


try:
	itemAddName = dataForm.getvalue("item-name")
	itemAddQuant = dataForm.getvalue("item-quantity")
	itemAddLoc = dataForm.getvalue("item-loc")
	for loc in locations:
		if loc.name == itemAddLoc:
			loc.items.append(Item(itemAddName, itemAddQuant))
			dataDump(locations)
			print("<meta http-equiv=\"refresh\" content=\"0;url=/cgi-bin/ic/main.py\">")
			# we reload so that if the user reloads it doesn't add another item
except AttributeError:
	pass  # not trying to add one
try:
	locAddName = dataForm.getvalue("loc-name")
except AttributeError:
	pass  # not trying to add one

# header
header.showHeader(loggedIn)


if len(locations) == 0: locations.append(Location("Base Location")); locations.append(Location("Second Location"))


# content
startTag("div", id="containter")  # start container
if loggedIn:
	# item list
	startTag("div", id="items")
	dispHTML("h3", contents="Items")
	startTag("div", id="itemlist")
	for loc in locations:
		dispHTML("b", contents=loc.name)
		for item in loc.items:
			startTag("p")
			print("<span class=\"itemListIndent\"/>")
			dispHTML("a", contents="<i class=\"fa fa-trash\" aria-hidden=\"true\"></i>",
					 href="/cgi-bin/ic/removeItem.py?location=" + loc.name + "&item=" + item.name)
			dispHTML("a", contents="<i class=\"fa fa-pencil\" aria-hidden=\"true\"></i>",
					 href="/cgi-bin/ic/editItem.py?location=" + loc.name + "&item=" + item.name)
			dispHTML("a", contents="<i class=\"fa fa-info\" aria-hidden=\"true\"></i>",
					 href="/cgi-bin/ic/analyseItem.py?location=" + loc.name + "&item=" + item.name)
			print("<span class=\"itemListSeparator\"> " + str(item))
			endTag("p")
	endTag("div")  # end item list
	endTag("div")  # end items

	# item controls
	startTag("div", id="add-item")
	dispHTML("h3", contents="Add item")<commit_msg>Make home page look nicer<commit_after>#!/usr/local/bin/python3
#  ^^^ this is bad practice, DON'T do as I did!
import cgitb  # debugging
import cgi
import footer
import header
from htmlify import *
from assets import *


print("Content-Type: text/html;charset=utf-8\n")
cgitb.enable()  # enable debugging
dataForm = cgi.FieldStorage()
locations = getLocations()

try:
	loggedIn = authenticate(dataForm.getvalue("password"))
	if loggedIn:
		print('<meta http-equiv="set-cookie" content="password=' + cgi.escape(dataForm.getvalue("password")) + '";>')
except AttributeError:  # password == None
	loggedIn = checkCookieLogin()
except (FileNotFoundError, PermissionError):
	dispHTML("p", contents="Error in login: Config file missing or invalid perms set!")
	loggedIn = False
except IndexError as e:
	dispHTML("p", contents="Error in login: Config file incorrectly formatted!")
	loggedIn = False


try:
	itemAddName = dataForm.getvalue("item-name")
	itemAddQuant = dataForm.getvalue("item-quantity")
	itemAddLoc = dataForm.getvalue("item-loc")
	for loc in locations:
		if loc.name == itemAddLoc:
			loc.items.append(Item(itemAddName, itemAddQuant))
			dataDump(locations)
			print("<meta http-equiv=\"refresh\" content=\"0;url=/cgi-bin/ic/main.py\">")
			# we reload so that if the user reloads it doesn't add another item
except AttributeError:
	pass  # not trying to add one
try:
	locAddName = dataForm.getvalue("loc-name")
except AttributeError:
	pass  # not trying to add one

# header
header.showHeader(loggedIn)


if len(locations) == 0: locations.append(Location("First Location")); locations.append(Location("Second Location"))


# content
startTag("div", id="containter")  # start container
if loggedIn:
	# item list
	startTag("div", id="items")
	dispHTML("h3", contents="Items")
	startTag("div", id="itemlist")
	for loc in locations:
		dispHTML("b", contents=loc.name)
		for item in loc.items:
			startTag("p")
			print("<span class=\"itemListIndent\"/>")
			dispHTML("a", contents="<i class=\"fa fa-trash\" aria-hidden=\"true\"></i>",
					 href="/cgi-bin/ic/removeItem.py?location=" + loc.name + "&item=" + item.name)
			dispHTML("a", contents="<i class=\"fa fa-pencil\" aria-hidden=\"true\"></i>",
					 href="/cgi-bin/ic/editItem.py?location=" + loc.name + "&item=" + item.name)
			dispHTML("a", contents="<i class=\"fa fa-info\" aria-hidden=\"true\"></i>",
					 href="/cgi-bin/ic/analyseItem.py?location=" + loc.name + "&item=" + item.name)
			print("<span class=\"itemListSeparator\"> " + str(item))
			endTag("p")
		dispHTML("br")
	endTag("div")  # end item list
	endTag("div")  # end items

	# item controls
	startTag("div", id="add-item")
	dispHTML("h3", contents="Add item")
{'fraction_non_alphanumeric': 0.17033993276055287, 'fraction_numerical': 0.0022413149047441168, 'mean_word_length': 4.923672566371682, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '25740', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1755, 'n_words': 430}