Spaces:
Running
Running
rmm
commited on
Commit
·
6d20197
1
Parent(s):
92f48dd
fix: lat/lon values persist over page switches
Browse files- this also copes with edits made if the original value came from file
metadata, so the user can correct it (previously it would re-read
the metadata and changes would be lost)
- src/input/input_handling.py +33 -8
src/input/input_handling.py
CHANGED
@@ -202,7 +202,12 @@ def metadata_inputs_one_file(file:UploadedFile, image_hash:str, dbg_ix:int=0) ->
|
|
202 |
m_logger.warning("[W] `container_metadata_inputs` is None, using sidebar")
|
203 |
|
204 |
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
206 |
author_email = st.session_state["input_author_email"]
|
207 |
filename = file.name
|
208 |
image_datetime_raw = get_image_datetime(file)
|
@@ -211,6 +216,23 @@ def metadata_inputs_one_file(file:UploadedFile, image_hash:str, dbg_ix:int=0) ->
|
|
211 |
msg = f"[D] {filename}: lat, lon from image metadata: {latitude0}, {longitude0}"
|
212 |
m_logger.debug(msg)
|
213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
if spoof_metadata:
|
215 |
if latitude0 is None: # get some default values if not found in exifdata
|
216 |
latitude0:float = spoof_metadata.get('latitude', 0) + dbg_ix
|
@@ -222,17 +244,13 @@ def metadata_inputs_one_file(file:UploadedFile, image_hash:str, dbg_ix:int=0) ->
|
|
222 |
#viewcontainer.title(f"Metadata for {filename}")
|
223 |
viewcontainer = _viewcontainer.expander(f"Metadata for {file.name}", expanded=True)
|
224 |
|
225 |
-
# TODO: use session state so any changes are persisted within session -- currently I think
|
226 |
-
# we are going to take the defaults over and over again -- if the user adjusts coords, or date, it will get lost
|
227 |
-
# - it is a bit complicated, if no values change, they persist (the widget definition: params, name, key, etc)
|
228 |
-
# even if the code is re-run. but if the value changes, it is lost.
|
229 |
-
|
230 |
|
231 |
# 3. Latitude Entry Box
|
232 |
latitude = viewcontainer.text_input(
|
233 |
"Latitude for " + filename,
|
234 |
latitude0,
|
235 |
-
key=f"input_latitude_{image_hash}")
|
|
|
236 |
if latitude and not is_valid_number(latitude):
|
237 |
viewcontainer.error("Please enter a valid latitude (numerical only).")
|
238 |
m_logger.error(f"Invalid latitude entered: {latitude}.")
|
@@ -240,10 +258,17 @@ def metadata_inputs_one_file(file:UploadedFile, image_hash:str, dbg_ix:int=0) ->
|
|
240 |
longitude = viewcontainer.text_input(
|
241 |
"Longitude for " + filename,
|
242 |
longitude0,
|
243 |
-
key=f"input_longitude_{image_hash}")
|
|
|
244 |
if longitude and not is_valid_number(longitude):
|
245 |
viewcontainer.error("Please enter a valid longitude (numerical only).")
|
246 |
m_logger.error(f"Invalid latitude entered: {latitude}.")
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
|
248 |
# 5. Date/time
|
249 |
## first from image metadata
|
|
|
202 |
m_logger.warning("[W] `container_metadata_inputs` is None, using sidebar")
|
203 |
|
204 |
|
205 |
+
# logic for the precedence of lat/lon values (descending importance)
|
206 |
+
# 1) if something was already entered, take that value (can have arrived from 2 or 3 in previous round)
|
207 |
+
# 2) if file metadata, take that value
|
208 |
+
# 3) if spoof metadata flag is up, take that value
|
209 |
+
# 4) else, empty (None)
|
210 |
+
|
211 |
author_email = st.session_state["input_author_email"]
|
212 |
filename = file.name
|
213 |
image_datetime_raw = get_image_datetime(file)
|
|
|
216 |
msg = f"[D] {filename}: lat, lon from image metadata: {latitude0}, {longitude0}"
|
217 |
m_logger.debug(msg)
|
218 |
|
219 |
+
# let's see if there was a value that was already entered for latitude and/or longitude
|
220 |
+
key_lon=f"input_longitude_{image_hash}"
|
221 |
+
key_lat=f"input_latitude_{image_hash}"
|
222 |
+
present_lat = key_lat in st.session_state
|
223 |
+
present_lon = key_lon in st.session_state
|
224 |
+
|
225 |
+
latitude_prior = st.session_state.get(key_lat, None)
|
226 |
+
longitude_prior = st.session_state.get(key_lon, None)
|
227 |
+
|
228 |
+
m_logger.debug(f"[D] {key_lat}: key present? {int(present_lat)} | prior value: {latitude_prior} | metadata value: {latitude0}")
|
229 |
+
m_logger.debug(f"[D] {key_lon}: key present? {int(present_lon)} | prior value: {longitude_prior} | metadata value: {longitude0}")
|
230 |
+
|
231 |
+
if latitude_prior is not None:
|
232 |
+
latitude0 = latitude_prior
|
233 |
+
if longitude_prior is not None:
|
234 |
+
longitude0 = longitude_prior
|
235 |
+
|
236 |
if spoof_metadata:
|
237 |
if latitude0 is None: # get some default values if not found in exifdata
|
238 |
latitude0:float = spoof_metadata.get('latitude', 0) + dbg_ix
|
|
|
244 |
#viewcontainer.title(f"Metadata for {filename}")
|
245 |
viewcontainer = _viewcontainer.expander(f"Metadata for {file.name}", expanded=True)
|
246 |
|
|
|
|
|
|
|
|
|
|
|
247 |
|
248 |
# 3. Latitude Entry Box
|
249 |
latitude = viewcontainer.text_input(
|
250 |
"Latitude for " + filename,
|
251 |
latitude0,
|
252 |
+
#key=f"input_latitude_{image_hash}")
|
253 |
+
)
|
254 |
if latitude and not is_valid_number(latitude):
|
255 |
viewcontainer.error("Please enter a valid latitude (numerical only).")
|
256 |
m_logger.error(f"Invalid latitude entered: {latitude}.")
|
|
|
258 |
longitude = viewcontainer.text_input(
|
259 |
"Longitude for " + filename,
|
260 |
longitude0,
|
261 |
+
#key=f"input_longitude_{image_hash}")
|
262 |
+
)
|
263 |
if longitude and not is_valid_number(longitude):
|
264 |
viewcontainer.error("Please enter a valid longitude (numerical only).")
|
265 |
m_logger.error(f"Invalid latitude entered: {latitude}.")
|
266 |
+
|
267 |
+
# now store the latitude and longitude into the session state (persists across page switches)
|
268 |
+
st.session_state[key_lat] = latitude
|
269 |
+
st.session_state[key_lon] = longitude
|
270 |
+
|
271 |
+
|
272 |
|
273 |
# 5. Date/time
|
274 |
## first from image metadata
|