diff --git a/flatisfy/web/js_src/store/getters.js b/flatisfy/web/js_src/store/getters.js index f633416..97f3dee 100644 --- a/flatisfy/web/js_src/store/getters.js +++ b/flatisfy/web/js_src/store/getters.js @@ -1,77 +1,88 @@ import { findFlatGPS, costFilter } from '../tools' export default { - allFlats: state => state.flats, + allFlats: (state) => state.flats, - flat: (state, getters) => id => state.flats.find(flat => flat.id === id), + flat: (state, getters) => (id) => + state.flats.find((flat) => flat.id === id), - isLoading: state => state.loading > 0, + isLoading: (state) => state.loading > 0, - postalCodesFlatsBuckets: (state, getters) => filter => { - const postalCodeBuckets = {} + inseeCodesFlatsBuckets: (state, getters) => (filter) => { + const buckets = {}; - state.flats.forEach(flat => { + state.flats.forEach((flat) => { if (!filter || filter(flat)) { - const postalCode = flat.flatisfy_postal_code.postal_code - if (!postalCodeBuckets[postalCode]) { - postalCodeBuckets[postalCode] = { - 'name': flat.flatisfy_postal_code.name, - 'flats': [] - } + const insee = flat.flatisfy_postal_code.insee_code; + if (!buckets[insee]) { + buckets[insee] = { + name: flat.flatisfy_postal_code.name, + flats: [], + }; } - postalCodeBuckets[postalCode].flats.push(flat) + buckets[insee].flats.push(flat); } - }) + }); - return postalCodeBuckets + return buckets; }, flatsMarkers: (state, getters) => (router, filter) => { - const markers = [] - state.flats.forEach(flat => { + const markers = []; + state.flats.forEach((flat) => { if (filter && filter(flat)) { - const gps = findFlatGPS(flat) + const gps = findFlatGPS(flat); if (gps) { const previousMarker = markers.find( - marker => marker.gps[0] === gps[0] && marker.gps[1] === gps[1] - ) + (marker) => + marker.gps[0] === gps[0] && marker.gps[1] === gps[1] + ); if (previousMarker) { - // randomize position a bit - // gps[0] += (Math.random() - 0.5) / 500 - // gps[1] += (Math.random() - 0.5) / 500 + // randomize position a bit + // gps[0] += (Math.random() - 0.5) / 500 + // gps[1] += (Math.random() - 0.5) / 500 } - const href = router.resolve({ name: 'details', params: { id: flat.id }}).href + const href = router.resolve({ + name: "details", + params: { id: flat.id }, + }).href; const cost = flat.cost ? costFilter(flat.cost, flat.currency) - : '' + : ""; markers.push({ - 'title': '', - 'content': '' + flat.title + '' + cost, - 'gps': gps, - 'flat_id': flat.id - }) + title: "", + content: + '' + + flat.title + + "" + + cost, + gps: gps, + flat_id: flat.id, + }); } } - }) + }); - return markers + return markers; }, - allTimeToPlaces: state => { - const places = {} - Object.keys(state.timeToPlaces).forEach(constraint => { - const constraintTimeToPlaces = state.timeToPlaces[constraint] - Object.keys(constraintTimeToPlaces).forEach(name => { - places[name] = constraintTimeToPlaces[name] - }) - }) - return places + allTimeToPlaces: (state) => { + const places = {}; + Object.keys(state.timeToPlaces).forEach((constraint) => { + const constraintTimeToPlaces = state.timeToPlaces[constraint]; + Object.keys(constraintTimeToPlaces).forEach((name) => { + places[name] = constraintTimeToPlaces[name]; + }); + }); + return places; }, timeToPlaces: (state, getters) => (constraintName) => { - return state.timeToPlaces[constraintName] + return state.timeToPlaces[constraintName]; }, - metadata: state => state.metadata -} + metadata: (state) => state.metadata, +}; diff --git a/flatisfy/web/js_src/views/home.vue b/flatisfy/web/js_src/views/home.vue index d6f44a1..c71a5f0 100644 --- a/flatisfy/web/js_src/views/home.vue +++ b/flatisfy/web/js_src/views/home.vue @@ -15,16 +15,16 @@ - - + + - {{ postal_code_data.name || $t('common.Unknown') }} - - ({{ postal_code }}) + {{ insee_code_data.name || $t('common.Unknown') }} + + ({{ insee_code }}) - - {{ postal_code_data.flats.length }} {{ $tc("common.flats", postal_code_data.flats.length) }} + - {{ insee_code_data.flats.length }} {{ $tc("common.flats", insee_code_data.flats.length) }} - + @@ -83,8 +83,8 @@ export default { }, computed: { - postalCodesFlatsBuckets () { - return this.$store.getters.postalCodesFlatsBuckets(flat => + inseeCodesFlatsBuckets () { + return this.$store.getters.inseeCodesFlatsBuckets(flat => flat.status === 'new' && (this.showExpiredFlats || !flat.is_expired) ) diff --git a/flatisfy/web/js_src/views/search.vue b/flatisfy/web/js_src/views/search.vue index dd164d6..8d73073 100644 --- a/flatisfy/web/js_src/views/search.vue +++ b/flatisfy/web/js_src/views/search.vue @@ -12,10 +12,10 @@ {{ $t("common.loading") }} - - - {{ postal_code_data.name }} ({{ postal_code }}) - {{ postal_code_data.flats.length }} {{ $tc("common.flats", postal_code_data.flats.length) }} - + + + {{ insee_code_data.name }} ({{ insee_code }}) - {{ insee_code_data.flats.length }} {{ $tc("common.flats", insee_code_data.flats.length) }} + @@ -51,12 +51,12 @@ export default { }, computed: { - postalCodesFlatsBuckets () { + inseeCodesFlatsBuckets () { if (!this.$route.query.query || this.loading) { return {} } - return this.$store.getters.postalCodesFlatsBuckets( + return this.$store.getters.inseeCodesFlatsBuckets( flat => flat.status !== 'duplicate' && flat.status !== 'ignored' && flat.status !== 'user_deleted' ) }, diff --git a/flatisfy/web/js_src/views/status.vue b/flatisfy/web/js_src/views/status.vue index bf53595..354f10a 100644 --- a/flatisfy/web/js_src/views/status.vue +++ b/flatisfy/web/js_src/views/status.vue @@ -17,11 +17,11 @@ {{ $t("common.loading") }} - - - {{ postal_code_data.name }} ({{ postal_code }}) - {{ postal_code_data.flats.length }} {{ $tc("common.flats", postal_code_data.flats.length) }} + + + {{ insee_code_data.name }} ({{ insee_code }}) - {{ insee_code_data.flats.length }} {{ $tc("common.flats", insee_code_data.flats.length) }} flat.status === this.$route.params.status) + inseeCodesFlatsBuckets () { + return this.$store.getters.inseeCodesFlatsBuckets(flat => flat.status === this.$route.params.status) }, title () { return 'Flatisfy - ' + capitalize(this.$t('status.' + this.$route.params.status)) diff --git a/flatisfy/web/routes/api.py b/flatisfy/web/routes/api.py index dae22fa..fd2c7a1 100644 --- a/flatisfy/web/routes/api.py +++ b/flatisfy/web/routes/api.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera import datetime import itertools import json +import logging import re import os @@ -15,6 +16,7 @@ import vobject import flatisfy.data from flatisfy.models import flat as flat_model +from flatisfy.models import postal_code from flatisfy.models.postal_code import PostalCode from flatisfy import cmds @@ -106,15 +108,17 @@ def _serialize_flat(flat, config): postal_codes[constraint_name] = flatisfy.data.load_data(PostalCode, constraint, config) try: - assert flat["flatisfy_postal_code"] + assert flat["flatisfy_position"] + lat = flat["flatisfy_position"]["lat"] + lng = flat["flatisfy_position"]["lng"] postal_code_data = next( - x - for x in postal_codes.get(flat["flatisfy_constraint"], []) - if x.postal_code == flat["flatisfy_postal_code"] + x for x in postal_codes.get(flat["flatisfy_constraint"], []) if x.lat == lat and x.lng == lng ) + logging.warn(f"{postal_code_data.name}, {lat}, {lng}") flat["flatisfy_postal_code"] = { - "postal_code": flat["flatisfy_postal_code"], + "postal_code": postal_code_data.postal_code, + "insee_code": postal_code_data.insee_code, "name": postal_code_data.name, "gps": (postal_code_data.lat, postal_code_data.lng), } diff --git a/start.sh b/start.sh index 074a496..18700c5 100755 --- a/start.sh +++ b/start.sh @@ -7,7 +7,7 @@ function clean_up { exit } -python -m flatisfy serve --config config.json & +python -m flatisfy serve --config config.json -v & SERVE_PID=$! yarn watch:dev &
{{ $t("common.loading") }}