Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/create new site group #84

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,5 @@ def create_user(
session.add(user)
site_group.users.append(user)
session.commit()
print(user)

return user
52 changes: 46 additions & 6 deletions src/sites_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sqlalchemy import func
from pvsite_datamodel.connection import DatabaseConnection
from pvsite_datamodel.sqlmodels import SiteSQL
from pvsite_datamodel.write.user_and_site import make_user
from pvsite_datamodel.write.user_and_site import make_site_group
from pvsite_datamodel.read import (
get_all_sites,
get_user_by_email,
Expand Down Expand Up @@ -318,7 +318,7 @@ def sites_toolbox_page():

# create a new site
st.markdown(
f'<h1 style="color:#63BCAF;font-size:32px;">{"Create New Site"}</h1>',
f'<h1 style="color:#63BCAF;font-size:32px;">{"Create Site"}</h1>',
unsafe_allow_html=True,
)
with st.expander("Input new site data"):
Expand Down Expand Up @@ -406,7 +406,7 @@ def sites_toolbox_page():

# create a new user
st.markdown(
f'<h1 style="color:#63BCAF;font-size:32px;">{"Create New User"}</h1>',
f'<h1 style="color:#63BCAF;font-size:32px;">{"Create User"}</h1>',
unsafe_allow_html=True,
)

Expand All @@ -419,7 +419,9 @@ def sites_toolbox_page():
unsafe_allow_html=True,
)
email = st.text_input("User Email")
site_group_name = st.selectbox("Select a group", site_groups, key="site_group")
site_group_name = st.selectbox(
"Select a group", site_groups, key="site_group"
)
email_validation = validate_email(email)
# check that site group exists
if st.button(f"Create new user"):
Expand All @@ -434,7 +436,6 @@ def sites_toolbox_page():
unsafe_allow_html=True,
)
else:

user = create_user(
session=session,
email=email,
Expand All @@ -450,4 +451,43 @@ def sites_toolbox_page():

if st.button("Close details"):
st.empty()


# create site group
st.markdown(
f'<h1 style="color:#63BCAF;font-size:32px;">{"Create Site Group"}</h1>',
unsafe_allow_html=True,
)

with st.expander("Input new group data"):
with connection.get_session() as session:
st.markdown(
f'<h1 style="color:#FFD053;font-size:22px;">{"Site Group Information"}</h1>',
unsafe_allow_html=True,
)
new_site_group_name = st.text_input("Enter new site group name")
# check that site group exists
if st.button(f"Create new site group"):
if new_site_group_name == "":
st.markdown(
f'<p style="color:#f07167;font-size:16px;">{"Please enter a valid name for the site group."}</p>',
unsafe_allow_html=True,
)
elif new_site_group_name in site_groups:
st.markdown(
f'<p style="color:#f07167;font-size:16px;">{"This site group already exists."}</p>',
unsafe_allow_html=True,
)
else:
new_site_group = make_site_group(
db_session=session,
site_group_name=new_site_group_name,
)
new_site_group_details = {
"site_group": str(new_site_group.site_group_name),
"site_group_uuid": str(new_site_group.site_group_uuid),
"date_added": (new_site_group.created_utc.strftime("%Y-%m-%d")),
}
st.json(new_site_group_details)

if st.button("Close details"):
st.empty()
1 change: 1 addition & 0 deletions tests/test_get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ def test_create_user(db_session):
assert user_1.email == "test_user@test.org"
assert user_1.site_group.site_group_name == "test_site_group"
assert user_1.site_group_uuid == site_group_1.site_group_uuid

Loading