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
/
main.py
executable file
·127 lines (117 loc) · 5.08 KB
/
main.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/local/bin/python3
# ^^^ this is bad practice, DON'T do as I did!
import cgi
import cgitb # debugging
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
# Add any items the user wanted last load
itemAddName = dataForm.getvalue("item-name")
itemAddQuant = dataForm.getvalue("item-quantity")
itemAddLoc = dataForm.getvalue("item-loc")
doAdd = True
for loc in locations:
for item in loc.items:
if item.name == itemAddName: dispHTML("h3", contents="You can't add an item with a pre-existing name."); doAdd = False
if loc.name == itemAddLoc and doAdd:
loc.items.append(Item(itemAddName, itemAddQuant))
dataDump(locations)
print("<meta http-equiv=\"refresh\" content=\"0;url=main.py\">")
# we reload so that if the user reloads it doesn't add another item
# And locations
locAddName = dataForm.getvalue("loc-name")
if locAddName is not None:
addLocError = False
for loc in locations:
if loc.name == locAddName:
dispHTML("h3", contents="Error")
dispHTML("p", contents="You can't add a location with a name the same as one that exists already")
addLocError = True
if not addLocError:
locations.append(Location(locAddName))
print("<meta http-equiv=\"refresh\" content=\"0;url=main.py\">")
# we reload so that if the user reloads it doesn't add another location
# header
showHeader(loggedIn)
# 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:
itemNameDisplay = "<div class='dropdown'>"
itemNameDisplay += "<i class=\"fa fa-info\"></i>"
itemNameDisplay += "<div class='dropdown-content'>"
itemNameDisplay += "<a href=\"removeLocation.py?location=" + loc.name + "\"><i class=\"fa fa-fw fa-trash\" aria-hidden=\"true\"></i>Delete</a><br />"
itemNameDisplay += "<a href=\"editLocation.py?location=" + loc.name + "\"><i class=\"fa fa-fw fa-pencil\" aria-hidden=\"true\"></i>Edit</a><br />"
itemNameDisplay += "<a href=\"analyseLocation.py?location=" + loc.name + "\"><i class=\"fa fa-fw fa-info\" aria-hidden=\"true\"></i>Info</a><br />"
itemNameDisplay += "</div>"
itemNameDisplay += "</div>"
itemNameDisplay += "<span class=\"locListSeparator\" /> "
itemNameDisplay += getHTML("b", contents=loc.name)
print(itemNameDisplay)
for item in loc.items:
startTag("p")
print("<span class=\"itemListIndent\"/>")
dispHTML("a", contents="<i class=\"fa fa-trash\" aria-hidden=\"true\"></i>",
href="removeItem.py?location=" + loc.name + "&item=" + item.name)
dispHTML("a", contents="<i class=\"fa fa-pencil\" aria-hidden=\"true\"></i>",
href="editItem.py?location=" + loc.name + "&item=" + item.name)
dispHTML("a", contents="<i class=\"fa fa-info\" aria-hidden=\"true\"></i>",
href="analyseItem.py?location=" + loc.name + "&item=" + item.name)
print("<span class=\"itemListSeparator\" /> " + str(item))
endTag("p")
if len(loc.items) == 0: dispHTML("br")
endTag("div") # end item list
endTag("div") # end items
# item controls
startTag("div", id="add-item")
dispHTML("h3", contents="Add item")
startTag("form", id="add-item-form", method="POST", action="main.py") # login form
dispHTML("p", contents="Name:", newLine=False)
dispHTML("input", type="text", name="item-name")
dispHTML("p", contents="Quantity:", newLine=False)
dispHTML("input", type="number", name="item-quantity", min="1")
dispHTML("br")
startTag("select", name="item-loc")
dispHTML("option", value="", disabled="disabled", selected="selected", contents="Location")
for loc in locations:
dispHTML("option", value=loc.name, contents=loc.name)
endTag("select")
dispHTML("button", contents="submit")
endTag("form") # end login form
endTag("div") # end div id=add-item
# item controls
startTag("div", id="add-loc")
dispHTML("h3", contents="Add location")
startTag("form", id="add-loc-form", method="POST", action="main.py") # login form
dispHTML("p", contents="Name:", newLine=False)
dispHTML("input", type="text", name="loc-name")
dispHTML("button", contents="submit")
endTag("form") # end login form
endTag("div") # end div id=add-item
else:
dispHTML("h3", contents="Welcome to InventoryControl!")
dispHTML("p", contents="IC is Sound and Lights' own inventory management system.")
dispHTML("p", contents="It was developed by the Sound and Lights programming team, and is open source.")
dispHTML("p", contents="Please login to continue.")
endTag("div") # end container
# footer
showFooter()
dataDump(locations)