._.
This commit is contained in:
parent
e522b0fb3f
commit
f6cc0558c8
@ -197,7 +197,6 @@ class Attendance(base):
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
date = Column(Date)
|
||||
is_attended = Column(Boolean)
|
||||
reason = Column(Text)
|
||||
|
||||
user_id = Column(Integer, ForeignKey('users.id'))
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import datetime
|
||||
|
||||
from PyQt6 import uic
|
||||
from PyQt6.QtWidgets import QDialog
|
||||
from PyQt6.QtWidgets import QDialog, QWidget, QHBoxLayout, QLabel, QDateEdit, QMessageBox
|
||||
|
||||
from data.connect import connect, Event, UserEvent, EventType, Attendance, VacationTimetable
|
||||
|
||||
@ -19,3 +21,322 @@ class EventsListDialog(QDialog):
|
||||
self.attendances = session.query(Attendance).filter(Attendance.user_id == user.id).all()
|
||||
|
||||
self.vacations = session.query(VacationTimetable).filter(VacationTimetable.user_id == user.id).all()
|
||||
|
||||
self.past = False
|
||||
self.current = False
|
||||
self.future = False
|
||||
|
||||
self.user = user
|
||||
|
||||
self.dateEdit.dateChanged.connect(self.set_minimum_date)
|
||||
self.dateEdit.setDate(datetime.date.today())
|
||||
|
||||
self.pushButton_3.clicked.connect(self.change_past)
|
||||
self.pushButton_2.clicked.connect(self.change_current)
|
||||
self.pushButton_4.clicked.connect(self.change_future)
|
||||
|
||||
self.label_6.setVisible(False)
|
||||
self.dateEdit_2.setVisible(False)
|
||||
|
||||
self.label_7.setVisible(False)
|
||||
self.lineEdit.setVisible(False)
|
||||
|
||||
self.comboBox.currentTextChanged.connect(self.change_type_event)
|
||||
|
||||
self.pushButton_5.clicked.connect(self.add_new_event)
|
||||
|
||||
self.change_future()
|
||||
self.change_current()
|
||||
|
||||
def add_new_event(self):
|
||||
if self.comboBox.currentText() == 'Обучение':
|
||||
with connect() as session:
|
||||
type_edu_event = session.query(EventType).filter(EventType.title == 'Обучение').first()
|
||||
|
||||
new_event = Event(
|
||||
type_id=type_edu_event.id,
|
||||
datetime_event=self.dateEdit.date().toPyDate()
|
||||
)
|
||||
session.add(new_event)
|
||||
session.flush()
|
||||
|
||||
new_user_event = UserEvent(
|
||||
event_id=new_event.id,
|
||||
user_id=self.user.id
|
||||
)
|
||||
session.add(new_user_event)
|
||||
session.commit()
|
||||
|
||||
elif self.comboBox.currentText() == 'Отгул':
|
||||
new_attendance = Attendance(
|
||||
date=self.dateEdit.date().toPyDate(),
|
||||
reason=self.lineEdit.text() if self.lineEdit.text() else None,
|
||||
user_id=self.user.id,
|
||||
)
|
||||
with connect() as session:
|
||||
session.add(new_attendance)
|
||||
session.commit()
|
||||
|
||||
elif self.comboBox.currentText() == 'Отпуск':
|
||||
new_vacation = VacationTimetable(
|
||||
user_id=self.user.id,
|
||||
start_date=self.dateEdit.date().toPyDate(),
|
||||
end_date=self.dateEdit_2.date().toPyDate()
|
||||
)
|
||||
with connect() as session:
|
||||
session.add(new_vacation)
|
||||
session.commit()
|
||||
|
||||
self.lineEdit.clear()
|
||||
QMessageBox.information(
|
||||
self,
|
||||
'Данные сохранены',
|
||||
'Новое событие было добавлено'
|
||||
)
|
||||
|
||||
with connect() as session:
|
||||
self.curses = session.query(Event).join(UserEvent).join(EventType).filter(
|
||||
UserEvent.user_id == self.user.id,
|
||||
EventType.title == 'Обучение'
|
||||
).all()
|
||||
|
||||
self.attendances = session.query(Attendance).filter(Attendance.user_id == self.user.id).all()
|
||||
|
||||
self.vacations = session.query(VacationTimetable).filter(VacationTimetable.user_id == self.user.id).all()
|
||||
|
||||
self.display_list()
|
||||
|
||||
def set_minimum_date(self):
|
||||
self.dateEdit_2.setMinimumDate(
|
||||
self.dateEdit.date().toPyDate() + datetime.timedelta(days=1)
|
||||
)
|
||||
|
||||
def change_type_event(self):
|
||||
if self.comboBox.currentText() == 'Обучение':
|
||||
self.label_6.setVisible(False)
|
||||
self.dateEdit_2.setVisible(False)
|
||||
|
||||
self.label_7.setVisible(False)
|
||||
self.lineEdit.setVisible(False)
|
||||
elif self.comboBox.currentText() == 'Отгул':
|
||||
self.label_6.setVisible(False)
|
||||
self.dateEdit_2.setVisible(False)
|
||||
|
||||
self.label_7.setVisible(True)
|
||||
self.lineEdit.setVisible(True)
|
||||
elif self.comboBox.currentText() == 'Отпуск':
|
||||
self.label_6.setVisible(True)
|
||||
self.dateEdit_2.setVisible(True)
|
||||
|
||||
self.label_7.setVisible(False)
|
||||
self.lineEdit.setVisible(False)
|
||||
|
||||
def change_future(self):
|
||||
self.future = not self.future
|
||||
|
||||
if self.future:
|
||||
self.pushButton_4.setStyleSheet('''
|
||||
QPushButton {
|
||||
background-color: #2f9836;
|
||||
}
|
||||
''')
|
||||
else:
|
||||
self.pushButton_4.setStyleSheet('''
|
||||
QPushButton {
|
||||
background-color: rgb(228, 244, 204);
|
||||
}
|
||||
''')
|
||||
|
||||
self.display_list()
|
||||
|
||||
def change_current(self):
|
||||
self.current = not self.current
|
||||
|
||||
if self.current:
|
||||
self.pushButton_2.setStyleSheet('''
|
||||
QPushButton {
|
||||
background-color: #2f9836;
|
||||
}
|
||||
''')
|
||||
else:
|
||||
self.pushButton_2.setStyleSheet('''
|
||||
QPushButton {
|
||||
background-color: rgb(228, 244, 204);
|
||||
}
|
||||
''')
|
||||
|
||||
self.display_list()
|
||||
|
||||
def change_past(self):
|
||||
self.past = not self.past
|
||||
|
||||
if self.past:
|
||||
self.pushButton_3.setStyleSheet('''
|
||||
QPushButton {
|
||||
background-color: #2f9836;
|
||||
}
|
||||
''')
|
||||
else:
|
||||
self.pushButton_3.setStyleSheet('''
|
||||
QPushButton {
|
||||
background-color: rgb(228, 244, 204);
|
||||
}
|
||||
''')
|
||||
|
||||
self.display_list()
|
||||
|
||||
def display_list(self):
|
||||
for i in range(self.verticalLayout.count()):
|
||||
self.verticalLayout.itemAt(i).widget().close()
|
||||
|
||||
for i in range(self.verticalLayout_2.count()):
|
||||
self.verticalLayout_2.itemAt(i).widget().close()
|
||||
|
||||
for i in range(self.verticalLayout_3.count()):
|
||||
self.verticalLayout_3.itemAt(i).widget().close()
|
||||
|
||||
curses = sorted(self.curses, key=lambda x: x.datetime_event)
|
||||
attendances = sorted(self.attendances, key=lambda x: x.date)
|
||||
vacations = sorted(self.vacations, key=lambda x: x.start_date)
|
||||
|
||||
if self.past:
|
||||
past_curser = list(
|
||||
filter(
|
||||
lambda x: x.datetime_event.date() < datetime.date.today(),
|
||||
curses
|
||||
)
|
||||
)
|
||||
|
||||
for i in past_curser:
|
||||
event_widget = EventWidget(i.datetime_event)
|
||||
self.verticalLayout.addWidget(event_widget)
|
||||
|
||||
past_attendances = list(
|
||||
filter(
|
||||
lambda x: x.date < datetime.date.today(),
|
||||
attendances
|
||||
)
|
||||
)
|
||||
|
||||
for i in past_attendances:
|
||||
event_widget = EventWidget(i.date, reason=i.reason)
|
||||
self.verticalLayout_2.addWidget(event_widget)
|
||||
|
||||
past_vacations = list(
|
||||
filter(
|
||||
lambda x: x.start_date < datetime.date.today(),
|
||||
vacations
|
||||
)
|
||||
)
|
||||
|
||||
for i in past_vacations:
|
||||
event_widget = EventWidget(i.start_date, i.end_date)
|
||||
self.verticalLayout_3.addWidget(event_widget)
|
||||
|
||||
if self.current:
|
||||
current_curser = list(
|
||||
filter(
|
||||
lambda x: x.datetime_event.date() == datetime.date.today(),
|
||||
curses
|
||||
)
|
||||
)
|
||||
|
||||
for i in current_curser:
|
||||
event_widget = EventWidget(i.datetime_event)
|
||||
self.verticalLayout.addWidget(event_widget)
|
||||
|
||||
current_attendances = list(
|
||||
filter(
|
||||
lambda x: x.date == datetime.date.today(),
|
||||
attendances
|
||||
)
|
||||
)
|
||||
|
||||
for i in current_attendances:
|
||||
event_widget = EventWidget(i.date, reason=i.reason)
|
||||
self.verticalLayout_2.addWidget(event_widget)
|
||||
|
||||
current_vacations = list(
|
||||
filter(
|
||||
lambda x: x.start_date <= datetime.date.today() <= x.end_date,
|
||||
vacations
|
||||
)
|
||||
)
|
||||
|
||||
for i in current_vacations:
|
||||
event_widget = EventWidget(i.start_date, i.end_date)
|
||||
self.verticalLayout_3.addWidget(event_widget)
|
||||
|
||||
if self.future:
|
||||
future_curser = list(
|
||||
filter(
|
||||
lambda x: x.datetime_event.date() > datetime.date.today(),
|
||||
curses
|
||||
)
|
||||
)
|
||||
|
||||
for i in future_curser:
|
||||
event_widget = EventWidget(i.datetime_event)
|
||||
self.verticalLayout.addWidget(event_widget)
|
||||
|
||||
future_attendances = list(
|
||||
filter(
|
||||
lambda x: x.date > datetime.date.today(),
|
||||
attendances
|
||||
)
|
||||
)
|
||||
|
||||
for i in future_attendances:
|
||||
event_widget = EventWidget(i.date, reason=i.reason)
|
||||
self.verticalLayout_2.addWidget(event_widget)
|
||||
|
||||
future_vacations = list(
|
||||
filter(
|
||||
lambda x: x.start_date > datetime.date.today(),
|
||||
vacations
|
||||
)
|
||||
)
|
||||
|
||||
for i in future_vacations:
|
||||
event_widget = EventWidget(i.start_date, i.end_date)
|
||||
self.verticalLayout_3.addWidget(event_widget)
|
||||
|
||||
|
||||
class EventWidget(QWidget):
|
||||
def __init__(self, start_date, end_date=None, reason=None):
|
||||
super().__init__()
|
||||
|
||||
self.setMinimumHeight(90)
|
||||
self.setMaximumHeight(90)
|
||||
|
||||
self.layout = QHBoxLayout()
|
||||
label1 = QLabel(
|
||||
str(start_date) if end_date is None else 'Дата начала:\n' + str(start_date)
|
||||
)
|
||||
self.layout.addWidget(label1)
|
||||
|
||||
if not end_date is None:
|
||||
label2 = QLabel(
|
||||
'Дата окончания:\n' + str(end_date)
|
||||
)
|
||||
self.layout.addWidget(label2)
|
||||
|
||||
if not reason is None:
|
||||
label3 = QLabel('Причина:\n' + reason)
|
||||
self.layout.addWidget(label3)
|
||||
|
||||
wdg = QWidget()
|
||||
|
||||
wdg.setLayout(self.layout)
|
||||
wdg.setStyleSheet('''
|
||||
QWidget {
|
||||
border: 1px solid black;
|
||||
}
|
||||
QLabel {
|
||||
border: none;
|
||||
}
|
||||
''')
|
||||
|
||||
lyt = QHBoxLayout()
|
||||
lyt.addWidget(wdg)
|
||||
self.setLayout(lyt)
|
||||
|
||||
@ -26,13 +26,91 @@
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QPushButton {
|
||||
background-color: rgb(228, 244, 204);
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #2f9836;
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="2" colspan="3">
|
||||
<item row="1" column="0" rowspan="6" colspan="2">
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>69</width>
|
||||
<height>606</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="7" column="5">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="5">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Назад</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3" rowspan="5" colspan="3">
|
||||
<widget class="QScrollArea" name="scrollArea_2">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
@ -42,8 +120,8 @@ background-color: #2f9836;
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>923</width>
|
||||
<height>606</height>
|
||||
<width>897</width>
|
||||
<height>504</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
@ -82,8 +160,8 @@ background-color: #2f9836;
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>903</width>
|
||||
<height>554</height>
|
||||
<width>877</width>
|
||||
<height>452</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
@ -125,36 +203,7 @@ background-color: #2f9836;
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>69</width>
|
||||
<height>606</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Назад</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<item row="7" column="3">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -167,8 +216,111 @@ background-color: #2f9836;
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<item row="5" column="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="6" column="3" colspan="3">
|
||||
<widget class="QScrollArea" name="scrollArea_4">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>897</width>
|
||||
<height>94</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="3" column="4">
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QDateEdit" name="dateEdit">
|
||||
<property name="calendarPopup">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="5">
|
||||
<widget class="QPushButton" name="pushButton_5">
|
||||
<property name="text">
|
||||
<string>Добавить</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="3">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Тип события</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="2">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Дата начала</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Обучение</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Отгул</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Отпуск</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QDateEdit" name="dateEdit_2">
|
||||
<property name="calendarPopup">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4" rowspan="3">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Краткое обоснование</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3" rowspan="3">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Дата окончания</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="4">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
@ -180,15 +332,15 @@ background-color: #2f9836;
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<item row="2" column="2">
|
||||
<spacer name="verticalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user