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.
1 parent
7caaa86
commit 56f87a5
Showing
13 changed files
with
3,751 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,278 @@ | ||
import streamlit as st | ||
from API import API | ||
import extra_streamlit_components as stx | ||
from streamlit_option_menu import option_menu | ||
import toml | ||
import os | ||
|
||
from Views.AddState import AddState | ||
from Views.DisplayStates import DisplayStates | ||
from Views.EditState import EditState | ||
from Views.DeleteState import DeleteState | ||
|
||
from Views.AddDistrict import AddDistrict | ||
from Views.DisplayDistricts import DisplayDistricts | ||
from Views.EditDistrict import EditDistrict | ||
from Views.DeleteDistrict import DeleteDistrict | ||
|
||
from Views.AddConstituency import AddConstituency | ||
from Views.DisplayConstituencies import DisplayConstituencies | ||
from Views.EditConstituency import EditConstituency | ||
from Views.DeleteConstituency import DeleteConstituency | ||
|
||
from Views.DisplayParties import DisplayParties | ||
from Views.AddParty import AddParty | ||
from Views.DeleteParty import DeleteParty | ||
|
||
from Views.ChangePassword import ChangePassword | ||
from Views.RegisterAgent import RegisterAgent | ||
from Views.Login import Login | ||
|
||
from Views.VotersList import DisplayVoters | ||
|
||
config = toml.load(".streamlit/config.toml") | ||
api_base_url = "http://{}:8000/".format( | ||
os.getenv('SERVER_URL', '127.0.0.1') | ||
) | ||
|
||
st.markdown(""" | ||
<style> | ||
.main .block-container { | ||
margin-top: -4rem; | ||
} | ||
#MainMenu {visibility: hidden;} | ||
footer {visibility: hidden;} | ||
</style> | ||
""", unsafe_allow_html=True) | ||
|
||
cookie_manager = stx.CookieManager() | ||
cookies = cookie_manager.get_all() | ||
authentication_token = cookies.get( | ||
"token") if type(cookies) == dict else cookies | ||
|
||
api = API(api_base_url, authentication_token) | ||
|
||
|
||
def manage_login(login_details): | ||
token = api.login(login_details) | ||
cookie_manager.set("token", token) | ||
return token is not None | ||
|
||
|
||
def manage_signup(signup_details): | ||
return api.signup(signup_details) | ||
|
||
|
||
def manage_changepassword(password_details): | ||
return api.change_password(password_details) | ||
|
||
|
||
def register_agent(agent_details): | ||
return api.signup(agent_details) | ||
|
||
|
||
if api.is_logged_in(): | ||
|
||
with st.sidebar: | ||
selected = option_menu( | ||
menu_title="Main Menu", | ||
options=["States", "Districts", "Constituencies", | ||
"Political Parties", "Display Voters List", "Register Agent", "Change Password", "Log Out"], | ||
icons=['patch-check', 'patch-check', 'patch-check', 'patch-check', | ||
'patch-check', 'person-plus', 'shuffle', 'box-arrow-left'], | ||
menu_icon="app-indicator", | ||
styles={ | ||
"container": {"padding": "5px !important"}, | ||
"icon": {"font-size": "24px"}, | ||
"nav-link": {"font-size": "16px", "text-align": "left", "margin": "0px", | ||
"--hover-color": "rgba(128,128,128,0.25)"} | ||
} | ||
) | ||
|
||
############################################################### | ||
# | ||
# L O G O U T | ||
# | ||
############################################################### | ||
if selected == "Log Out": | ||
if api.admin_logout(): | ||
st.success("Logging out!") | ||
st.session_state.runpage = Login(manage_login, manage_signup) | ||
st.experimental_rerun() | ||
else: | ||
st.error("An error occurred during logout!") | ||
|
||
############################################################### | ||
# | ||
# C H A N G E P A S S W O R D | ||
# | ||
############################################################### | ||
|
||
if selected == "Change Password": | ||
ChangePassword(manage_changepassword) | ||
|
||
############################################################### | ||
# | ||
# S T A T E S | ||
# | ||
############################################################### | ||
if selected == "States": | ||
tab1, tab2, tab3, tab4 = st.tabs( | ||
["View States", "Add State", "Edit State", "Delete State"]) | ||
|
||
with tab1: | ||
# List States | ||
DisplayStates(api.get_states) | ||
|
||
with tab2: | ||
# Add a State | ||
AddState(api.add_state) | ||
|
||
with tab3: | ||
# Edit State | ||
EditState(api.get_states, api.edit_state) | ||
|
||
with tab4: | ||
# Delete State | ||
DeleteState(api.get_states, api.delete_state) | ||
|
||
############################################################### | ||
# | ||
# D I S T R I C T S | ||
# | ||
############################################################### | ||
if selected == "Districts": | ||
tab1, tab2, tab3, tab4 = st.tabs( | ||
["View Districts", "Add District", "Edit District", "Delete District"]) | ||
|
||
with tab1: | ||
# List Districts | ||
DisplayDistricts(api.get_states,api.get_districts_for_given_state) | ||
|
||
with tab2: | ||
# Add a District | ||
AddDistrict(api.get_states, api.add_district) | ||
|
||
with tab3: | ||
# Edit District | ||
EditDistrict(api.get_states,api.get_districts_for_given_state, api.edit_district) | ||
|
||
with tab4: | ||
# Delete District | ||
DeleteDistrict(api.get_states,api.get_districts_for_given_state, api.delete_district) | ||
|
||
############################################################### | ||
# | ||
# C O N S T I T U E N C I E S | ||
# | ||
############################################################### | ||
if selected == "Constituencies": | ||
tab1, tab2, tab3, tab4 = st.tabs( | ||
["View Constituencies", "Add Constituency", "Edit Constituency", "Delete Constituency"]) | ||
|
||
with tab1: | ||
# List Constituencies | ||
# DisplayConstituencies(api.get_constituencies) | ||
DisplayConstituencies(api.get_states,api.get_districts_for_given_state,api.get_constituencies_for_given_district) | ||
|
||
|
||
|
||
with tab2: | ||
# Add a Constituency | ||
AddConstituency(api.get_states,api.get_districts_for_given_state,api.add_constituency) | ||
|
||
with tab3: | ||
# Edit Constituency | ||
EditConstituency(api.get_states,api.get_districts_for_given_state,api.get_constituencies_for_given_district, api.edit_constituency) | ||
|
||
with tab4: | ||
# Delete Constituency | ||
# DeleteConstituency(api.get_constituencies_for_given_district, api.delete_constituency) | ||
DeleteConstituency(api.get_states,api.get_districts_for_given_state,api.get_constituencies_for_given_district, api.delete_constituency) | ||
|
||
############################################################### | ||
# | ||
# D I S P L A Y V O T E R S L I S T | ||
# | ||
############################################################### | ||
if selected == "Display Voters List": | ||
DisplayVoters(api.get_voters) | ||
|
||
############################################################### | ||
# | ||
# R E G I S T E R A N A G E N T | ||
# | ||
############################################################### | ||
if selected == "Register Agent": | ||
RegisterAgent(register_agent) | ||
|
||
############################################################### | ||
# | ||
# P O L I T I C A L P A R T I E S | ||
# | ||
############################################################### | ||
if selected == "Political Parties": | ||
tab1, tab2, tab3 = st.tabs( | ||
["View Political Parties", "Add Political Party", "Delete Political Party"]) | ||
|
||
with tab1: | ||
# List Political Parties | ||
DisplayParties(api.get_parties) | ||
|
||
with tab2: | ||
# Add a Political Party | ||
AddParty(api.add_party,api.get_states) | ||
|
||
with tab3: | ||
# Delete a Political Party | ||
DeleteParty(api.get_parties, api.delete_party) | ||
|
||
|
||
elif api.is_agent_logged_in(): | ||
with st.sidebar: | ||
agent_selected = option_menu( | ||
menu_title="Main Menu", | ||
options=["Upload Voter Details", "Display Voters List", "Change Password", "Log Out"], | ||
icons=['file-arrow-up', 'patch-check', 'shuffle', 'box-arrow-left'], | ||
menu_icon="app-indicator", | ||
styles={ | ||
"container": {"padding": "5px !important"}, | ||
"icon": {"font-size": "24px"}, | ||
"nav-link": {"font-size": "16px", "text-align": "left", "margin": "0px", | ||
"--hover-color": "rgba(128,128,128,0.25)"} | ||
} | ||
) | ||
|
||
############################################################### | ||
# | ||
# L O G O U T | ||
# | ||
############################################################### | ||
if agent_selected == "Log Out": | ||
if api.agent_logout(): | ||
st.success("Logging out!") | ||
st.session_state.runpage = Login(manage_login, manage_signup) | ||
st.experimental_rerun() | ||
else: | ||
st.error("An error occurred during logout!") | ||
|
||
############################################################### | ||
# | ||
# C H A N G E P A S S W O R D | ||
# | ||
############################################################### | ||
|
||
if agent_selected == "Change Password": | ||
ChangePassword(manage_changepassword) | ||
|
||
############################################################### | ||
# | ||
# D I S P L A Y V O T E R S L I S T | ||
# | ||
############################################################### | ||
if agent_selected == "Display Voters List": | ||
DisplayVoters(api.get_voters) | ||
|
||
else: | ||
Login(manage_login, manage_signup) |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,92 @@ | ||
import pandas as pd | ||
import json | ||
|
||
excel_file_name = "data/voterCRM.xlsx" | ||
json_file_name = "data/voter_data.json" | ||
|
||
|
||
def convert_excel_to_df(excel_file_name): | ||
df = pd.read_excel(excel_file_name) | ||
return df | ||
|
||
|
||
def convert_df_to_json_str(df, orient="records"): | ||
""" | ||
Converts pandas dataframe to Json string | ||
Parameters: | ||
df (dataframe): pandas dataframe | ||
orient(string): how to orient the json string | ||
Returns: | ||
json_str:Returning value | ||
""" | ||
json_str = df.to_json(orient=orient) | ||
return json_str | ||
|
||
|
||
def convert_df_to_json_file(df, file_name, orient="records"): | ||
""" | ||
Converts pandas dataframe to Json file | ||
Parameters: | ||
df (dataframe): pandas dataframe | ||
file_name(string): json file name | ||
orient(string): how to orient the json string | ||
Returns: | ||
None | ||
""" | ||
json_str = df.to_json(orient=orient) | ||
with open(json_file_name, "w") as outfile: | ||
json.dump(json_str, outfile) | ||
print(f"dataframe is saved as {file_name}") | ||
|
||
|
||
def convert_json_file_to_df(json_file_name, orient="records"): | ||
|
||
""" | ||
Converts Json file to pandas dataframe | ||
Parameters: | ||
json_file_name(string): json file name | ||
orient(string): how to orient the json string | ||
Returns: | ||
dataframe | ||
""" | ||
with open(json_file_name, "r") as filectx: | ||
json_file = json.load(filectx) | ||
json_df = pd.read_json(json_file, orient=orient) | ||
return json_df | ||
|
||
|
||
def convert_json_str_to_df(json_str, orient="records"): | ||
|
||
""" | ||
Converts Json string to pandas dataframe | ||
Parameters: | ||
json_str(string): json string | ||
orient(string): how to orient the json string | ||
Returns: | ||
dataframe | ||
""" | ||
json_df = pd.read_json(json_str, orient=orient) | ||
return json_df | ||
|
||
|
||
### below is the example usage | ||
|
||
# df =convert_excel_to_df(excel_file_name) | ||
# convert_df_to_json_file(df,json_file_name) | ||
# json_str = convert_df_to_json_str(df) | ||
|
||
# json_df = convert_json_file_to_df(json_file_name) | ||
# convert_json_str_to_df(json_str) | ||
|