author | Tero Marttila <terom@fixme.fi> |
Thu, 23 Dec 2010 00:57:46 +0200 | |
changeset 9 | 0327b83959e9 |
parent 7 | bbac4b0f4320 |
child 10 | 4bdb45071c89 |
permissions | -rw-r--r-- |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
# coding: utf-8 |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
""" |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
Order data model/view/handler |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
""" |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
|
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
from svv.controllers import PageHandler |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
from svv.html import tags |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
from svv import database as db |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
|
7 | 10 |
import datetime |
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
11 |
import logging |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
13 |
log = logging.getLogger('svv.orders') |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
15 |
class FormError (Exception) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
16 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
17 |
A user-level error in a form field |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
18 |
""" |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
19 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
20 |
def __init__ (self, field, error) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
21 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
22 |
field - name of field with error |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
23 |
error - descriptive text for user |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
24 |
""" |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
26 |
self.field = field |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
27 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
28 |
super(FormError, self).__init__(error) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
29 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
30 |
class OrderForm (object) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
31 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
32 |
A single instance of a <form>, where we can process submitted data from the client, storing the associated |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
33 |
Order-related data, and then render a form for any of that related data. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
34 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
35 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
36 |
# any POST data we have processed, updated from process() |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
37 |
data = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
38 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
39 |
def __init__ (self, app) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
40 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
41 |
app - bind this form to the app state (db etc) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
42 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
43 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
44 |
self.app = app |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
45 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
46 |
def defaults (self) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
47 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
48 |
Update our attributes with default values |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
49 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
50 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
51 |
self.customer_id = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
52 |
self.customer_name = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
53 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
54 |
self.contact_id = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
55 |
self.contact_name = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
56 |
self.contact_phone = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
57 |
self.contact_email = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
58 |
self.contact_customer = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
59 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
60 |
self.event_name = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
61 |
self.event_description = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
62 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
63 |
tomorrow = datetime.date.today() + datetime.timedelta(days=1) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
64 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
65 |
# default to tomorrow afternoon |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
66 |
self.event_start = datetime.datetime.combine(tomorrow, datetime.time(16, 00)) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
67 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
68 |
# automatically determined once start is set |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
69 |
self.event_end = None |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
70 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
71 |
def process_raw_field (self, name, default=None, required=None) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
72 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
73 |
Process a generic incoming data field. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
74 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
75 |
default - value to return if no value was present |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
76 |
required - raise a FormError if no value present |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
77 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
78 |
Returns the value as a str, or default |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
79 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
80 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
81 |
if name in self.post : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
82 |
return self.post[name] |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
83 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
84 |
elif required : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
85 |
raise FormError(name, "Required field") |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
86 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
87 |
else : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
88 |
return default |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
89 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
90 |
def process_string_field (self, name, default=None, required=None, strip=True) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
91 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
92 |
Process a generic incoming string field. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
93 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
94 |
Trims extra whitespace from around the value, unless strip=False is given. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
95 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
96 |
Returns the value as unicode, or default. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
97 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
98 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
99 |
value = self.process_raw_field(name, required=required) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
100 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
101 |
if value is None : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
102 |
return default |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
103 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
104 |
try : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
105 |
# XXX: decode somehow, or can werkzeug handle that? |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
106 |
value = unicode(value) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
107 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
108 |
except UnicodeDecodeError : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
109 |
raise FormError(name, "Failed to decode Unicode characters") |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
110 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
111 |
if strip : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
112 |
value = value.strip() |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
113 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
114 |
return value |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
115 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
116 |
def process_integer_field (self, name, default=None, required=None) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
117 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
118 |
Process a generic incoming int field. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
119 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
120 |
Returns the value as int, or default. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
121 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
122 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
123 |
value = self.process_raw_field(name, required=required) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
124 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
125 |
if value is None : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
126 |
return default |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
127 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
128 |
try : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
129 |
return int(value) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
130 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
131 |
except ValueError : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
132 |
raise FormError(name, "Must be a number") |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
133 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
134 |
DATETIME_FORMAT = "%d.%m.%Y %H:%M" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
135 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
136 |
def process_datetime_field (self, name, default=None, required=None, format=DATETIME_FORMAT) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
137 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
138 |
Process an incoming datetime field. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
139 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
140 |
Returns the value as datetime, or default. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
141 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
142 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
143 |
value = self.process_raw_field(name, required=required) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
144 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
145 |
if value is None : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
146 |
return default |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
147 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
148 |
try : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
149 |
return datetime.datetime.strptime(value, format) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
150 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
151 |
except ValueError, ex : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
152 |
raise FormError(name, "Invalid date/time value: " + str(ex)) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
153 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
154 |
def process_multifield (self, table, id, fields) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
155 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
156 |
Process a set of user-given field values for an object with an unique id, and some set of additional fields. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
157 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
158 |
If the id is given, look up the corresponding field values, and return those. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
159 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
160 |
If any of the fields are given, either look up a matching row, or create a new one, and return its id. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
161 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
162 |
Returns an (id_name, field_name, ...) N-tuple. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
163 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
164 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
165 |
id_name, id_col, id_value = id |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
166 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
167 |
if id_value : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
168 |
# look up object from db |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
169 |
columns = [col for name, col, value in fields] |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
170 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
171 |
sql = db.select(columns, (id_col == id_value)) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
172 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
173 |
for row in sql : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
174 |
# XXX: sanity-check row values vs our values |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
175 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
176 |
# new values |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
177 |
fields = tuple( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
178 |
(name, col, row[col]) for name, col, value in fields |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
179 |
) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
180 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
181 |
# ok, just use the first one |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
182 |
break |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
183 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
184 |
else : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
185 |
# not found! |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
186 |
raise FormError(id_name, "Item selected does not seem to exist") |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
187 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
188 |
log.info("Lookup %s=%d -> %s", id_name, id_value, dict((name, value) for name, col, value in fields)) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
189 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
190 |
elif any(value for name, col, value in fields) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
191 |
# look up identical object from db? |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
192 |
sql = db.select([id_col], db.and_(*[(col == value) for name, col, value in fields])) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
193 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
194 |
for row in self.app.query(sql) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
195 |
if id_value : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
196 |
log.warn("Duplicate %s=%d for %s", id_name, id_value, dict((name, value) for name, col, value in fields)) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
197 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
198 |
# found object's id |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
199 |
id_value = row[id_col] |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
200 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
201 |
log.info("Found %s -> %d", dict((name, value) for name, col, value in fields), id_value) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
202 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
203 |
# create new object? |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
204 |
if not id_value : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
205 |
sql = db.insert(table).values(dict((col, value) for name, col, value in fields)) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
206 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
207 |
id_value, = self.app.insert(sql) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
208 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
209 |
log.info("Create %s -> %d", dict((name, value) for name, col, value in fields), id_value) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
210 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
211 |
else : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
212 |
# not known |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
213 |
log.debug("No %s known for order...", id_name) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
214 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
215 |
# return full set of values |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
216 |
return (id_value, ) + tuple(value for name, col, value in fields) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
217 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
218 |
def process_customer (self) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
219 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
220 |
Process the incoming customer_* fields, returning (customer_id, customer_name). |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
221 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
222 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
223 |
return self.process_multifield(db.customers, |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
224 |
('customer_id', db.customers.c.id, self.process_integer_field('customer_id')), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
225 |
( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
226 |
('customer_name', db.customers.c.name, self.process_string_field('customer_name')), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
227 |
), |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
228 |
) |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
229 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
230 |
def process_contact (self, customer_id) : |
7 | 231 |
""" |
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
232 |
Process the incoming contact_* fields, returning |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
233 |
(contact_id, contact_name, contact_phone, contact_email, contact_customer) |
7 | 234 |
""" |
235 |
||
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
236 |
return self.process_multifield(db.contacts, |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
237 |
('contact_id', db.contacts.c.id, self.process_integer_field('contact_id')), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
238 |
( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
239 |
('contact_name', db.contacts.c.name, self.process_string_field('contact_name')), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
240 |
('contact_phone', db.contacts.c.phone, self.process_string_field('contact_phone')), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
241 |
('contact_email', db.contacts.c.email, self.process_string_field('contact_email')), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
242 |
('contact_customer', db.contacts.c.customer, customer_id), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
243 |
), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
244 |
) |
7 | 245 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
246 |
def process_event (self) : |
7 | 247 |
""" |
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
248 |
Process the incoming event_* fields, returning |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
249 |
(event_name, event_description, event_start, event_end) |
7 | 250 |
""" |
251 |
||
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
252 |
event_name = self.process_string_field('event_name') |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
253 |
event_description = self.process_string_field('event_description', strip=False) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
254 |
event_start = self.process_datetime_field('event_start') |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
255 |
event_end = self.process_datetime_field('event_end') |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
256 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
257 |
return (event_name, event_description, event_start, event_end) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
258 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
259 |
def process (self, data) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
260 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
261 |
Bind ourselves to the given incoming POST data, and update our order field attributes. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
262 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
263 |
data - the submitted POST data as a MultiDict |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
264 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
265 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
266 |
# bind the raw post data |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
267 |
self.data = data |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
268 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
269 |
# customer |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
270 |
self.customer_id, self.customer_name = self.process_customer() |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
271 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
272 |
# contact |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
273 |
self.contact_id, self.contact_name, self.contact_phone, self.contact_email, self.contact_customer = self.process_contact(customer_id) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
274 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
275 |
if self.contact_customer and not self.customer_id : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
276 |
# TODO: be really smart? |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
277 |
pass |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
278 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
279 |
# event |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
280 |
self.event_name, self.event_description, self.event_start, self.event_end = self.process_event() |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
281 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
282 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
283 |
def build_customer_list (self) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
284 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
285 |
Query a (id, name) list of customers. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
286 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
287 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
288 |
sql = db.select([db.customers.c.id, db.customers.c.name]) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
289 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
290 |
return self.app.query(sql) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
291 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
292 |
def build_contact_list (self, customer_id=None) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
293 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
294 |
Query a (id, name, phone, email) list of contacts, optionally for given customer if given. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
295 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
296 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
297 |
sql = db.select([db.contacts.c.id, db.contacts.c.name, db.contacts.c.phone, db.contacts.c.email]) |
7 | 298 |
|
299 |
if customer_id : |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
300 |
sql = sql.where((db.contacts.c.customer == customer_id)) |
7 | 301 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
302 |
return self.app.query(sql) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
303 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
304 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
305 |
def render_text_input (self, name, value=None, multiline=False) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
306 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
307 |
Render HTML for a generic text field input. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
308 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
309 |
name - field name, as used for POST |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
310 |
value - default field value |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
311 |
multiline - use a multi-line <textarea> instead |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
312 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
313 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
314 |
if multiline : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
315 |
# XXX: textarea can't be self-closing for some reason? |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
316 |
return tags.textarea(name=name, id=name, _selfclosing=False, _whitespace_sensitive=True)(value) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
317 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
318 |
else : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
319 |
return tags.input(type='text', name=name, id=name, value=value) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
320 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
321 |
def render_select_input (self, name, options, value=None) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
322 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
323 |
Render HTML for a generic select control. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
324 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
325 |
name - field name, as used for POST |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
326 |
options - sequence of (value, title) options. `value` may be None to omit. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
327 |
value - the selected value |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
328 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
329 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
330 |
return tags.select(name=name, id=name)( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
331 |
( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
332 |
tags.option(value=opt_value, selected=('selected' if opt_value == value else None))(opt_title) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
333 |
) for opt_value, opt_title in options |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
334 |
) |
7 | 335 |
|
336 |
def render_customer_input (self) : |
|
337 |
""" |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
338 |
Render HTML for customer_id/name field inputs. |
7 | 339 |
""" |
340 |
||
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
341 |
# all known customers |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
342 |
customers = self.build_customer_list() |
7 | 343 |
|
344 |
return ( |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
345 |
self.render_select_input('customer_id', customers, self.customer_id), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
346 |
self.render_text_input('customer_name', self.customer_name), |
7 | 347 |
|
348 |
tags.script(r"$(document).ready(function () { $('#customer_id').formSelectPreset({textTarget: $('#customer_name')}); });"), |
|
349 |
) |
|
350 |
||
351 |
def render_contact_input (self) : |
|
352 |
""" |
|
353 |
Render HTML for contact name field <input>s |
|
354 |
""" |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
355 |
# recommended contacts for selected customer, if known |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
356 |
contacts = self.get_contact_list(self.customer_id) |
7 | 357 |
|
358 |
return ( |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
359 |
self.render_select_input('contact_id', ((id, name) for id, name, phone, email in contacts), self.contact_id) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
360 |
self.render_text_input('contact_name', self.contact_name), |
7 | 361 |
|
362 |
tags.script(r"$(document).ready(function () { $('#contact_id').formSelectPreset({textTarget: $('#contact_name')}); });"), |
|
363 |
) |
|
364 |
||
365 |
def render_event_input (self) : |
|
366 |
""" |
|
367 |
Render HTML for event start/end field <input>s |
|
368 |
""" |
|
369 |
||
370 |
return ( |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
371 |
self.render_text_input('event_start', (self.event_start.strftime(self.DATETIME_FORMAT) if event_start else None)), |
7 | 372 |
" - ", |
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
373 |
self.render_text_input('event_end', (self.event_end.strftime(self.DATETIME_FORMAT) if event_end else None)), |
7 | 374 |
|
375 |
tags.script(r""" |
|
376 |
$(document).ready(function () { |
|
377 |
var event_start = $('#event_start'); |
|
378 |
var event_end = $('#event_end'); |
|
379 |
||
380 |
event_start.datetimepicker(); |
|
381 |
event_end.datetimepicker(); |
|
382 |
||
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
383 |
/* Buggy shit doesn't work |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
384 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
385 |
{ |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
386 |
beforeShow: function (input, inst) { |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
387 |
// copy default value from event_start |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
388 |
event_end.datetimepicker("option", "defaultDate", event_start.datetimepicker("getDate")); |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
389 |
} |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
390 |
} |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
391 |
|
7 | 392 |
event_start.change(function () { |
393 |
// copy value as default |
|
394 |
var start_date = event_start.datetimepicker("getDate"); |
|
395 |
||
396 |
event_end.datetimepicker("option", "defaultDate", start_date); |
|
397 |
}); |
|
398 |
||
399 |
// init default as well |
|
400 |
event_start.change(); |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
401 |
*/ |
7 | 402 |
});""" ), |
403 |
||
404 |
) |
|
405 |
||
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
406 |
def render_form_field (self, name, title, description, inputs) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
407 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
408 |
Render the label, input control, error note and description for a single field, along with their containing <li>. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
409 |
""" |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
410 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
411 |
return tags.li(class_='field')( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
412 |
tags.label(title, for_=name), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
413 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
414 |
inputs, |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
415 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
416 |
# XXX: somewhere where we tag these! |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
417 |
# tags.span("Error!"), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
418 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
419 |
tags.p(description), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
420 |
) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
421 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
422 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
423 |
def render (self, action, submit=u"Tallenna") : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
424 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
425 |
Render the entire <form>, using any loaded/processed values. |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
426 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
427 |
action - the target URL for the form to POST to |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
428 |
submit - label for the submit button |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
429 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
430 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
431 |
return tags.form(action=action, method='POST')( |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
432 |
tags.fieldset( |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
433 |
tags.legend(u"Tilaaja"), |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
434 |
|
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
435 |
tags.ol( |
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
436 |
self.render_form_field('customer_name', u"Tilaaja", u"Tilaavan yhdistyksen/henkilön nimi", ( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
437 |
self.render_customer_input() |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
438 |
)), |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
439 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
440 |
self.render_form_field('contact_name', u"Yhteyshenkilö", u"Yhteyshenkilön nimi, jos eri kun tilaaja", ( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
441 |
self.render_contact_input() |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
442 |
)), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
443 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
444 |
self.render_form_field('contact_phone', u"Puhelin", u"Yhteyshenkilön puhelinnumero", ( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
445 |
self.render_text_input('contact_phone', self.contact_phone) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
446 |
)), |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
447 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
448 |
self.render_form_field('contact_email', u"Sähköposti", u"Yhteyshenkilön sähköpostiosoite", ( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
449 |
self.render_text_input('contact_email', self.contact_email) |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
450 |
)), |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
451 |
), |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
452 |
), |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
453 |
|
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
454 |
tags.fieldset( |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
455 |
tags.legend(u"Tapahtuma"), |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
456 |
|
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
457 |
tags.ol( |
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
458 |
self.render_form_field('event_name', u"Tapahtuma", u"Tapahtuman lyhyt nimi", ( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
459 |
self.render_text_input('event_name', self.event_name) |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
460 |
)), |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
461 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
462 |
self.render_form_field('event_description', u"Lisätiedot", u"Tapahtuman tarkemmat tiedot", ( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
463 |
self.render_text_input('event_description', self.event_description, multiline=True) |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
464 |
)), |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
465 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
466 |
self.render_form_field('event_start', u"Ajankohta", u"Tapahtuman ajankohta (kamat noudetaan - palautetaan)", ( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
467 |
self.render_event_input() |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
468 |
)), |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
469 |
), |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
470 |
), |
7 | 471 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
472 |
tags.input(type='submit', value=submit), |
6
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
473 |
) |
72c73df76db2
Split wsgi.py into controllers/customers/urls for now; start orders form
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
474 |
|
9
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
475 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
476 |
class OrdersView (PageHandler) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
477 |
def render (self) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
478 |
return tags.h1("Orders list") |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
479 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
480 |
class OrderView (PageHandler) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
481 |
def render (self, id) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
482 |
return tags.h1("Order info for #%d" % (id, )) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
483 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
484 |
class NewOrderView (PageHandler) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
485 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
486 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
487 |
""" |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
488 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
489 |
def render (self) : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
490 |
if self.POST : |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
491 |
print self.POST |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
492 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
493 |
# |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
494 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
495 |
# if we've gotten this far, then we can create it! |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
496 |
sql = db.insert(db.orders).values( |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
497 |
customer = customer_id, |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
498 |
contact = contact_id, |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
499 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
500 |
event_name = event_name, |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
501 |
event_description = event_description, |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
502 |
event_start = event_start, |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
503 |
event_end = event_end, |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
504 |
) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
505 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
506 |
# go! |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
507 |
order_id, = self.app.insert(sql) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
508 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
509 |
# ok, we don't need the /new URL anymore, we can just show the order page |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
510 |
return self.redirect_for(OrderView, id=order_id) |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
511 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
512 |
# render form |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
513 |
return self.render_form() |
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
514 |
|
0327b83959e9
Implement working NewOrderView, and start restructuring it again right away...
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
515 |