updated database with field_type
This commit is contained in:
parent
c69ad9d9ad
commit
a2deb2b1bd
3 changed files with 35 additions and 20 deletions
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 = [
|
||||||
|
]
|
|
@ -157,59 +157,60 @@ def report_detail(request, report_pk):
|
||||||
def section(request, report_pk, section_pk):
|
def section(request, report_pk, section_pk):
|
||||||
|
|
||||||
for key in request.data:
|
for key in request.data:
|
||||||
update_field = Field.objects.get(section_id=section_pk, field_name=key)
|
# get the matching field object
|
||||||
|
update = Field.objects.get(section_id=section_pk, field_name=key)
|
||||||
|
|
||||||
if update_field.type == "boolean":
|
if update.field_type == "boolean":
|
||||||
# flight check
|
# flight check
|
||||||
if request.data[key] == "on":
|
if request.data[key] == "on":
|
||||||
update_field.data_bool = True
|
update.data_bool = True
|
||||||
elif request.data[key] == "off":
|
elif request.data[key] == "off":
|
||||||
update_field.data_bool = False
|
update.data_bool = False
|
||||||
# everything else
|
# everything else
|
||||||
else:
|
else:
|
||||||
update_field.data_bool = request.data[key]
|
update.data_bool = request.data[key]
|
||||||
|
|
||||||
if update_field.type == "decimal":
|
if update.field_type == "decimal":
|
||||||
# initialize to 0
|
# initialize to 0
|
||||||
if (
|
if (
|
||||||
request.data[key] == "" or
|
request.data[key] == "" or
|
||||||
request.data[key] is None
|
request.data[key] is None
|
||||||
):
|
):
|
||||||
update_field.data_decimal = 0.0
|
update.data_decimal = 0.0
|
||||||
else:
|
else:
|
||||||
update_field.data_decimal = request.data[key]
|
update.data_decimal = request.data[key]
|
||||||
|
|
||||||
if update_field.type == "date":
|
if update.field_type == "date":
|
||||||
# initialize to today's date
|
# initialize to today's date
|
||||||
if (
|
if (
|
||||||
request.data[key] == "" or
|
request.data[key] == "" or
|
||||||
request.data[key] is None
|
request.data[key] is None
|
||||||
):
|
):
|
||||||
# update_field.data_date = datetime.date.today()
|
update.data_date = None
|
||||||
update_field.data_date = None
|
|
||||||
else:
|
else:
|
||||||
update_field.data_date = request.data[key]
|
update.data_date = request.data[key]
|
||||||
|
|
||||||
if update_field.type == "file":
|
if update.field_type == "file":
|
||||||
update_field.data_file = request.data[key]
|
update.data_file = request.data[key]
|
||||||
|
|
||||||
if update_field.type == "string":
|
if update.field_type == "string":
|
||||||
update_field.data_string = request.data[key]
|
update.data_string = request.data[key]
|
||||||
|
|
||||||
if update_field.type == "integer":
|
if update.field_type == "integer":
|
||||||
# initialize to 0
|
# initialize to 0
|
||||||
if (
|
if (
|
||||||
request.data[key] == "" or
|
request.data[key] == "" or
|
||||||
request.data[key] is None
|
request.data[key] is None
|
||||||
):
|
):
|
||||||
update_field.data_integer = 0
|
update.data_integer = 0
|
||||||
else:
|
else:
|
||||||
update_field.data_integer = request.data[key]
|
update.data_integer = request.data[key]
|
||||||
|
|
||||||
update_field.save()
|
update.save()
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
BIN
back/db.sqlite3
BIN
back/db.sqlite3
Binary file not shown.
Loading…
Reference in a new issue