You've already forked DBViewerOnStreamlit
mirror of
https://github.com/Llloooggg/DBViewerOnStreamlit.git
synced 2026-03-05 20:56:23 +03:00
Start
This commit is contained in:
0
modules/__init.py__
Normal file
0
modules/__init.py__
Normal file
BIN
modules/__pycache__/main.cpython-38.pyc
Normal file
BIN
modules/__pycache__/main.cpython-38.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/mainPage.cpython-38.pyc
Normal file
BIN
modules/__pycache__/mainPage.cpython-38.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/ticketsMaker.cpython-38.pyc
Normal file
BIN
modules/__pycache__/ticketsMaker.cpython-38.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/ticketsViewer.cpython-38.pyc
Normal file
BIN
modules/__pycache__/ticketsViewer.cpython-38.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/usersEditor.cpython-38.pyc
Normal file
BIN
modules/__pycache__/usersEditor.cpython-38.pyc
Normal file
Binary file not shown.
15
modules/mainPage.py
Normal file
15
modules/mainPage.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import streamlit as st
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
st.title('Добро пожаловать в просмотрщик базы даных')
|
||||
st.write('Вас приветствует простое приложение для работы с бд')
|
||||
|
||||
image = Image.open('./media/image.png')
|
||||
st.image(image, use_column_width=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
55
modules/ticketsMaker.py
Normal file
55
modules/ticketsMaker.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import streamlit as st
|
||||
import pymysql
|
||||
from re import match
|
||||
|
||||
connection = pymysql.connect(
|
||||
host='localhost',
|
||||
user='UserForDBViewerOnStreamlit',
|
||||
password='123',
|
||||
db='DBForDBViewerOnStreamlit'
|
||||
)
|
||||
|
||||
|
||||
def main(connection=connection):
|
||||
|
||||
def string_check(string):
|
||||
|
||||
if match('^[0-9A-Za-zA-Яa-яЁё -"/_]*$', string) and string:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def all_table_elements(TableName):
|
||||
|
||||
with connection:
|
||||
query = 'SELECT * FROM ' + TableName
|
||||
cursor = connection.cursor(pymysql.cursors.DictCursor)
|
||||
cursor.execute(query)
|
||||
rowsList = cursor.fetchall()
|
||||
return rowsList
|
||||
|
||||
usersList = all_table_elements('Users')
|
||||
|
||||
listToDisplay = []
|
||||
for i in range(len(usersList)):
|
||||
listToDisplay.append(
|
||||
str(usersList[i]['UserID']) + ' ' + usersList[i]['UserName'])
|
||||
|
||||
st.title('Создание заявок')
|
||||
choice = st.selectbox('Выберите пользователя', listToDisplay)
|
||||
ticketText = st.text_area('Введите текст заявки')
|
||||
AddButton = st.button('Создать')
|
||||
|
||||
if AddButton:
|
||||
if string_check(ticketText):
|
||||
with connection:
|
||||
cursor = connection.cursor()
|
||||
cursor.execute('INSERT INTO Tickets (TicketText, UserID) VALUES (\'' +
|
||||
ticketText + '\' , \'' + choice.split(' ')[0] + '\')')
|
||||
st.text('Заявка создана!')
|
||||
else:
|
||||
st.text('Некорректный ввод!')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
53
modules/ticketsViewer.py
Normal file
53
modules/ticketsViewer.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import streamlit as st
|
||||
import pymysql
|
||||
|
||||
connection = pymysql.connect(
|
||||
host='localhost',
|
||||
user='UserForDBViewerOnStreamlit',
|
||||
password='123',
|
||||
db='DBForDBViewerOnStreamlit'
|
||||
)
|
||||
|
||||
|
||||
def main(connection=connection):
|
||||
|
||||
def all_table_elements(TableName):
|
||||
|
||||
with connection:
|
||||
query = 'SELECT * FROM ' + TableName
|
||||
cursor = connection.cursor(pymysql.cursors.DictCursor)
|
||||
cursor.execute(query)
|
||||
rowsList = cursor.fetchall()
|
||||
return rowsList
|
||||
|
||||
def filtered_tickets(userID):
|
||||
|
||||
with connection:
|
||||
query = 'SELECT * FROM Tickets WHERE UserID IN (' + userID + ')'
|
||||
cursor = connection.cursor(pymysql.cursors.DictCursor)
|
||||
cursor.execute(query)
|
||||
userTickets = cursor.fetchall()
|
||||
return userTickets
|
||||
|
||||
usersList = all_table_elements('Users')
|
||||
st.title('Список пользователей и их заявок')
|
||||
st.dataframe(usersList)
|
||||
|
||||
listToDisplay = []
|
||||
for i in range(len(usersList)):
|
||||
listToDisplay.append(
|
||||
str(usersList[i]['UserID']) + ' ' + usersList[i]['UserName'])
|
||||
|
||||
filterBox = st.checkbox('Фильтр по пользователю')
|
||||
if filterBox:
|
||||
choice = st.selectbox(
|
||||
'Выберите пользователя для просмотра его заявок', listToDisplay)
|
||||
if choice is not None:
|
||||
userTickets = filtered_tickets(choice.split(' ')[0])
|
||||
st.dataframe(userTickets)
|
||||
else:
|
||||
st.dataframe(all_table_elements('Tickets'))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
82
modules/usersEditor.py
Normal file
82
modules/usersEditor.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import streamlit as st
|
||||
import pymysql
|
||||
from re import match
|
||||
|
||||
connection = pymysql.connect(
|
||||
host='localhost',
|
||||
user='UserForDBViewerOnStreamlit',
|
||||
password='123',
|
||||
db='DBForDBViewerOnStreamlit'
|
||||
)
|
||||
|
||||
|
||||
def main(connection=connection):
|
||||
|
||||
def string_check(string):
|
||||
|
||||
if match('^[-0-9A-Za-zA-Яa-яЁё ]*$', string) and not ("\\" in string) and string:
|
||||
return True
|
||||
else:
|
||||
st.text(
|
||||
'Некорректный ввод! Строка должно включать русские или английские буквы, цифры или дефис')
|
||||
return False
|
||||
|
||||
def all_table_elements(TableName):
|
||||
|
||||
with connection:
|
||||
query = 'SELECT * FROM ' + TableName
|
||||
cursor = connection.cursor(pymysql.cursors.DictCursor)
|
||||
cursor.execute(query)
|
||||
rowsList = cursor.fetchall()
|
||||
return rowsList
|
||||
|
||||
def user_add(userName):
|
||||
|
||||
if not string_check(userName):
|
||||
return False
|
||||
|
||||
with connection:
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(
|
||||
'INSERT INTO Users (UserName) VALUES (\'' + userName + '\')')
|
||||
return True
|
||||
|
||||
def user_delete(user):
|
||||
|
||||
if not string_check(user):
|
||||
return False
|
||||
|
||||
with connection:
|
||||
cursor = connection.cursor()
|
||||
try:
|
||||
cursor.execute(
|
||||
'DELETE FROM Users WHERE UserID IN (' + str(user.split(' ')[0]) + ')')
|
||||
except Exception:
|
||||
st.text('Польователь \"' + str(user) +
|
||||
'\" отсутствует или не может быть удален!')
|
||||
return False
|
||||
return True
|
||||
|
||||
st.title('Управление пользоватлями')
|
||||
usersList = all_table_elements('Users')
|
||||
userName = st.text_input('Введите имя нового пользователя')
|
||||
addButton = st.button('Добавить')
|
||||
user = st.text_input(
|
||||
'Введите ID и полное имя удаляемого пользователя через пробел')
|
||||
deleteButton = st.button('Удалить')
|
||||
|
||||
if addButton:
|
||||
if user_add(userName):
|
||||
st.text('Польователь \"' + userName + '\" успешно добавлен!')
|
||||
usersList = all_table_elements('Users')
|
||||
|
||||
if deleteButton:
|
||||
if user_delete(user):
|
||||
st.text('Польователь \"' + str(user) +
|
||||
'\" удален или отсутствовал!')
|
||||
usersList = all_table_elements('Users')
|
||||
st.dataframe(usersList)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user