This repository has been archived by the owner on Jun 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyseItem.py
executable file
·82 lines (77 loc) · 2.79 KB
/
analyseItem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/local/bin/python3
# ^^^ this is bad practice, DON'T do as I did!
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()
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="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.")
showFooter()
dataDump(locations)