diff --git a/back/backend/policy.py b/back/backend/policy.py index 1131e30..e325284 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 @@ -60,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"}, } ) @@ -75,7 +77,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..ff7facf 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): @@ -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 + value = get_datatype(i) data = { "field_name": i.field_name, "label": i.label, "type": i.type, "number": i.number, - "value": "i.to_json()", + "value": 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 True + else: + return False + elif self.type == "decimal": + return self.data_decimal + elif self.type == "date": + return "{}".format(self.data_date) + elif self.type == "file": + return "{}".format(self.data_file) + elif self.type == "string": + return "{}".format(self.data_string) + elif self.type == "integer": + return self.data_integer + # API Endpoints @api_view(['POST']) @@ -97,9 +123,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 77fd67f..9b7a3db 100644 Binary files a/back/db.sqlite3 and b/back/db.sqlite3 differ