added function that displays data values

This commit is contained in:
Rupika 2019-02-07 18:13:32 -08:00
parent 9552589e24
commit f19781a682
3 changed files with 28 additions and 1 deletions

View file

@ -61,6 +61,7 @@ flight_section = Section(
"departure_date": {"label": "Departure date", "type": "date"},
"return_date": {"label": "Return date", "type": "date"},
"fare": {"label": "Fare", "type": "decimal"},
"layovers": {"label": "Transit wait", "type": "integer"},
}
)

View file

@ -49,13 +49,16 @@ def get_fields(s_id):
# create dict of arrays for fields
field_set = {"fields": []}
queryset = Field.objects.filter(section_id=s_id).order_by('number')
for i in queryset:
# function to print corresponding datatype
key, value = get_datatype(i)
data = {
"field_name": i.field_name,
"label": i.label,
"type": i.type,
"number": i.number,
"value": "i.to_json()",
key: value
}
# append the fields to array
# use copy() to avoid overwriting
@ -63,6 +66,29 @@ def get_fields(s_id):
return field_set
# function to convert value into JSON
def to_json(convert):
return {"value": convert}
# function that gets corresponding
# data type
def get_datatype(self):
if self.type == "boolean":
if self.data_bool:
return "data_bool", True
else:
return "data_bool", False
elif self.type == "decimal":
return "decimal", self.data_decimal
elif self.type == "date":
return "date", "{}".format(self.data_date)
elif self.type == "file":
return "file", "{}".format(self.data_file)
elif self.type == "string":
return "string", "{}".format(self.data_string)
elif self.type == "integer":
return "integer", self.data_integer
# API Endpoints
@api_view(['POST'])

Binary file not shown.