From f19781a68209f5ac0ef1c569c7febb2067c8cb57 Mon Sep 17 00:00:00 2001 From: Rupika Date: Thu, 7 Feb 2019 18:13:32 -0800 Subject: [PATCH] added function that displays data values --- back/backend/policy.py | 1 + back/backend/views.py | 28 +++++++++++++++++++++++++++- back/db.sqlite3 | Bin 97280 -> 99328 bytes 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/back/backend/policy.py b/back/backend/policy.py index d40f56e..e325284 100644 --- a/back/backend/policy.py +++ b/back/backend/policy.py @@ -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"}, } ) diff --git a/back/backend/views.py b/back/backend/views.py index b04e358..3ef2682 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -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']) diff --git a/back/db.sqlite3 b/back/db.sqlite3 index fe3ce3eff3b1cdb31aac803e57d19c86f8d8abe2..9b7a3db3c49816018aeeb88b745028bf5b925f37 100644 GIT binary patch delta 1215 zcmZvcUq~EB9LMK3ztuZE?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