Settings from backend

This commit is contained in:
Bartosz Karwacki 2022-01-23 19:03:55 +01:00
parent b3964b3a97
commit 370df82259
3 changed files with 37 additions and 15 deletions

View File

@ -77,7 +77,7 @@ def get_fuzzy_response(request_params, objects_list):
car.combustion,
)
)
if min(comparator) > settings.COMPARATOR:
if comparator and min(comparator) > settings.COMPARATOR:
end_object_list.append(car)
return end_object_list

View File

@ -1,7 +1,7 @@
import re
from rest_framework import generics
from rest_framework.views import APIView
from rest_framework.response import Response
from django.conf import settings
from .fuzzy_logic import get_fuzzy_response
from .models import Car
from .serializers import CarSerializer
@ -23,3 +23,13 @@ class SettingsAPIView(APIView):
def post(self, request, *args, **kwargs):
set_settings_values(request.data)
return Response("Settings changed")
def get(self, request, *args, **kwargs):
return Response({
'production_year':settings.PRODUCTION_YEAR,
'mileage':settings.MILEAGE,
'engine_capacity':settings.ENGINE_CAPACITY,
'combustion':settings.COMBUSTION,
'comparator':settings.COMPARATOR,
})

View File

@ -13,7 +13,7 @@
</template>
<script>
import axios from 'axios';
import axios from "axios";
export default {
name: "Table",
@ -53,21 +53,33 @@ export default {
},
comparator: {
label: "Stopień przynależności",
items: [
{ label: "",
value: 0.75
}
],
}
items: [{ label: "", value: 0.75 }],
},
},
}),
computed: {
computed: {},
created() {
this.getSettings();
},
methods: {
changeSettings() {
axios.post('http://localhost:8000/settings', this.settings)
}
}
axios.post("http://localhost:8000/settings", this.settings);
},
setValuesToSettings(label, data) {
this.settings[label].items[0].value = data[label].low.join(',')
this.settings[label].items[1].value = data[label].mid.join(',')
this.settings[label].items[2].value = data[label].high.join(',')
},
async getSettings() {
const response = await axios.get("http://localhost:8000/settings");
const data = response.data;
this.settings.comparator.items[0].value = data.comparator
this.setValuesToSettings('production_year', data)
this.setValuesToSettings('mileage', data)
this.setValuesToSettings('combustion', data)
this.setValuesToSettings('engine_capacity', data)
},
},
};
</script>