Skip to content

Commit

Permalink
precommit formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Qouentinne committed May 5, 2024
1 parent 69da052 commit 4d5eea3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/pages/0_Import_File.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
def set_page_filter(value: dict):
set_state(["config", "pagefilter"], value)


def initiate_configuration() -> None:
st.session_state["config"] = copy.deepcopy(st.session_state["initial_config"])
if isinstance(st.session_state["config"]["pagefilter"], list):
Expand All @@ -27,6 +28,7 @@ def initiate_configuration() -> None:
"pagefilter"
]["type"]


def on_pdf_file_upload() -> None:
# Change states related to the pdf file upload
mytmpfile.write(st.session_state.original_pdf.read())
Expand All @@ -45,9 +47,12 @@ def on_config_file_upload() -> None:


def on_change_page_filter(name_to_filter_dict: dict) -> None:
st.session_state["selected_page_filter_name"] = st.session_state["radio_button_filter_selection"] #this 'buffer' is needed because selectors wipe their key on reload
st.session_state["selected_page_filter_name"] = st.session_state[
"radio_button_filter_selection"
] # this 'buffer' is needed because selectors wipe their key on reload
set_page_filter(name_to_filter_dict[st.session_state["selected_page_filter_name"]])


# Check if a redirection was requested
# Workaround because st.switch_page is not allowed in a callback function
if st.session_state.get("page_redirection", False):
Expand Down Expand Up @@ -158,4 +163,4 @@ def on_change_page_filter(name_to_filter_dict: dict) -> None:
st.markdown(
get_pdf_iframe(st.session_state["working_file_pdf"].name),
unsafe_allow_html=True,
)
)
1 change: 1 addition & 0 deletions app/pages/1_Selected_Pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def set_extractors() -> None:
st.session_state["proc"] = ReportProcessor(st.session_state["config"])
generate_assets()


st.set_page_config(layout="wide", page_title="Pages selection") # page_icon="📈"
st.title("Country by Country Tax Reporting analysis : Selected Pages")
st.subheader(
Expand Down
6 changes: 4 additions & 2 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import Any

import pandas as pd
from pypdf import PdfReader
import streamlit as st
from pypdf import PdfReader


def get_pdf_iframe(pdf_to_process: str) -> str:
Expand Down Expand Up @@ -43,6 +43,7 @@ def to_csv_file(df: pd.DataFrame) -> bytes:

return df.to_csv(index=False).encode("utf-8")


def set_state(key: Any, value: Any) -> None:
"""
Sets the session_state[key] to value.
Expand All @@ -63,6 +64,7 @@ def set_state(key: Any, value: Any) -> None:
else:
st.session_state[key] = value


def generate_assets() -> None:
assets = {
"pagefilter": {},
Expand All @@ -82,4 +84,4 @@ def generate_assets() -> None:
# Hence, we display the full pdf, letting the user select the pages
number_pages = len(PdfReader(st.session_state["working_file_pdf"]).pages)
assets["pagefilter"]["selected_pages"] = list(range(number_pages))
st.session_state["assets"] = assets
st.session_state["assets"] = assets

0 comments on commit 4d5eea3

Please sign in to comment.