States are handle correctly for multiple values
Browse files- sdc_view.py +61 -52
sdc_view.py
CHANGED
@@ -20,6 +20,7 @@ def render_sdc():
|
|
20 |
## The file where the state is
|
21 |
STATE_FILE = "besser_example.json"
|
22 |
SAVE_FILE = "session_state.json"
|
|
|
23 |
|
24 |
def load_state():
|
25 |
"""Load state from file and update session_state."""
|
@@ -27,9 +28,9 @@ def render_sdc():
|
|
27 |
try:
|
28 |
with open(STATE_FILE, "r") as f:
|
29 |
data = json.load(f)
|
30 |
-
print(data)
|
31 |
st.session_state.update(data)
|
32 |
st.session_state['form_data'] = data
|
|
|
33 |
except Exception as e:
|
34 |
st.error(f"Error loading state: {e}")
|
35 |
|
@@ -66,6 +67,7 @@ def render_sdc():
|
|
66 |
if "form_data" not in st.session_state:
|
67 |
st.session_state.form_data = load_cached_data()
|
68 |
|
|
|
69 |
# Function to save to cache when any input changes
|
70 |
def save_to_cache():
|
71 |
st.cache_data.clear()
|
@@ -252,6 +254,10 @@ def render_sdc():
|
|
252 |
if key in st.session_state and 0 <= index < len(st.session_state[key]):
|
253 |
st.session_state[key].pop(index)
|
254 |
st.rerun() # Rerun to update the interface
|
|
|
|
|
|
|
|
|
255 |
##
|
256 |
## Title
|
257 |
##
|
@@ -325,7 +331,7 @@ def render_sdc():
|
|
325 |
""")
|
326 |
with colt:
|
327 |
if st.button("Load Besser's diversity card", type="secondary"):
|
328 |
-
load_state()
|
329 |
##
|
330 |
## Master info
|
331 |
##
|
@@ -348,6 +354,7 @@ def render_sdc():
|
|
348 |
cached_multiple_radio("governance_projectType",["public funded", "research", "private", "private non-profit", "driven by open-source community", "citizen science"],"Specify the type of software project")
|
349 |
with col1:
|
350 |
# Multiple value
|
|
|
351 |
key = "governance_govProcesses"
|
352 |
init_state(key)
|
353 |
st.write("Define the set of governament process of your software project")
|
@@ -355,15 +362,16 @@ def render_sdc():
|
|
355 |
if st.button("Add governament processes"):
|
356 |
add_text_area(key)
|
357 |
# Loop over the array and create a text area with a remove button for each element
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
|
|
367 |
|
368 |
# BODIES
|
369 |
st.write("Add the different types of governament bodies of your software project (boards and funders)")
|
@@ -372,32 +380,33 @@ def render_sdc():
|
|
372 |
if st.button("Add governament bodies"):
|
373 |
add_text_area(key)
|
374 |
# Loop over the array and create a text area with a remove button for each element
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
|
|
401 |
|
402 |
with usageContext:
|
403 |
colr, coll = st.columns([1, 1])
|
@@ -430,21 +439,21 @@ def render_sdc():
|
|
430 |
if st.button("Add a team of participants"):
|
431 |
add_text_area(key)
|
432 |
# Loop over the array and create a text area with a remove button for each element
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
|
449 |
|
450 |
|
|
|
20 |
## The file where the state is
|
21 |
STATE_FILE = "besser_example.json"
|
22 |
SAVE_FILE = "session_state.json"
|
23 |
+
|
24 |
|
25 |
def load_state():
|
26 |
"""Load state from file and update session_state."""
|
|
|
28 |
try:
|
29 |
with open(STATE_FILE, "r") as f:
|
30 |
data = json.load(f)
|
|
|
31 |
st.session_state.update(data)
|
32 |
st.session_state['form_data'] = data
|
33 |
+
return unflatten(st.session_state["form_data"])
|
34 |
except Exception as e:
|
35 |
st.error(f"Error loading state: {e}")
|
36 |
|
|
|
67 |
if "form_data" not in st.session_state:
|
68 |
st.session_state.form_data = load_cached_data()
|
69 |
|
70 |
+
|
71 |
# Function to save to cache when any input changes
|
72 |
def save_to_cache():
|
73 |
st.cache_data.clear()
|
|
|
254 |
if key in st.session_state and 0 <= index < len(st.session_state[key]):
|
255 |
st.session_state[key].pop(index)
|
256 |
st.rerun() # Rerun to update the interface
|
257 |
+
|
258 |
+
|
259 |
+
unflattenedJson = unflatten(st.session_state["form_data"])
|
260 |
+
|
261 |
##
|
262 |
## Title
|
263 |
##
|
|
|
331 |
""")
|
332 |
with colt:
|
333 |
if st.button("Load Besser's diversity card", type="secondary"):
|
334 |
+
unflattenedJson = load_state()
|
335 |
##
|
336 |
## Master info
|
337 |
##
|
|
|
354 |
cached_multiple_radio("governance_projectType",["public funded", "research", "private", "private non-profit", "driven by open-source community", "citizen science"],"Specify the type of software project")
|
355 |
with col1:
|
356 |
# Multiple value
|
357 |
+
|
358 |
key = "governance_govProcesses"
|
359 |
init_state(key)
|
360 |
st.write("Define the set of governament process of your software project")
|
|
|
362 |
if st.button("Add governament processes"):
|
363 |
add_text_area(key)
|
364 |
# Loop over the array and create a text area with a remove button for each element
|
365 |
+
if 'governance' in unflattenedJson:
|
366 |
+
if 'govProcesses' in unflattenedJson['governance']:
|
367 |
+
for idx, processes in enumerate(unflattenedJson['governance']['govProcesses']):
|
368 |
+
# Create two columns: one for the text area, one for the remove button
|
369 |
+
col1, col2 = st.columns([6, 1])
|
370 |
+
with col1:
|
371 |
+
cached_text_area(f"Governament process {idx + 1}", f"governance_govProcesses_{idx}", "Specific the governance rules of the software project. For instance, the funders, or the role and the relation between the different bodies that governs the software.")
|
372 |
+
with col2:
|
373 |
+
if st.button("Remove", key=f"remove_{key}_{idx}"):
|
374 |
+
remove_text_area(idx,key)
|
375 |
|
376 |
# BODIES
|
377 |
st.write("Add the different types of governament bodies of your software project (boards and funders)")
|
|
|
380 |
if st.button("Add governament bodies"):
|
381 |
add_text_area(key)
|
382 |
# Loop over the array and create a text area with a remove button for each element
|
383 |
+
if 'governance' in unflattenedJson:
|
384 |
+
if 'bodies' in unflattenedJson['governance']:
|
385 |
+
for idx, text in enumerate(unflattenedJson['governance']['bodies']):
|
386 |
+
# Create two columns: one for the text area, one for the remove button
|
387 |
+
with st.container(border=True):
|
388 |
+
col1, col2 = st.columns([3, 2])
|
389 |
+
with col1:
|
390 |
+
cached_text_input("Body name", f"{key}_{idx}_name", "The name of id of the body")
|
391 |
+
cached_text_area("Body description", f"{key}_{idx}_description", "A description of the body")
|
392 |
+
|
393 |
+
|
394 |
+
with col2:
|
395 |
+
cached_multiple_radio(f"{key}_{idx}_type", ['funders', 'directors', 'administrators', 'other'], f"Body role type" )
|
396 |
+
if st.button("Remove", key=f"{key}_remove_{idx}"):
|
397 |
+
remove_text_area(idx,f"{key}_remove_{idx}")
|
398 |
+
|
399 |
+
|
400 |
+
with st.expander("If needed provide detailed information about the organizations or individuals involved in the governance", expanded=False):
|
401 |
+
# Button to add a new text area
|
402 |
+
org, individual = st.tabs([
|
403 |
+
"Organization",
|
404 |
+
"Individual",
|
405 |
+
])
|
406 |
+
with individual:
|
407 |
+
participant(f"{key}_{idx}_participant")
|
408 |
+
with org:
|
409 |
+
organization(f"{key}_{idx}_organization")
|
410 |
|
411 |
with usageContext:
|
412 |
colr, coll = st.columns([1, 1])
|
|
|
439 |
if st.button("Add a team of participants"):
|
440 |
add_text_area(key)
|
441 |
# Loop over the array and create a text area with a remove button for each element
|
442 |
+
if 'participants' in unflattenedJson:
|
443 |
+
for idx, text in enumerate(unflattenedJson['participants']):
|
444 |
+
# Create two columns: one for the text area, one for the remove button
|
445 |
+
with st.container(border=True):
|
446 |
+
col1, col2 = st.columns([2, 2])
|
447 |
+
with col1:
|
448 |
+
cached_text_input("Team name", f"{key}_{idx}_name", "The name of id of the team")
|
449 |
+
cached_text_area("Team description", f"{key}_{idx}_description", "A description of the team")
|
450 |
+
|
451 |
+
|
452 |
+
with col2:
|
453 |
+
if st.button("Remove", key=f"{key}_remove_{idx}"):
|
454 |
+
remove_text_area(idx,f"{key}_remove_{idx}")
|
455 |
+
cached_multiple_radio(f"{key}_{idx}_type", ['Development Team', 'NonCoding Contributor', 'Tester Team', 'Public Reporter TEam'], f"Team role type" )
|
456 |
+
team(f"{key}_{idx}")
|
457 |
|
458 |
|
459 |
|