From 1434cfeddad68ac756ba34ca4c03001cf83e3b66 Mon Sep 17 00:00:00 2001 From: dohseven Date: Sun, 13 Jan 2019 20:22:57 +0100 Subject: [PATCH 1/2] Add metadata indicating last update of application --- flatisfy/cmds.py | 9 ++++++ flatisfy/web/app.py | 2 ++ flatisfy/web/js_src/api/index.js | 7 +++++ flatisfy/web/js_src/i18n/en/index.js | 1 + flatisfy/web/js_src/i18n/fr/index.js | 1 + flatisfy/web/js_src/store/actions.js | 6 ++++ flatisfy/web/js_src/store/getters.js | 4 ++- flatisfy/web/js_src/store/mutations-types.js | 1 + flatisfy/web/js_src/store/mutations.js | 5 +++ flatisfy/web/js_src/views/home.vue | 21 +++++++++++++ flatisfy/web/routes/api.py | 32 +++++++++++++++++++- 11 files changed, 87 insertions(+), 2 deletions(-) diff --git a/flatisfy/cmds.py b/flatisfy/cmds.py index c48e5c8..89af785 100644 --- a/flatisfy/cmds.py +++ b/flatisfy/cmds.py @@ -6,6 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals import collections import logging +import os import flatisfy.filters from flatisfy import database @@ -203,6 +204,14 @@ def import_and_filter(config, load_from_db=False): if config["send_email"]: email.send_notification(config, new_flats) + # Touch a file to indicate last update timestamp + ts_file = os.path.join( + config["data_directory"], + "timestamp" + ) + with open(ts_file, 'w'): + os.utime(ts_file, None) + LOGGER.info("Done!") diff --git a/flatisfy/web/app.py b/flatisfy/web/app.py index 94d7d69..a10e376 100644 --- a/flatisfy/web/app.py +++ b/flatisfy/web/app.py @@ -107,6 +107,8 @@ def get_app(config): app.route("/api/v1/opendata/postal_codes", "GET", api_routes.opendata_postal_codes_v1) + app.route("/api/v1/metadata", ["GET", "OPTIONS"], api_routes.metadata_v1) + # Index app.route("/", "GET", lambda: _serve_static_file("index.html")) diff --git a/flatisfy/web/js_src/api/index.js b/flatisfy/web/js_src/api/index.js index 59be30e..fbcb524 100644 --- a/flatisfy/web/js_src/api/index.js +++ b/flatisfy/web/js_src/api/index.js @@ -161,3 +161,10 @@ export const doSearch = function (query, callback) { console.error('Unable to perform search: ' + ex) }) } + +export const getMetadata = function (callback) { + fetch('/api/v1/metadata', { credentials: 'same-origin' }) + .then(response => response.json()) + .then(json => callback(json.data)) + .catch(ex => console.error('Unable to fetch application metadata: ' + ex)) +} diff --git a/flatisfy/web/js_src/i18n/en/index.js b/flatisfy/web/js_src/i18n/en/index.js index b2906d9..ad0c29e 100644 --- a/flatisfy/web/js_src/i18n/en/index.js +++ b/flatisfy/web/js_src/i18n/en/index.js @@ -19,6 +19,7 @@ export default { }, home: { 'new_available_flats': 'New available flats', + 'Last_update': 'Last update:', 'show_expired_flats': 'Show expired flats' }, flatListing: { diff --git a/flatisfy/web/js_src/i18n/fr/index.js b/flatisfy/web/js_src/i18n/fr/index.js index 0b79726..ccc44b1 100644 --- a/flatisfy/web/js_src/i18n/fr/index.js +++ b/flatisfy/web/js_src/i18n/fr/index.js @@ -19,6 +19,7 @@ export default { }, home: { 'new_available_flats': 'Nouveaux appartements disponibles', + 'Last_update': 'Dernière mise à jour :', 'show_expired_flats': 'Montrer les annonces expirées' }, flatListing: { diff --git a/flatisfy/web/js_src/store/actions.js b/flatisfy/web/js_src/store/actions.js index 4d1bc9c..90c50e8 100644 --- a/flatisfy/web/js_src/store/actions.js +++ b/flatisfy/web/js_src/store/actions.js @@ -50,5 +50,11 @@ export default { api.doSearch(query, flats => { commit(types.REPLACE_FLATS, { flats }) }) + }, + getMetadata ({ commit }) { + commit(types.IS_LOADING) + api.getMetadata(metadata => { + commit(types.RECEIVE_METADATA, { metadata }) + }) } } diff --git a/flatisfy/web/js_src/store/getters.js b/flatisfy/web/js_src/store/getters.js index 7e67088..6610e33 100644 --- a/flatisfy/web/js_src/store/getters.js +++ b/flatisfy/web/js_src/store/getters.js @@ -67,5 +67,7 @@ export default { timeToPlaces: (state, getters) => (constraintName) => { return state.timeToPlaces[constraintName] - } + }, + + metadata: state => state.metadata } diff --git a/flatisfy/web/js_src/store/mutations-types.js b/flatisfy/web/js_src/store/mutations-types.js index 89c45fa..663ee10 100644 --- a/flatisfy/web/js_src/store/mutations-types.js +++ b/flatisfy/web/js_src/store/mutations-types.js @@ -5,4 +5,5 @@ export const UPDATE_FLAT_NOTES = 'UPDATE_FLAT_NOTES' export const UPDATE_FLAT_NOTATION = 'UPDATE_FLAT_NOTATION' export const UPDATE_FLAT_VISIT_DATE = 'UPDATE_FLAT_VISIT_DATE' export const RECEIVE_TIME_TO_PLACES = 'RECEIVE_TIME_TO_PLACES' +export const RECEIVE_METADATA = 'RECEIVE_METADATA' export const IS_LOADING = 'IS_LOADING' diff --git a/flatisfy/web/js_src/store/mutations.js b/flatisfy/web/js_src/store/mutations.js index 1c9dbc5..a7b2d19 100644 --- a/flatisfy/web/js_src/store/mutations.js +++ b/flatisfy/web/js_src/store/mutations.js @@ -5,6 +5,7 @@ import * as types from './mutations-types' export const state = { flats: [], timeToPlaces: [], + metadata: [], loading: 0 } @@ -58,6 +59,10 @@ export const mutations = { state.timeToPlaces = timeToPlaces state.loading -= 1 }, + [types.RECEIVE_METADATA] (state, { metadata }) { + state.metadata = metadata + state.loading -= 1 + }, [types.IS_LOADING] (state) { state.loading += 1 } diff --git a/flatisfy/web/js_src/views/home.vue b/flatisfy/web/js_src/views/home.vue index 71eef5c..61e591c 100644 --- a/flatisfy/web/js_src/views/home.vue +++ b/flatisfy/web/js_src/views/home.vue @@ -4,6 +4,11 @@

{{ $t("home.new_available_flats") }} +