This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_portfolio.py
54 lines (43 loc) · 1.99 KB
/
edit_portfolio.py
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
import sys
import datetime
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
from py_ui.edit_portfolio import Ui_Dialog
from service import *
from config import *
class EditPortfolio(QDialog, Ui_Dialog):
def __init__(self):
super().__init__()
self.setupUi(self)
self.fill_portfolio_list()
self.btn_delete.clicked.connect(self.delete_portfolio_item)
def delete_portfolio_item(self):
ans = QMessageBox.question(self, 'Уверены?', 'Вы точно хотите удалить это и из своего портфолио?')
if ans == QMessageBox.Yes:
selected_row = self.list_portfolio.currentRow()
selected_row_text = self.list_portfolio.item(selected_row).text()
selected_row_data = selected_row_text.split('; ')
data = {
'competitions_name': selected_row_data[0],
'place': selected_row_data[1],
'datetime': int(datetime.datetime.strptime(selected_row_data[2], '%d.%m.%Y').timestamp())
}
delete_portfolio_item(data)
QMessageBox.information(self, 'Успешно!', 'Это удалено с вашего портфолио')
self.remove_from_list(selected_row)
def remove_from_list(self, row_index):
self.list_portfolio.takeItem(row_index)
def fill_portfolio_list(self):
user_portfolio = get_user_portfolio()
for portfolio_item in user_portfolio:
competitions_name = portfolio_item[1]
place = portfolio_item[2]
datetime_ = datetime.datetime.fromtimestamp(portfolio_item[3]).strftime('%d.%m.%Y')
self.list_portfolio.addItem(f'{competitions_name}; {place}; {datetime_}')
def except_hook(cls, exception, traceback):
sys.__excepthook__(cls, exception, traceback)
if __name__ == '__main__':
app = QApplication(sys.argv)
app_ = EditPortfolio()
app_.show()
sys.excepthook = except_hook
sys.exit(app.exec())