forked from SykamRaju/Voter-CRM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download Polling Booths
Showing
4 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import streamlit as st | ||
from typing import Callable | ||
import pandas as pd | ||
from streamlit_option_menu import option_menu | ||
from Views.AddConstituency import AddConstituency | ||
from API import API | ||
|
||
|
||
|
||
|
||
class DownloadBooths: | ||
|
||
def get_districts(self,states,selected_option,get_districts_for_given_state,district_place): | ||
# Code to be executed when the select box value changes | ||
state_details = {state["State_Name"]: {key: value for key, value in state.items() if key != "State_Name"} for state in states} | ||
# st.write(state_details) | ||
# st.write("Selected option:", selected_option) | ||
State_Code = state_details[selected_option]['State_Id'] | ||
districts = get_districts_for_given_state(State_Code) | ||
|
||
if districts is not None: | ||
district_names = [district["District_Name"] for district in districts if district is not None] | ||
else: | ||
district_names = [] | ||
|
||
# district_place.write(districts) | ||
selected_district = district_place.selectbox("Select a District", district_names,key="download_con_1") | ||
# st.write(districts) | ||
# st.table(data) | ||
|
||
return selected_district,district_names,districts | ||
|
||
|
||
def get_constituencies(self,selected_option, | ||
get_constituencies_for_given_district, | ||
constituency_place, | ||
constituency_place_2): | ||
constituencies = get_constituencies_for_given_district(selected_option) | ||
# st.table(data) | ||
|
||
if constituencies is not None: | ||
constituencies_names = [constituency["Constituency_Name"] for constituency in constituencies if constituency is not None] | ||
else: | ||
constituencies_names = [] | ||
|
||
selected_constituency = constituency_place.selectbox("Select a Constituency", constituencies_names,key="download_con_11") | ||
# constituency_place.write(constituencies_names) | ||
# constituency_place_2.write(get_constituencies_for_given_district) | ||
# constituency_place.write(get_constituencies_for_given_district) | ||
# constituency_place.table(data) | ||
return constituencies,constituencies_names,selected_constituency | ||
|
||
def __init__(self,get_states: Callable[[str], bool],get_districts_for_given_state: Callable[[str], bool],get_constituencies_for_given_district: Callable[[str], bool],download_polling_booths: Callable[[str], bool]): | ||
|
||
st.header("Download Polling Booths") | ||
|
||
states=get_states() | ||
state_details = {state["State_Name"]: {key: value for key, value in state.items() if key != "State_Name"} for state in states} | ||
|
||
# st.write(state_details) | ||
if states is not None: | ||
state_names = [state["State_Name"] for state in states] | ||
# form = st.form("edit_district") | ||
Existing_State_Name = st.selectbox("Select a state", state_names,key="download_con_2") | ||
|
||
district_place = st.empty() | ||
|
||
constituency_place = st.empty() | ||
|
||
constituency_place_2 = st.empty() | ||
|
||
# Call the function whenever the state box value changes | ||
selected_district,district_names,districts = self.get_districts(states,Existing_State_Name,get_districts_for_given_state,district_place) | ||
|
||
# Call the function whenever the district box value changes | ||
constituencies,constituencies_names,selected_constituency = self.get_constituencies(selected_district, | ||
get_constituencies_for_given_district, | ||
constituency_place, | ||
constituency_place_2) | ||
|
||
|
||
|
||
|
||
if districts is not None: | ||
district_details = {district["District_Name"]: {key: value for key, value in district.items() if key != "District_Name"} for district in districts} | ||
else: | ||
district_details = [] | ||
|
||
if constituencies is not None: | ||
constituencies_details = {constituency["Constituency_Name"]: {key: value for key, value in constituency.items() if key != "Constituency_Name"} for constituency in constituencies} | ||
else: | ||
constituencies_details = [] | ||
|
||
if st.button('Download Polling Booths',key="download_con_3"): | ||
# st.write("State: ",Existing_State_Name) | ||
# st.write("DistrictName: ",selected_district) | ||
# st.write("Constituency: ",selected_constituency) | ||
data = download_polling_booths(Existing_State_Name,selected_district,selected_constituency) | ||
# st.write(data) | ||
file_name = "polling_booths_"+Existing_State_Name+"_"+selected_district+"_"+selected_constituency+".csv" | ||
st.download_button( | ||
label="Download Polling Booths as CSV", | ||
data=data, | ||
file_name=file_name, | ||
mime='text/csv', | ||
) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters