Exemple #1
0
 def add_movie(self):
     """ button btn_create_movie """
     line_title = self.line_title.text()
     line_production_year = self.line_production_year.text()
     viewed = self.checkBox_viewed.isChecked()
     if "" not in [line_title, line_production_year]:
         self.line_title.clear()
         self.line_production_year.clear()
         self.checkBox_viewed.setChecked(False)
         Movies.create(title=line_title, production_year=date(int(line_production_year), 1, 1), viewed=viewed)
Exemple #2
0
    def item_changed(self, item: QtWidgets.QTableWidgetItem):

        if self.column_name[item.column()] == 'title':
            field = {self.column_name[item.column()]: item.text()}  # field for change {id: 'value'}
            result = Movies.update(**field).where(Movies.id == self.id_dict[item.row()]).execute()
            #  result = Movies.update(title=item.text()) не работает
        elif self.column_name[item.column()] == 'production_year':
            try:
                #  подключить виджет для корректного ввода данных?
                field = {self.column_name[item.column()]: item.text()}
                result = Movies.update(**field).where(Movies.id == self.id_dict[item.row()]).execute()
            except Exception:  #  peewee.
                self.create_qmessage_box_without_choice('', "Неправильый формат даты\nправильно ГГГГ-ММ-ДД")
        elif self.column_name[item.column()] == 'viewed':
            field = {self.column_name[item.column()]: item.text() == 'True'}
            result = Movies.update(**field).where(Movies.id == self.id_dict[item.row()]).execute()
Exemple #3
0
def print_movies_from_db(self):
    self.clear_table()
    self.movies_list.setHorizontalHeaderLabels(["title", "year", "viewed"])
    self.id_dict = {}
    for row, movie in enumerate(Movies.select()):
        self.id_dict[row] = movie.id
        self.movies_list.insertRow(self.movies_list.rowCount())
        self.movies_list.setItem(row, 0, Item(movie.title))
        self.movies_list.setItem(row, 1, Item(str(movie.production_year)))
        self.movies_list.setItem(row, 2, Item(str(movie.viewed)))
    print(self.id_dict)
Exemple #4
0
    def delete_by_id(self, id_row):
        """ button btn_delete_by_id """
        # if id_row == -1:
        #     id_row = Movies.select().order_by(Movies.id.desc()).get()

        Movies.select().where(Movies.id == id_row).get().delete_instance()
Exemple #5
0
 def paste_item(self):
     print(self.cells_data)
     Movies.create(**self.cells_data)
Exemple #6
0
 def clear_all(self):
     if self.create_qmessage_box('', 'Вы уверены?'):
         Movies.delete().execute()
         self.clear_table()
Exemple #7
0
 def add_row(self, movie: Movies = None) -> Movies:
     return Movies.create(title='Null', production_year=date(1900, 1, 1), viewed=False)