Skip to content

Commit

Permalink
Merge pull request #184 from wasade/add_shortname
Browse files Browse the repository at this point in the history
Track the question_shortname in the vue form
  • Loading branch information
wasade committed Jun 4, 2020
2 parents a5f6e88 + 7651932 commit c3b2fa4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
32 changes: 21 additions & 11 deletions microsetta_private_api/model/vue/vue_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class VueField:
# There are also additional properties dependent on the type
def __init__(self, type_, label, model, id_, input_name, featured, visible,
disabled, required, multi, default, hint, help_, validator,
validate_debounce_time, style_classes, buttons, attributes):
validate_debounce_time, style_classes, buttons, attributes,
shortname):
# Type of Vue field displayed to user
self.type = type_
# Label of the field
Expand Down Expand Up @@ -50,6 +51,8 @@ def __init__(self, type_, label, model, id_, input_name, featured, visible,
self.buttons = buttons
# Additional attributes to add to the field
self.attributes = attributes
# the question shortname if applicable
self.shortname = shortname

def set(self, **attributes):
for key in attributes:
Expand All @@ -58,7 +61,7 @@ def set(self, **attributes):


class VueInputField(VueField):
def __init__(self, question_id, question_text):
def __init__(self, question_id, question_text, question_shortname=None):
super().__init__(
type_="input",
label=question_text,
Expand All @@ -77,13 +80,14 @@ def __init__(self, question_id, question_text):
validate_debounce_time=None,
style_classes=None,
buttons=None,
attributes=None
attributes=None,
shortname=question_shortname
)
self.inputType = "text"


class VueTextAreaField(VueField):
def __init__(self, question_id, question_text):
def __init__(self, question_id, question_text, question_shortname=None):
super().__init__(
type_="textArea",
label=question_text,
Expand All @@ -102,7 +106,8 @@ def __init__(self, question_id, question_text):
validate_debounce_time=None,
style_classes=None,
buttons=None,
attributes=None
attributes=None,
shortname=question_shortname
)
self.autocomplete = None
self.max = None
Expand All @@ -113,7 +118,8 @@ def __init__(self, question_id, question_text):


class VueSelectField(VueField):
def __init__(self, question_id, question_text, valid_responses):
def __init__(self, question_id, question_text, valid_responses,
question_shortname=None):
super().__init__(
type_="select",
label=question_text,
Expand All @@ -132,7 +138,8 @@ def __init__(self, question_id, question_text, valid_responses):
validate_debounce_time=None,
style_classes=None,
buttons=None,
attributes=None
attributes=None,
shortname=question_shortname
)
self.values = valid_responses
self.selectOptions = {
Expand All @@ -142,7 +149,8 @@ def __init__(self, question_id, question_text, valid_responses):


class VueChecklistField(VueField):
def __init__(self, question_id, question_text, valid_responses):
def __init__(self, question_id, question_text, valid_responses,
question_shortname=None):
super().__init__(
type_="checklist",
label=question_text,
Expand All @@ -161,15 +169,16 @@ def __init__(self, question_id, question_text, valid_responses):
validate_debounce_time=None,
style_classes=None,
buttons=None,
attributes=None
attributes=None,
shortname=question_shortname
)
self.listBox = False
self.values = valid_responses
self.selectOptions = {}


class VueDateTimePickerField(VueField):
def __init__(self, question_id, question_text):
def __init__(self, question_id, question_text, question_shortname=None):
super().__init__(
type_="dateTimePicker",
label=question_text,
Expand All @@ -188,7 +197,8 @@ def __init__(self, question_id, question_text):
validate_debounce_time=None,
style_classes=None,
buttons=None,
attributes=None
attributes=None,
shortname=question_shortname
)
self.dateTimePickerOptions = {
"format": "YYYY-MM-DD HH:mm:ss"
Expand Down
14 changes: 10 additions & 4 deletions microsetta_private_api/util/vue_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ def to_vue_field(question, triggered_by=None):
if question.response_type == "SINGLE":
vue_field = VueSelectField(question.id,
question.localized_text,
question.valid_responses)
question.valid_responses,
question.short_name)
elif question.response_type == "MULTIPLE":
vue_field = VueChecklistField(question.id,
question.localized_text,
question.valid_responses)
question.valid_responses,
question.short_name)
elif question.response_type == "STRING":
vue_field = VueInputField(question.id, question.localized_text)
vue_field = VueInputField(question.id,
question.localized_text,
question.short_name)
elif question.response_type == "TEXT":
vue_field = VueTextAreaField(question.id, question.localized_text)
vue_field = VueTextAreaField(question.id,
question.localized_text,
question.short_name)
else:
raise ValueError("Unknown question response_type %s" %
question.response_type)
Expand Down

0 comments on commit c3b2fa4

Please sign in to comment.