-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathadmin_tools.py
More file actions
126 lines (92 loc) · 2.83 KB
/
admin_tools.py
File metadata and controls
126 lines (92 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# -*- coding: utf-8 -*-
"""
Copyright (c) Lodve Berre and NTNU Technology Transfer AS 2024.
This file is part of Really Nice IRL.
Really Nice IRL is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your option)
any later version.
Really Nice IRL is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Really Nice IRL. If not, see:
<https://www.gnu.org/licenses/agpl-3.0.html>.
"""
import streamlit as st
import base
import ui
from streamlit import session_state as ss
###################
# Event handlers. #
###################
def on_add_organisation():
"""
Add organisations to the database.
Optionally also adds faculties if present in the UI.
Returns
-------
None.
"""
org = ss.new_org
org_id = base.add_org(org)
if ss.new_fac is not None:
for faculty in ss.new_fac.split("\n"):
base.add_fac(org_id, faculty)
ss.new_org = None
ss.new_fac = None
def on_add_faculties():
"""
Adds faculties to an existing organisation.
Returns
-------
None.
"""
org_id = ss.select_org.org_id
if ss.new_facs is not None:
for fac in ss.new_facs.split("\n"):
base.add_fac(org_id, fac)
ss.new_facs = None
def on_add_departments():
"""
Returns
-------
None.
"""
fac_id = ss.select_fac.fac_id
if ss.new_deps is not None:
for dep in ss.new_deps.split("\n"):
base.add_dep(fac_id, dep)
ss.new_deps = None
def on_delete_irl_ass():
print("Not deleting anything yet.")
# The action starts here.
dark_mode = (st.context.theme.type == 'dark')
ui.add_logo(dark_mode)
user = ss.user
ui.add_user()
st.divider()
ui.change_password(user, True)
st.divider()
ui.change_user_rights()
st.divider()
ui.change_user_status()
st.divider()
ui.add_organisation(on_add_organisation)
st.divider()
ui.add_faculties(on_add_faculties)
st.divider()
ui.add_departments(on_add_departments)
st.divider()
st.markdown("""
<div style="border:2px solid red; padding:10px; border-radius:5px;">
<h3 style="color:red;">🚨 Danger Zone</h3>
<p><strong>Be careful!</strong></p>
<p>Actions here are irreversible and may affect critical data.</p>
<p><strong>DO NOT touch anything here unless you are absolutely sure you know what you are doing!</strong></p>
</div>
""",
unsafe_allow_html=True)
st.divider()
ui.delete_irl_ass(ss.user)