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:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
./venv
|
||||
37
DBViewer.py
Normal file
37
DBViewer.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import streamlit as st
|
||||
import pymysql
|
||||
import modules.mainPage
|
||||
import modules.ticketsViewer
|
||||
import modules.ticketsMaker
|
||||
import modules.usersEditor
|
||||
|
||||
|
||||
connection = pymysql.connect(
|
||||
host='localhost',
|
||||
user='UserForDBViewerOnStreamlit',
|
||||
password='123',
|
||||
db='DBForDBViewerOnStreamlit'
|
||||
)
|
||||
|
||||
st.sidebar.title('Навигация')
|
||||
pages = st.sidebar.radio('Страницы', ['Главная',
|
||||
'Просмотр заявок',
|
||||
'Создание заявок',
|
||||
'Управление пользователями']
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
if pages == 'Главная':
|
||||
modules.mainPage.main()
|
||||
elif pages == 'Просмотр заявок':
|
||||
modules.ticketsViewer.main(connection)
|
||||
elif pages == 'Создание заявок':
|
||||
modules.ticketsMaker.main(connection)
|
||||
elif pages == 'Управление пользователями':
|
||||
modules.usersEditor.main(connection)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
78
db.sql
Normal file
78
db.sql
Normal file
@@ -0,0 +1,78 @@
|
||||
-- MariaDB dump 10.17 Distrib 10.4.12-MariaDB, for Linux (x86_64)
|
||||
--
|
||||
-- Host: localhost Database: DBForDBViewerOnStreamlit
|
||||
-- ------------------------------------------------------
|
||||
-- Server version 10.4.12-MariaDB
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
--
|
||||
-- Table structure for table `Tickets`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `Tickets`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `Tickets` (
|
||||
`TicketID` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`TicketText` varchar(300) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`UserID` int(11) NOT NULL,
|
||||
`TicketDate` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`TicketResolved` tinyint(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`TicketID`),
|
||||
KEY `UserID` (`UserID`),
|
||||
CONSTRAINT `Tickets_ibfk_1` FOREIGN KEY (`UserID`) REFERENCES `Users` (`UserID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `Tickets`
|
||||
--
|
||||
|
||||
LOCK TABLES `Tickets` WRITE;
|
||||
/*!40000 ALTER TABLE `Tickets` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `Tickets` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `Users`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `Users`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `Users` (
|
||||
`UserID` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`UserName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`UserID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `Users`
|
||||
--
|
||||
|
||||
LOCK TABLES `Users` WRITE;
|
||||
/*!40000 ALTER TABLE `Users` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `Users` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2020-02-11 19:07:28
|
||||
BIN
media/image.png
Normal file
BIN
media/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 71 KiB |
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()
|
||||
71
requirements.txt
Normal file
71
requirements.txt
Normal file
@@ -0,0 +1,71 @@
|
||||
altair==4.0.1
|
||||
astor==0.8.1
|
||||
attrs==19.3.0
|
||||
backcall==0.1.0
|
||||
base58==2.0.0
|
||||
bleach==3.1.0
|
||||
blinker==1.4
|
||||
boto3==1.11.14
|
||||
botocore==1.14.14
|
||||
certifi==2019.11.28
|
||||
chardet==3.0.4
|
||||
Click==7.0
|
||||
decorator==4.4.1
|
||||
defusedxml==0.6.0
|
||||
docutils==0.15.2
|
||||
entrypoints==0.3
|
||||
enum-compat==0.0.3
|
||||
future==0.18.2
|
||||
idna==2.8
|
||||
ipykernel==5.1.4
|
||||
ipython==7.12.0
|
||||
ipython-genutils==0.2.0
|
||||
ipywidgets==7.5.1
|
||||
jedi==0.16.0
|
||||
Jinja2==2.11.1
|
||||
jmespath==0.9.4
|
||||
jsonschema==3.2.0
|
||||
jupyter-client==5.3.4
|
||||
jupyter-core==4.6.2
|
||||
MarkupSafe==1.1.1
|
||||
mistune==0.8.4
|
||||
nbconvert==5.6.1
|
||||
nbformat==5.0.4
|
||||
notebook==6.0.3
|
||||
numpy==1.18.1
|
||||
pandas==1.0.1
|
||||
pandocfilters==1.4.2
|
||||
parso==0.6.1
|
||||
pathtools==0.1.2
|
||||
pexpect==4.8.0
|
||||
pickleshare==0.7.5
|
||||
Pillow==7.0.0
|
||||
prometheus-client==0.7.1
|
||||
prompt-toolkit==3.0.3
|
||||
protobuf==3.11.3
|
||||
ptyprocess==0.6.0
|
||||
pydeck==0.2.1
|
||||
Pygments==2.5.2
|
||||
PyMySQL==0.9.3
|
||||
pyrsistent==0.15.7
|
||||
python-dateutil==2.8.0
|
||||
pytz==2019.3
|
||||
pyzmq==18.1.1
|
||||
requests==2.22.0
|
||||
s3transfer==0.3.3
|
||||
Send2Trash==1.5.0
|
||||
six==1.14.0
|
||||
streamlit==0.55.0
|
||||
terminado==0.8.3
|
||||
testpath==0.4.4
|
||||
toml==0.10.0
|
||||
toolz==0.10.0
|
||||
tornado==5.1.1
|
||||
traitlets==4.3.3
|
||||
tzlocal==2.0.0
|
||||
urllib3==1.25.8
|
||||
validators==0.14.2
|
||||
watchdog==0.10.2
|
||||
wcwidth==0.1.8
|
||||
webencodings==0.5.1
|
||||
widgetsnbextension==3.5.1
|
||||
Reference in New Issue
Block a user