Merge pull request #82 from danieldupriest/in-order-fields

Added 'number' attribute to fields in the policy file, so they actually sort
This commit is contained in:
rupikad 2019-02-15 22:28:07 -08:00 committed by GitHub
commit 14a77c95ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 21 deletions

View file

@ -39,7 +39,7 @@ general_section = Section(
title="General Info", title="General Info",
html_description="", html_description="",
fields={ fields={
"destination": {"label": "Destination City", "field_type": "string"}, "destination": {"number": 0, "label": "Destination City", "field_type": "string"},
} }
) )
@ -57,12 +57,12 @@ flight_section = Section(
title="Flight Info", title="Flight Info",
html_description="<p>Enter flight details here.</p>", html_description="<p>Enter flight details here.</p>",
fields={ fields={
"international": {"label": "Is this an international flight?", "field_type": "boolean"}, "international": {"number": 0, "label": "Is this an international flight?", "field_type": "boolean"},
"departure_date": {"label": "Departure date", "field_type": "date"}, "departure_date": {"number": 1, "label": "Departure date", "field_type": "date"},
"return_date": {"label": "Return date", "field_type": "date"}, "return_date": {"number": 2, "label": "Return date", "field_type": "date"},
"fare": {"label": "Fare", "field_type": "decimal"}, "fare": {"number": 3, "label": "Fare", "field_type": "decimal"},
"layovers": {"label": "Transit wait", "field_type": "integer"}, "layovers": {"number": 4, "label": "Transit wait", "field_type": "integer"},
"fare_search_screenshot": {"label": "Screenshot of fare search", "field_type": "file"}, "fare_search_screenshot": {"number": 5, "label": "Screenshot of fare search", "field_type": "file"},
} }
) )
@ -79,12 +79,12 @@ pol.add_section(flight_section)
lodging_section = Section( lodging_section = Section(
title="Hotel Info", title="Hotel Info",
html_description="<p>Enter hotel info here.\nPer diem rates can be found at " html_description="<p>Enter hotel info here.\nPer diem rates can be found at "
"<a href='https://www.gsa.gov/travel/plan-book/per-diem-rates'>this link</a></p>", "<a href='https://www.gsa.gov/travel/plan-book/per-diem-rates' target='_blank'>this link</a></p>",
fields={ fields={
"check-in_date": {"label": "Check-in date", "field_type": "date"}, "check-in_date": {"number": 0, "label": "Check-in date", "field_type": "date"},
"check-out_date": {"label": "Check-out date", "field_type": "date"}, "check-out_date": {"number": 1, "label": "Check-out date", "field_type": "date"},
"rate": {"label": "Per diem nightly rate", "field_type": "decimal"}, "rate": {"number": 2, "label": "Per diem nightly rate", "field_type": "decimal"},
"cost": {"label": "Total Cost", "field_type": "decimal"} "cost": {"number": 3, "label": "Total Cost", "field_type": "decimal"}
} }
) )
@ -108,8 +108,8 @@ transport_section = Section(
title="Local Transportation", title="Local Transportation",
html_description="<p>How much did you spend on local transportation, in total?</p>", html_description="<p>How much did you spend on local transportation, in total?</p>",
fields={ fields={
"duration": {"label": "How many days was your trip?", "field_type": "integer"}, "duration": {"number":0, "label": "How many days was your trip?", "field_type": "integer"},
"cost": {"label": "Total cost", "field_type": "decimal"} "cost": {"number":1, "label": "Total cost", "field_type": "decimal"}
} }
) )
@ -126,11 +126,11 @@ pol.add_section(transport_section)
per_diem_section = Section( per_diem_section = Section(
title="Per Diem", title="Per Diem",
html_description="<p>Enter info about meals and incidentals here.\nPer diem rates can be found at " html_description="<p>Enter info about meals and incidentals here.\nPer diem rates can be found at "
"<a href='https://www.gsa.gov/travel/plan-book/per-diem-rates'>this link</a></p>", "<a href='https://www.gsa.gov/travel/plan-book/per-diem-rates' target='_blank'>this link</a></p>",
fields={ fields={
"duration": {"label": "How many days was your trip?", "field_type": "integer"}, "duration": {"number":0, "label": "How many days was your trip?", "field_type": "integer"},
"rate": {"label": "What is the per diem rate for your destination?", "field_type": "decimal"}, "rate": {"number":1, "label": "What is the per diem rate for your destination?", "field_type": "decimal"},
"cost": {"label": "Total Cost for meals and incidentals", "field_type": "decimal"} "cost": {"number":2,"label": "Total Cost for meals and incidentals", "field_type": "decimal"}
} }
) )

View file

@ -116,13 +116,11 @@ def report(request):
s.save() s.save()
# Create the fields # Create the fields
j = 0
for key in section.fields: for key in section.fields:
field = section.fields[key] field = section.fields[key]
f = Field.objects.create(section_id=s, field_name=key, label=field['label'], f = Field.objects.create(section_id=s, field_name=key, label=field['label'],
number=j, field_type=field['field_type'], completed=False) number=field['number'], field_type=field['field_type'], completed=False)
f.save() f.save()
j = j+1
# Return the newly created report # Return the newly created report
data = get_reports(report.id) data = get_reports(report.id)