DialogHistory.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from PySide6.QtWidgets import QDialog
  2. from PySide6.QtCore import Slot
  3. from .ui_py.ui_DialogHistory import Ui_DialogHistory
  4. from module.WorkWithDB import connect, list_propusk, list_personal, list_place
  5. from sqlalchemy import select, func
  6. from module.ModelPropusk import PropuskDataMethods
  7. from module.TemplatePropusk import TemplatePropusk
  8. import os
  9. from module.ImageTool import rotate_image
  10. # from PySide6.QtGui import QStandardItemModel
  11. class DialogHistory(Ui_DialogHistory, QDialog):
  12. def __init__(self, parent=None):
  13. super(DialogHistory, self).__init__(parent)
  14. self.setupUi(self)
  15. self.line_search.textChanged.connect(
  16. self.filter_items
  17. )
  18. self.list_propusk.itemSelectionChanged.connect(
  19. self.selected_item
  20. )
  21. self.load_data()
  22. self.list_propusk.setCurrentRow(0)
  23. def selected_item(self) -> None:
  24. try:
  25. id_propusk = self.list_propusk.selectedItems()[0].text()
  26. self.load_page(int(id_propusk))
  27. except IndexError:
  28. self.browser.clear()
  29. @Slot(str)
  30. def filter_items(self, text: str) -> None:
  31. for index in range(self.list_propusk.count()):
  32. item = self.list_propusk.item(index)
  33. if text:
  34. item.setHidden(not self.match_text(text, item.text()))
  35. else:
  36. item.setHidden(False)
  37. def match_text(self, text, keywords) -> None:
  38. return text in keywords
  39. def load_data(self) -> None:
  40. with connect() as conn:
  41. rows = conn.execute(
  42. list_propusk.select()) \
  43. .all()
  44. for line in rows:
  45. self.list_propusk.addItem(str(line.id_propusk))
  46. def load_page(self, id_propusk: int) -> None:
  47. with connect() as conn:
  48. row = conn.execute(
  49. select(
  50. list_propusk.c.id_propusk,
  51. list_propusk.c.date_from,
  52. list_propusk.c.date_to,
  53. func.format(
  54. list_personal.c.lastname
  55. + " " + list_personal.c.firstname
  56. + " " + list_personal.c.middlename)
  57. .label("personal"),
  58. func.format(list_place.c.name_place).label("place"),
  59. list_propusk.c.receiving_man,
  60. list_propusk.c.purpose_visite,
  61. list_propusk.c.face_photo
  62. ).select_from(list_propusk).join(
  63. list_personal, list_propusk.c.personal == list_personal.c.id
  64. ).where(list_propusk.c.id_propusk == id_propusk)
  65. ).fetchone()
  66. pdm = PropuskDataMethods(*row)
  67. pdm.set_value("face_photo",
  68. rotate_image(pdm.get_value("face_photo"))
  69. )
  70. render_text = str(TemplatePropusk(pdm._propusk_data.__dict__,
  71. os.path.join(os.path.dirname(
  72. os.path.abspath(__package__)), 'docs')
  73. ))
  74. self.browser.setText(render_text)