Skip to content

Commit

Permalink
Made forms more complete for other metric types
Browse files Browse the repository at this point in the history
  • Loading branch information
u8sand committed Dec 11, 2018
1 parent 0892021 commit 7f28e1d
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions FAIRshakeAPI/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def __init__(self, *args, **kwargs):
('0.0', 'No'),
],
coerce=lambda v: float(v),
empty_value='',
widget=forms.RadioSelect(),
required=True,
)),
])
elif self.instance.metric.type == 'yesnobut':
Expand All @@ -132,8 +134,10 @@ def __init__(self, *args, **kwargs):
('0.25', 'No, but'),
('0.0', 'No'),
],
coerce=lambda v: float(v),
coerce=lambda v: float('nan') if v == '' else float(v),
empty_value='',
widget=forms.RadioSelect(),
required=True,
)),
('url_comment', forms.CharField(
widget=forms.Textarea(
Expand All @@ -159,35 +163,57 @@ def __init__(self, *args, **kwargs):
('answer', fields.TypedChoiceField(
choices=[
('1.0', 'Yes'),
('0.50', 'Maybe'),
('0.5', 'Maybe'),
('0.0', 'No'),
],
coerce=lambda v: float(v),
empty_value='',
widget=forms.RadioSelect(),
required=True,
)),
])
elif self.instance.metric.type == 'url':
self.fields = OrderedDict([
('answer', fields.TypedChoiceField(
choices=[
('1.0', 'Yes'),
('0.0', 'No'),
],
coerce=lambda v: float(v),
empty_value='',
widget=forms.RadioSelect(),
required=True,
)),
('url_comment', forms.CharField(
widget=forms.Textarea(
attrs={
'placeholder': 'Enter URLs, if applicable and available. Separate URLs by spaces or new lines.',
'rows': '2',
},
),
required=False,
required=True,
)),
])
elif self.instance.metric.type == 'text':
self.fields = OrderedDict([
('answer', fields.TypedChoiceField(
choices=[
('1.0', 'Yes'),
('0.0', 'No'),
],
coerce=lambda v: float(v),
empty_value='',
widget=forms.RadioSelect(),
required=True,
)),
('comment', forms.CharField(
widget=forms.Textarea(
attrs={
'placeholder': 'Please explain or describe your answer.',
'rows': '2',
},
),
required=False,
required=True,
)),
])
else:
Expand All @@ -197,6 +223,8 @@ class Meta:
model = models.Answer
fields = (
'answer',
'comment',
'url_comment',
)

class AssessmentRequestForm(forms.ModelForm):
Expand Down

0 comments on commit 7f28e1d

Please sign in to comment.