DialogHistory.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 logger import logger
  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 as err:
  28. logger.debug(err)
  29. self.browser.clear()
  30. except OSError as err:
  31. logger.debug(err)
  32. @Slot(str)
  33. def filter_items(self, text: str) -> None:
  34. for index in range(self.list_propusk.count()):
  35. item = self.list_propusk.item(index)
  36. if text:
  37. item.setHidden(not self.match_text(text, item.text()))
  38. else:
  39. item.setHidden(False)
  40. def match_text(self, text, keywords) -> None:
  41. return text in keywords
  42. def load_data(self) -> None:
  43. with connect() as conn:
  44. rows = conn.execute(
  45. list_propusk.select()) \
  46. .all()
  47. for line in rows:
  48. self.list_propusk.addItem(str(line.id_propusk))
  49. def load_page(self, id_propusk: int) -> None:
  50. with connect() as conn:
  51. row = conn.execute(
  52. select(
  53. list_propusk.c.id_propusk,
  54. list_propusk.c.date_from,
  55. list_propusk.c.date_to,
  56. func.format(
  57. list_personal.c.lastname
  58. + " " + list_personal.c.firstname
  59. + " " + list_personal.c.middlename)
  60. .label("personal"),
  61. func.format(list_place.c.name_place).label("place"),
  62. list_propusk.c.receiving_man,
  63. list_propusk.c.purpose_visite,
  64. list_propusk.c.face,
  65. list_propusk.c.document
  66. ).select_from(list_propusk).join(
  67. list_personal, list_propusk.c.personal == list_personal.c.id
  68. ).join(
  69. list_place, list_propusk.c.place == list_place.c.id
  70. ).where(list_propusk.c.id_propusk == id_propusk)
  71. ).fetchone()
  72. pdm = PropuskDataMethods(*row)
  73. face = os.path.join(os.environ.get('PHOTO_DIR'), pdm.get_value("face"))
  74. documet = os.path.join(os.environ.get('PHOTO_DIR'), pdm.get_value("document"))
  75. pdm.set_value("face", face)
  76. pdm.set_value("document", documet)
  77. render_text = str(TemplatePropusk(pdm._propusk_data.__dict__,
  78. os.path.join(os.path.dirname(
  79. os.path.abspath(__package__)), 'docs')
  80. ))
  81. self.browser.setText(render_text)