commit
b052bfea3c
5 changed files with 89 additions and 15 deletions
18
back/backend/migrations/0006_auto_20190213_2113.py
Normal file
18
back/backend/migrations/0006_auto_20190213_2113.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.1.5 on 2019-02-14 05:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('backend', '0005_field_field_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='field',
|
||||
name='data_date',
|
||||
field=models.DateField(blank=True, null=True),
|
||||
),
|
||||
]
|
14
back/backend/migrations/0007_merge_20190213_2318.py
Normal file
14
back/backend/migrations/0007_merge_20190213_2318.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Generated by Django 2.1.5 on 2019-02-14 07:18
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('backend', '0006_auto_20190213_1719'),
|
||||
('backend', '0006_auto_20190213_2113'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
|
@ -34,7 +34,7 @@ class Field(models.Model):
|
|||
completed = 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_date = models.DateField(default=datetime.date.today)
|
||||
data_date = models.DateField(null=True, blank=True)
|
||||
data_file = models.FileField(upload_to='uploads/%Y/%m/%d/', max_length=512, null=True, blank=True)
|
||||
data_string = models.TextField(default='', blank=True)
|
||||
data_integer = models.IntegerField(default=0, blank=True)
|
||||
|
|
|
@ -57,7 +57,8 @@ def get_fields(s_id):
|
|||
"label": i.label,
|
||||
"field_type": i.field_type,
|
||||
"number": i.number,
|
||||
"value": value
|
||||
"value": value,
|
||||
"id": i.id,
|
||||
}
|
||||
# append the fields to array
|
||||
# use copy() to avoid overwriting
|
||||
|
@ -155,20 +156,61 @@ def report_detail(request, report_pk):
|
|||
@api_view(['PUT'])
|
||||
def section(request, report_pk, section_pk):
|
||||
|
||||
""" original stub
|
||||
data = {
|
||||
"message": "Updated report {0}, section {1}.".format(report_pk, section_pk),
|
||||
"fields": {
|
||||
"international": True,
|
||||
"travel_date": "2012-04-23T18:25:43.511Z",
|
||||
"fare": "1024.99",
|
||||
"lowest_fare_screenshot": "image",
|
||||
}
|
||||
}
|
||||
"""
|
||||
for key in request.data:
|
||||
# get the matching field object
|
||||
update = Field.objects.get(section_id=section_pk, field_name=key)
|
||||
|
||||
if update.field_type == "boolean":
|
||||
# flight check
|
||||
if request.data[key] == "on":
|
||||
update.data_bool = True
|
||||
elif request.data[key] == "off":
|
||||
update.data_bool = False
|
||||
# everything else
|
||||
else:
|
||||
update.data_bool = request.data[key]
|
||||
|
||||
if update.field_type == "decimal":
|
||||
# initialize to 0
|
||||
if (
|
||||
request.data[key] == "" or
|
||||
request.data[key] is None
|
||||
):
|
||||
update.data_decimal = 0.0
|
||||
else:
|
||||
update.data_decimal = request.data[key]
|
||||
|
||||
if update.field_type == "date":
|
||||
# initialize to today's date
|
||||
if (
|
||||
request.data[key] == "" or
|
||||
request.data[key] is None
|
||||
):
|
||||
update.data_date = None
|
||||
else:
|
||||
update.data_date = request.data[key]
|
||||
|
||||
if update.field_type == "file":
|
||||
update.data_file = request.data[key]
|
||||
|
||||
if update.field_type == "string":
|
||||
update.data_string = request.data[key]
|
||||
|
||||
if update.field_type == "integer":
|
||||
# initialize to 0
|
||||
if (
|
||||
request.data[key] == "" or
|
||||
request.data[key] is None
|
||||
):
|
||||
update.data_integer = 0
|
||||
else:
|
||||
update.data_integer = request.data[key]
|
||||
|
||||
update.save()
|
||||
|
||||
data = {
|
||||
"message": "Updated report {0}, section {1}.".format(report_pk, section_pk),
|
||||
"request_data": request.data
|
||||
}
|
||||
|
||||
return JsonResponse(data)
|
||||
|
||||
|
|
BIN
back/db.sqlite3
BIN
back/db.sqlite3
Binary file not shown.
Loading…
Reference in a new issue