From 9552589e24be1317c77d9e2355c7d6c05c539744 Mon Sep 17 00:00:00 2001 From: Rupika Date: Thu, 7 Feb 2019 17:13:43 -0800 Subject: [PATCH 1/3] added filter by user_id -- now reports only display based on user id --- back/backend/policy.py | 6 ++++-- back/backend/views.py | 5 +++-- back/db.sqlite3 | Bin 97280 -> 97280 bytes 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/back/backend/policy.py b/back/backend/policy.py index 1131e30..d40f56e 100644 --- a/back/backend/policy.py +++ b/back/backend/policy.py @@ -12,7 +12,8 @@ class Policy(): class Section(): - def __init__(self, title="Section", html_description="", required=False, auto_submit=False, fields={}): + def __init__(self, title="Section", html_description="", required=False, + auto_submit=False, fields={}): self.title = title self.html_description = html_description self.required = required @@ -75,7 +76,8 @@ pol.add_section(flight_section) #### Section 2 lodging_section = Section( title="Hotel Info", - html_description="

Enter hotel info here.\nPer diem rates can be found at

", + html_description="

Enter hotel info here.\nPer diem rates can be found at " + "

", fields={ "check-in_date": {"label": "Check-in date", "type": "date"}, "check-out_date": {"label": "Check-out date", "type": "date"}, diff --git a/back/backend/views.py b/back/backend/views.py index 1c368c2..b04e358 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -2,7 +2,7 @@ from rest_framework.decorators import api_view from django.http import JsonResponse from .models import * from .policy import pol -import json + # function that prints all the reports def get_reports(report_pk): @@ -97,9 +97,10 @@ def report(request): @api_view(['GET']) def reports(request): report_set = {"reports": []} - queryset = Report.objects.all().order_by('date_created') + queryset = Report.objects.all().filter(user_id=request.user.id).order_by('date_created') for i in queryset: data = { + "user_id": request.user.id, "report_pk": i.id, "title": i.title, "date_created": i.date_created, diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 77fd67fd08e54caf24731ac1e3dfd3ef6ad93a2e..fe3ce3eff3b1cdb31aac803e57d19c86f8d8abe2 100644 GIT binary patch delta 3272 zcmeH}du&@*9mmf(KWA~`=H@Y9vvetQnzW6b*uK8kkJziGMz~3n)=rbS4?9oSzG-sp z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^xyeq~YUIqob$Uj@MvOg_>B!#yqiQV614;_bKXP9e=&6P`^hdfR| z#@Ns?*x5a>$xrLkU@|$a5F+$1^cCt7)`c$k7rcfaZs5&-Ntouj=#)uXb;zu|2+vX} z7tr5$ew0eiewM0&1G^G_BTrFr+GiMxs}66|Sj>40W6|k0jQhkMp+YR=1`)dGWP2gu z8ZPyHVLEDzwy!!O&C&K;*cfeh4j7}Uy}27BpN(M}ENtXRlYKQ2GIsHR#I@f}#tB`c zWh1J;Eqp;pz_-Z%wCy-0ZV`jUfjv+AtOkn{!QW^7_^ZCz;AFgcyF%pw@>e^t^v@W5PbOmPFpHykR&%z@^$m1$41Tq8(D$k$7DN~;d!^=`QE&1V?QoT z#@0_t#x5?y{=SxEeeHosXH&91LnX(D`FDqNi&Ui@n2dnEqe0+fcI7k#w6iBsV@GRX zTfC%%H>tI?tMedQoP4R0$n)ut!?9HoOgpWg_>=9-5^QA_<7RdsAI17vtS7J@!+IPO cR^a-58az&I`Aw;%72B3pY+t{#0v)FR0G_7Exc~qF From f19781a68209f5ac0ef1c569c7febb2067c8cb57 Mon Sep 17 00:00:00 2001 From: Rupika Date: Thu, 7 Feb 2019 18:13:32 -0800 Subject: [PATCH 2/3] 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?>w!StC(mKXo-sE&KU3Z4q5_-#grO@wrMm~*Skq_sC(z$ zo_}JZ27CyGQp1)^p{Y${8YQ-1dZb684`=y zKg-N-XMW$`%y)KXqhRJ-;art_kr1MZN4E2OLa=zff3?^bEic7d7|`N_Oi%O~ES)k; zzjesm+k=~&{&|CC7`VC#7*K$E;fOZ!k zKy+GiO7e`&$Z5$*o9Zda3CVHEF`MC0$*iO)nUOSXhDH_?tDr=|hXkMEpZEwL=DZ)@ zM>~do>(M9MN+_<|h4tezT+ewgKEPtpJGNh-XYbdS6a_2roaMN()2g2<&IPX=!D@T5 zKPnlKR3*cbA?xa5uSn=6cnfDShTaA561toG4&vMAgndU2v~^k6mtL~c%N4oU^34^m zf@`(_%@%-8ur0s_C{6 z59r_nf4*Z#1Qn6s%L~I0!LvS0pIhgiFaA1Qy_3{2o8VE>!4! zI!|@l3>#2RekUJ@aLbm=&G#O|LwwFEr<3e*yPe=`jiva^7(_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 -0800 Subject: [PATCH 3/3] changed the data_values to display as just "value" in the JSON data dict --- back/backend/views.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/back/backend/views.py b/back/backend/views.py index 3ef2682..ff7facf 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -52,13 +52,13 @@ def get_fields(s_id): for i in queryset: # function to print corresponding datatype - key, value = get_datatype(i) + value = get_datatype(i) data = { "field_name": i.field_name, "label": i.label, "type": i.type, "number": i.number, - key: value + "value": value } # append the fields to array # use copy() to avoid overwriting @@ -75,19 +75,19 @@ def to_json(convert): def get_datatype(self): if self.type == "boolean": if self.data_bool: - return "data_bool", True + return True else: - return "data_bool", False + return False elif self.type == "decimal": - return "decimal", self.data_decimal + return self.data_decimal elif self.type == "date": - return "date", "{}".format(self.data_date) + return "{}".format(self.data_date) elif self.type == "file": - return "file", "{}".format(self.data_file) + return "{}".format(self.data_file) elif self.type == "string": - return "string", "{}".format(self.data_string) + return "{}".format(self.data_string) elif self.type == "integer": - return "integer", self.data_integer + return self.data_integer # API Endpoints