This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
badge.py
executable file
·191 lines (176 loc) · 7.32 KB
/
badge.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/python
# -*- coding: utf-8 *-*
import web
from web import form
import config
import datetime
import db
from view import render
badgeForm = form.Form(
form.Textbox("prenom", form.notnull,
description="Prénom / First Name"),
form.Textbox("nom", form.notnull,
description="Nom / Last Name"),
form.Textbox("texte_insigne",
description="Texte sur l'insigne / Texte on the badge"),
form.Textbox("courriel", form.notnull,
description="Courriel / Email"),
form.Textbox("adresse_1", form.notnull,
description="Adresse 1 / Address 1"),
form.Textbox("adresse_2",
description="Adresse 2 / Address 2"),
form.Textbox("ville", form.notnull,
description="Ville / City"),
form.Dropdown("province",
[
("", "Sélectionner"),
("AB", "Alberta (AB)"),
("BC", "British Columbia (BC)"),
("MB", "Manitoba (MB)"),
("NB", "New Brunswick (NB)"),
("NL", "Newfoundland and Labrador (NL)"),
("NT", "Northwest Territories (NT)"),
("NS", "Nova Scotia (NS)"),
("NU", "Nunavut (NU)"),
("PE", "Prince Edward Island (PE)"),
("SK", "Saskatchewan (SK)"),
("ON", "Ontario (ON)"),
("QC", "Québec (QC)"),
("YT", "Yukon (YT)"),
("USA", "USA"),
("OTHER", "Other / Autre"),
], form.notnull,
description="Province / Province"),
form.Textbox("code_postal", form.notnull,
description="Code postal / Postal Code"),
form.Textbox("telephone_urgence", form.notnull,
description="Téléphone d'urgence / Emergency phone #"),
# Type de badge
form.Dropdown("type",
[
("Weekend_Adulte", "Fin de semaine, Adulte / Weekend Pass, Adult ~ 35$"),
("Weekend_Jeune", "Fin de semaine, 8 à 12 ans / Weekend Pass, 8 to 12 years old ~ 20$"),
("Weekend_Enfant", "Fin de semaine, 0 à 7 ans / Weekend Pass, 0 to 7 years old ~ 0$"),
("Friday_Adulte", "Vendredi seulement, Adulte / Friday only, Adult ~ 25$"),
("Friday_Jeune", "Vendredi seulement, 8 à 12 ans / Friday only, 8 to 12 years old ~ 20$"),
], form.notnull,
description="Type de billet / Ticket type"),
form.Radio("noiz", ("oui", "non"), value="non", description="Spectacle NOIZ (vendredi soir) / NOIZ show (Friday night)", pre="20 $"),
form.Dropdown("tshirt",
[
("X", "Aucun / None"),
("P", "Petit / Small"),
("M", "Moyen / Medium"),
("G", "Grand / Large"),
("TG", "Très grand / X-large")
], description="T-Shirt", pre="20 $"),
form.Checkbox("dvd",
description="DVD de la mascarade / Masquerade DVD", pre="20 $"),
form.Textarea("instructions_speciales", rows=2, cols=40,
description="Instructions spécial / Specials Instructions")
)
class create:
"""Display and process a badge form"""
def GET(self):
cart_id = web.cookies().get(config.cookieName)
if cart_id:
f = badgeForm()
return render.base(render.badge(f), "Nouvel insigne ~ New badge", True)
else:
raise web.seeother(config.make_url('/error'))
def POST(self):
cart_id = web.cookies().get(config.cookieName)
if cart_id:
# We have a cart, proceed
f = badgeForm()
if not f.validates():
return render.base(render.badge(f), "Nouvel insigne ~ New badge", True)
else:
# Everything is valid, let's build the query
badge = {
"prenom": f.d.prenom,
"nom": f.d.nom,
"texte_insigne": f.d.texte_insigne,
"courriel": f.d.courriel,
"adresse": {
"ligne_1": f.d.adresse_1,
"ligne_2": f.d.adresse_2,
"ville": f.d.ville,
"province": f.d.province,
"code_postal": f.d.code_postal
},
"type": f.d.type,
"telephone_urgence": f.d.telephone_urgence,
"extra": {
"noiz": f.d.noiz,
"tshirt": f.d.tshirt,
"dvd": f.d.dvd
},
"instructions_speciales": f.d.instructions_speciales,
"status": "IN_CART",
"date": datetime.datetime.utcnow()}
# Adding to DB
badge_id = db.addBadge(badge, cart_id)
raise web.seeother(config.make_url("/cart/add/%s" % badge_id))
else:
raise web.seeother(config.make_url('/error'))
class edit:
def GET(self, badge_id):
cart_id = web.cookies().get(config.cookieName)
if cart_id:
f = badgeForm()
if not db.validObjectId(badge_id):
raise web.seeother('/error')
badge = db.getBadge(badge_id)
badge["adresse_1"] = badge["adresse"]["ligne_1"]
badge["adresse_2"] = badge["adresse"]["ligne_2"]
badge["ville"] = badge["adresse"]["ville"]
badge["province"] = badge["adresse"]["province"]
badge["code_postal"] = badge["adresse"]["code_postal"]
badge["noiz"] = badge["extra"]["noiz"]
badge["tshirt"] = badge["extra"]["tshirt"]
badge["dvd"] = badge["extra"]["dvd"]
f.fill(badge)
return render.base(render.badge(f), "Editer une insigne ~ Edit a badge", True)
else:
raise web.seeother(config.make_url('/error'))
def POST(self, badge_id):
cart_id = web.cookies().get(config.cookieName)
if cart_id:
# We have a cart, proceed
f = badgeForm()
if not f.validates():
return render.base(render.badge(f), "Editer une insigne ~ Edit a badge", True)
else:
# Everything is valid, let's build the query
badge = {
"prenom": f.d.prenom,
"nom": f.d.nom,
"texte_insigne": f.d.texte_insigne,
"courriel": f.d.courriel,
"adresse": {
"ligne_1": f.d.adresse_1,
"ligne_2": f.d.adresse_2,
"ville": f.d.ville,
"province": f.d.province,
"code_postal": f.d.code_postal
},
"type": f.d.type,
"telephone_urgence": f.d.telephone_urgence,
"extra": {
"noiz": f.d.noiz,
"tshirt": f.d.tshirt,
"dvd": f.d.dvd
},
"instructions_speciales": f.d.instructions_speciales,
"status": "IN_CART"}
# Adding to DB
db.updateBadge(badge, badge_id)
raise web.seeother(config.make_url("/cart/update/%s" % badge_id))
else:
raise web.seeother(config.make_url('/error'))
class display:
def GET(self, badge_id):
raise web.internalerror()
def POST(self, badge_id):
raise web.internalerror()