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

print("Content-Type: text/html;charset=utf-8\n")
cgitb.enable()
locations = getLocations()
loggedIn = checkCookieLogin()
localData = cgi.FieldStorage()
header.showHeader(loggedIn=loggedIn)


locationName = localData.getvalue("location")
missCounter = 0
locationIndex = 0
for l in locations:
	if l.name == locationName:
		location = l
	else:
		missCounter += 1
		locationIndex += 1
if missCounter >= len(locations):
	dispHTML("h3", contents="Error")
	dispHTML("p", contents="Location '" + str(locationName) + "' not found.")
	itemFound = False
else:
	missCounter = 0
	itemName = localData.getvalue("item")
	itemFound = False
	itemIndex = 0
	for i in location.items:
		if i.name == itemName:
			item = i
			itemFound = True
		else:
			missCounter += 1
			itemIndex += 1
	if missCounter >= len(location.items):
		dispHTML("h3", contents="Error")
		dispHTML("p", contents="Item '" + str(itemName) + "' not found.")
		dispHTML("p", contents="If you just changed its location, go to the Home page and click the 'info' button to view it.")

if loggedIn and itemFound:
	setName = localData.getvalue("setName")
	setQuant = localData.getvalue("setQuant")
	setLoc = localData.getvalue("setLoc")
	setOwner = localData.getvalue("setOwner")
	setCurrentUser = localData.getvalue("setCurrentUser")
	if setName is not None: item.name = setName
	if setQuant is not None: item.quantity = int(setQuant)
	if setLoc is not None:  # man who move item between locations accomplish anything!
		for loc in locations:
			if loc.name == setLoc:
				loc.items.append(item)
				dispHTML("b", contents="Please note that changes to the location may take a while to show up.")
		counter = 0
		for i in location.items:
			if i == item:
				del location.items[counter]
		counter += 1

	dispHTML("h3", contents=item.name)
	print("<p><b>Quantity: </b> " + str(item.quantity) + "</p>")
	print("<p><b>Location: </b> " + location.name + "</p>")
	print("<p><b>Owner:    </b> " + item.owner.name + " (" + item.owner.email + ")")
	print("<p><b>Current user: </b>" + item.currentUser.name + " (" + item.currentUser.email + ")")
	dispHTML("br")
	startTag("p")
	dispHTML("a", contents="Edit", href="/cgi-bin/ic/editItem.py?location=" + locationName + "&item=" + itemName)
	endTag("p")
elif not loggedIn:
	dispHTML("h3", contents="Please login")
	dispHTML("p", contents="This area of the site requires you to authenticate.")
	dispHTML("p", contents="With cookies enabled, please go to the Login page, login, and navigate back here.")
	dispHTML("p", contents="If you don't want to find this page again, please copy the link now. \
	Once you have logged in you can paste it into your browser's address bar and, through the power of cookies, \
	you will be logged in.")

footer.showFooter()
dataDump(locations)<commit_msg>Fix move item issue<commit_after>#!/usr/local/bin/python3
#  ^^^ this is bad practice, DON'T do as I did!
import header
import footer
from htmlify import *
import cgi
import cgitb
from assets import *

print("Content-Type: text/html;charset=utf-8\n")
cgitb.enable()
locations = getLocations()
loggedIn = checkCookieLogin()
localData = cgi.FieldStorage()
header.showHeader(loggedIn=loggedIn)


locationName = localData.getvalue("location")
missCounter = 0
locationIndex = 0
for l in locations:
	if l.name == locationName:
		location = l
	else:
		missCounter += 1
		locationIndex += 1
if missCounter >= len(locations):
	dispHTML("h3", contents="Error")
	dispHTML("p", contents="Location '" + str(locationName) + "' not found.")
	itemFound = False
else:
	missCounter = 0
	itemName = localData.getvalue("item")
	itemFound = False
	itemIndex = 0
	for i in location.items:
		if i.name == itemName:
			item = i
			itemFound = True
		else:
			missCounter += 1
			itemIndex += 1
	if missCounter >= len(location.items):
		dispHTML("h3", contents="Error")
		dispHTML("p", contents="Item '" + str(itemName) + "' not found.")
		dispHTML("p", contents="If you just changed its location, go to the Home page and click the 'info' button to view it.")

if loggedIn and itemFound:
	setName = localData.getvalue("setName")
	setQuant = localData.getvalue("setQuant")
	setLoc = localData.getvalue("setLoc")
	setOwner = localData.getvalue("setOwner")
	setCurrentUser = localData.getvalue("setCurrentUser")
	if setName is not None: item.name = setName
	if setQuant is not None: item.quantity = int(setQuant)
	if setLoc is not None:  # man who move item between locations accomplish anything!
		for loc in locations:
			if loc.name == setLoc:
				loc.items.append(item)
				dispHTML("b", contents="Please note that changes to the location may take a while to show up.")
		counter = 0
		for i in location.items:
			if i == item:
				del location.items[counter]
			counter += 1

	dispHTML("h3", contents=item.name)
	print("<p><b>Quantity: </b> " + str(item.quantity) + "</p>")
	print("<p><b>Location: </b> " + location.name + "</p>")
	print("<p><b>Owner:    </b> " + item.owner.name + " (" + item.owner.email + ")")
	print("<p><b>Current user: </b>" + item.currentUser.name + " (" + item.currentUser.email + ")")
	dispHTML("br")
	startTag("p")
	dispHTML("a", contents="Edit", href="/cgi-bin/ic/editItem.py?location=" + locationName + "&item=" + itemName)
	endTag("p")
elif not loggedIn:
	dispHTML("h3", contents="Please login")
	dispHTML("p", contents="This area of the site requires you to authenticate.")
	dispHTML("p", contents="With cookies enabled, please go to the Login page, login, and navigate back here.")
	dispHTML("p", contents="If you don't want to find this page again, please copy the link now. \
	Once you have logged in you can paste it into your browser's address bar and, through the power of cookies, \
	you will be logged in.")

footer.showFooter()
dataDump(locations)
{'fraction_non_alphanumeric': 0.14326744382497045, 'fraction_numerical': 0.005406318634904545, 'mean_word_length': 4.548266166822867, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 35, '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': '861952', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1896, 'n_words': 600}