-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
130 lines (116 loc) · 3.52 KB
/
forms.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
"""Module that defines forms used in hole calc's three pin, reverse and pin size calculators.
Forms are composed here using WTForms and Flask-WTF"""
from flask_wtf import FlaskForm
from wtforms import DecimalField, RadioField, SelectField, SubmitField
from wtforms.validators import DataRequired, NumberRange
class PinSizeDecimal(DecimalField):
"""Defines pin gage diameter input fields"""
def __init__(self, pin_number: int, **kwargs):
super().__init__(
label=f'Pin {pin_number}',
validators=[DataRequired(),
NumberRange(min=0.00001,
max=9999,
message="Input value must be at least %(min)s")],
**kwargs
)
class PinClassSelect(SelectField):
"""Defines drop-down selection fields for pin gage tolerance classes"""
def __init__(self, pin_number: int, **kwargs):
super().__init__(
label=f'Pin {pin_number} Class',
choices=[
('ZZ', 'ZZ'),
('Z', 'Z'),
('Y', 'Y'),
('X', 'X'),
('XX', 'XX'),
],
default='ZZ',
**kwargs
)
class PinSignSelect(SelectField):
"""Defines drop-down selection fields for pin gage class sign (plus or minus)"""
def __init__(self, pin_number: int, **kwargs):
super().__init__(
label=f'Pin {pin_number} Sign',
choices=[
('+', '+'),
('-', '-')
],
default='-',
**kwargs
)
class ThreePinForm(FlaskForm):
"""Defines input form for three pin bore diameter calculator"""
tol_radio = RadioField(
label='Tolerance',
choices=[
('nom', 'Nominal'),
('tol', 'Tolerance')
],
default='nom'
)
pin1 = PinSizeDecimal(1)
pin2 = PinSizeDecimal(2)
pin3 = PinSizeDecimal(3)
pin1_class = PinClassSelect(1)
pin2_class = PinClassSelect(2)
pin3_class = PinClassSelect(3)
pin1_sign = PinSignSelect(1)
pin2_sign = PinSignSelect(2)
pin3_sign = PinSignSelect(3)
units = SelectField(
label='Units',
choices=[
('in', 'IN'),
('mm', 'MM')
]
)
precision = SelectField(
label='Precision',
choices=[
('0.1', '0.1'),
('0.01', '0.01'),
('0.001', '0.001'),
('0.0001', '0.0001'),
],
default='0.001'
)
calculate = SubmitField('Calculate')
class ReverseForm(FlaskForm):
"""Defines input form for two pin/reverse calculator"""
pin1 = PinSizeDecimal(1)
pin2 = PinSizeDecimal(2)
bore = DecimalField(label='Bore', validators=[DataRequired()])
units = SelectField(
label='Units',
choices=[
('in', 'IN'),
('mm', 'MM')
]
)
precision = SelectField(
label='Precision',
choices=[
('0.1', '0.1'),
('0.01', '0.01'),
('0.001', '0.001'),
('0.0001', '0.0001'),
],
default='0.001'
)
calculate = SubmitField('Calculate')
class PinSizeForm(FlaskForm):
"""Defines input form for gage pin diameter calculator"""
pin_dia = PinSizeDecimal(1)
pin_class = PinClassSelect(1)
pin_sign = PinSignSelect(1)
units = SelectField(
label='Units',
choices=[
('in', 'IN'),
('mm', 'MM')
]
)
calculate = SubmitField('Calculate')