fix db conflict?

This commit is contained in:
Rupika 2019-02-13 23:09:57 -08:00
commit c69ad9d9ad
6 changed files with 51 additions and 33 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 2.1.5 on 2019-02-14 01:19
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('backend', '0005_field_field_name'),
]
operations = [
migrations.RenameField(
model_name='field',
old_name='type',
new_name='field_type',
),
]

View file

@ -30,7 +30,7 @@ class Field(models.Model):
field_name = models.CharField(max_length=512, default="field") field_name = models.CharField(max_length=512, default="field")
label = models.CharField(max_length=512) label = models.CharField(max_length=512)
number = models.IntegerField() number = models.IntegerField()
type = models.CharField(max_length=128) field_type = models.CharField(max_length=128)
completed = models.BooleanField(default=False) completed = models.BooleanField(default=False)
data_bool = models.BooleanField(default=False) data_bool = models.BooleanField(default=False)
data_decimal = models.DecimalField(max_digits=9, decimal_places=2, null=True, blank=True) data_decimal = models.DecimalField(max_digits=9, decimal_places=2, null=True, blank=True)
@ -42,41 +42,41 @@ class Field(models.Model):
# function that prints the string representation # function that prints the string representation
# on the api? # on the api?
def __str__(self): def __str__(self):
if self.type == "boolean": if self.field_type == "boolean":
if self.data_bool: if self.data_bool:
return "True" return "True"
else: else:
return "False" return "False"
elif self.type == "decimal": elif self.field_type == "decimal":
return "{}".format(self.data_decimal) return "{}".format(self.data_decimal)
elif self.type == "date": elif self.field_type == "date":
return "{}".format(self.data_date) return "{}".format(self.data_date)
elif self.type == "file": elif self.field_type == "file":
return "{}".format(self.data_file) return "{}".format(self.data_file)
elif self.type == "string": elif self.field_type == "string":
return "{}".format(self.data_string) return "{}".format(self.data_string)
elif self.type == "integer": elif self.field_type == "integer":
return "{}".format(self.data_integer) return "{}".format(self.data_integer)
# function that gets corresponding # function that gets corresponding
# data type # data type
def get_datatype(self): def get_datatype(self):
if self.type == "boolean": if self.field_type == "boolean":
if self.data_bool: if self.data_bool:
return True return True
else: else:
return False return False
elif self.type == "decimal": elif self.field_type == "decimal":
return self.data_decimal return self.data_decimal
elif self.type == "date": elif self.field_type == "date":
return "{}".format(self.data_date) return "{}".format(self.data_date)
elif self.type == "file": elif self.field_type == "file":
file_name = self.path_leaf(str(self.data_file)) file_name = self.path_leaf(str(self.data_file))
return "{}".format(file_name) return "{}".format(file_name)
elif self.type == "string": elif self.field_type == "string":
return "{}".format(self.data_string) return "{}".format(self.data_string)
elif self.type == "integer": elif self.field_type == "integer":
return self.data_integer return self.data_integer
# function that accommodates if # function that accommodates if

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", "type": "string"}, "destination": {"label": "Destination City", "field_type": "string"},
} }
) )
@ -57,11 +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?", "type": "boolean"}, "international": {"label": "Is this an international flight?", "field_type": "boolean"},
"departure_date": {"label": "Departure date", "type": "date"}, "departure_date": {"label": "Departure date", "field_type": "date"},
"return_date": {"label": "Return date", "type": "date"}, "return_date": {"label": "Return date", "field_type": "date"},
"fare": {"label": "Fare", "type": "decimal"}, "fare": {"label": "Fare", "field_type": "decimal"},
"layovers": {"label": "Transit wait", "type": "integer"}, "layovers": {"label": "Transit wait", "field_type": "integer"},
"fare_search_screenshot": {"label": "Screenshot of fare search", "field_type": "file"},
} }
) )
@ -80,10 +81,10 @@ lodging_section = Section(
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'>this link</a></p>",
fields={ fields={
"check-in_date": {"label": "Check-in date", "type": "date"}, "check-in_date": {"label": "Check-in date", "field_type": "date"},
"check-out_date": {"label": "Check-out date", "type": "date"}, "check-out_date": {"label": "Check-out date", "field_type": "date"},
"rate": {"label": "Per diem nightly rate", "type": "decimal"}, "rate": {"label": "Per diem nightly rate", "field_type": "decimal"},
"cost": {"label": "Total Cost", "type": "decimal"} "cost": {"label": "Total Cost", "field_type": "decimal"}
} }
) )
@ -107,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?", "type": "decimal"}, "duration": {"label": "How many days was your trip?", "field_type": "decimal"},
"cost": {"label": "Total cost", "type": "decimal"} "cost": {"label": "Total cost", "field_type": "decimal"}
} }
) )
@ -127,9 +128,9 @@ per_diem_section = Section(
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'>this link</a></p>",
fields={ fields={
"duration": {"label": "How many days was your trip?", "type": "decimal"}, "duration": {"label": "How many days was your trip?", "field_type": "decimal"},
"rate": {"label": "What is the per diem rate for your destination?", "type": "decimal"}, "rate": {"label": "What is the per diem rate for your destination?", "field_type": "decimal"},
"cost": {"label": "Total Cost for meals and incidentals", "type": "decimal"} "cost": {"label": "Total Cost for meals and incidentals", "field_type": "decimal"}
} }
) )

View file

@ -55,7 +55,7 @@ def get_fields(s_id):
data = { data = {
"field_name": i.field_name, "field_name": i.field_name,
"label": i.label, "label": i.label,
"type": i.type, "field_type": i.field_type,
"number": i.number, "number": i.number,
"value": value, "value": value,
"id": i.id, "id": i.id,
@ -93,7 +93,7 @@ def report(request):
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, type=field['type'], completed=False) number=j, field_type=field['field_type'], completed=False)
f.save() f.save()
j = j+1 j = j+1
@ -210,7 +210,6 @@ def section(request, report_pk, section_pk):
data = { data = {
"message": "Updated report {0}, section {1}.".format(report_pk, section_pk), "message": "Updated report {0}, section {1}.".format(report_pk, section_pk),
"request.data": request.data
} }
return JsonResponse(data) return JsonResponse(data)

Binary file not shown.

View file

@ -72,7 +72,7 @@ function createFormGroup(field) {
input.name = field.field_name; input.name = field.field_name;
input.id = field.field_name; input.id = field.field_name;
switch(field.type) { switch(field.field_type) {
case "boolean": case "boolean":
input.type = "checkbox"; input.type = "checkbox";
if (field.value === true) if (field.value === true)
@ -242,7 +242,7 @@ function createReportForm(parsedData, type) {
let field = fields[key]; let field = fields[key];
console.log("Field label: " + field.label); console.log("Field label: " + field.label);
console.log("Field type: " + field.type); console.log("Field type: " + field.field_type);
console.log("Field value: " + field.value); console.log("Field value: " + field.value);
// Create a form group for each field and add it to the form // Create a form group for each field and add it to the form