Exemplo n.º 1
0
    def add_rental(self):
        """Add rental to DB."""

        # TODO: Check whether disk is available
        session = db.get_session()
        rental = {
            "rent_customer": int(self.le_customer.text()),
            "rent_disk": int(self.le_disk.text()),
            "returned": False,
            "time_taken": self.dte_time_taken.dateTime().toPyDateTime(),
            "time_returned": None,
            "deposit": int(self.le_deposit.text()),
        }

        if self.upd:
            rental["returned"] = True
            rental["time_returned"] = self.dte_time_returned.dateTime(
            ).toPyDateTime()

        # TODO: Do smth with disk return time
        # if not all(rental.values()):
        #    required_field_empty_warning(self)
        # else:

        db.insert_objects(Rental(**rental), self.rental_id)

        # TODO: implement this via ORM trigger, not user interface
        r_disk = session.query(Disk).filter(
            Disk.id == rental["rent_disk"]).first()
        r_disk.existance = self.upd
        db.insert_objects(r_disk, r_disk.id)
Exemplo n.º 2
0
    def add_disk(self):

        session = db.get_session()

        actors = [
            resp for name in map(str.strip,
                                 str(self.le_actors.text()).split(","))
            for resp in session.query(Actor).filter(Actor.name == name)
        ]

        genre = [
            resp for name in map(str.strip,
                                 str(self.le_genre.text()).split(","))
            for resp in session.query(Genre).filter(Genre.film_genre == name)
        ]

        disk = {
            "acq_date": to_date(self.de_acq_date.date()),
            "title": str(self.le_title.text()),
            "director": str(self.le_director.text()),
            "year": int(self.le_year.text()),
            "rating": int(self.sb_rating.value()),
            "existance": self.cb_existance.isChecked(),
            "actors": actors,
            "genre": genre
        }

        disk = Disk(**disk)

        # if not all(disk.values()):
        #     required_field_empty_warning(self)
        # else:

        db.insert_objects(disk, self.disk_id)
Exemplo n.º 3
0
    def load_customer_info(self):
        """Get all needed info from DB."""

        session = db.get_session()
        customer = session.query(Customer).filter(
            Customer.id == self.customer_id).first()

        self.le_ph_number.setText(customer.phone_number)
        self.le_name.setText(customer.name)
        self.le_passport.setText(customer.passport)
        self.le_ordered.setText(str(customer.ordered))
Exemplo n.º 4
0
def count_curr_deposit():
    """Count sum of all deposits available."""

    res = 0

    session = db.get_session()
    depo = session.query(Rental).filter(Rental.time_returned == None).all()

    for i in depo:
        res += i.deposit

    return res
Exemplo n.º 5
0
    def load_disk_info(self):

        session = db.get_session()
        disk = session.query(Disk).filter(Disk.id == self.disk_id).first()

        genre = [str(gen.film_genre) for gen in disk.genre]

        actors = [act.name for act in disk.actors]

        self.le_title.setText(disk.title)
        self.le_director.setText(disk.director)
        self.le_year.setText(str(disk.year))
        self.le_genre.setText(", ".join(genre))
        self.le_actors.setText(", ".join(actors))
        self.cb_existance.setChecked(disk.existance)
        self.de_acq_date.setDate(from_date(disk.acq_date))
        self.sb_rating.setValue(disk.rating)
Exemplo n.º 6
0
    def remove_selected(self):
        """Remove selected item from current table."""

        if not self.selected:
            required_field_empty_warning(self, "Select item for removal.")

        # on (row, 0) placed entity ID
        model_id = int(self.table_widget.item(self.selected[0], 0).text())

        if not DeleteDialog(
                "item with ID = {0}".format(model_id),
                self.model.__tablename__).exec_() == QDialog.Accepted:
            return

        session = db.get_session()
        rm_model = session.query(
            self.model).filter(self.model.id == model_id).first()
        session.delete(rm_model)
        session.commit()
        self.show_table(self.model)
Exemplo n.º 7
0
    def load_rental_info(self):
        """Get all needed info from DB."""

        self.cb_returned.setEnabled(True)

        session = db.get_session()
        rental = session.query(Rental).filter(
            Rental.id == self.rental_id).first()

        # TODO: Disk return time
        self.le_customer.setText(str(rental.rent_customer))
        self.customer_name.setText(
            session.query(Customer).filter(
                Customer.id == rental.rent_customer).first().name)
        self.le_disk.setText(str(rental.rent_disk))
        self.disk_title.setText(
            session.query(Disk).filter(
                Disk.id == rental.rent_disk).first().title)
        self.dte_time_taken.setDateTime(from_datetime(rental.time_taken))
        self.dte_time_returned.setDateTime(from_datetime(rental.time_returned))
        self.le_deposit.setText(str(rental.deposit))
Exemplo n.º 8
0
    def show_table(self, model):
        """Show all entries of model in table."""

        self.model = model
        session = db.get_session()
        names = model.__table__.columns.keys()
        data = list(session.query(model))

        rows = len(data)
        cols = len(names)
        self.table_widget.clear()
        self.table_widget.setSortingEnabled(True)
        self.table_widget.setRowCount(rows)
        self.table_widget.setColumnCount(cols)
        self.table_widget.setHorizontalHeaderLabels(names)
        self.table_widget.horizontalHeader().setResizeMode(QHeaderView.Fixed)
        # self.table_widget.sortByColumn(0, Qt.AscendingOrder)

        for row in range(rows):
            for col in range(cols):
                item = QTableWidgetItem(str(data[row].__dict__[names[col]]))
                self.table_widget.setItem(row, col, item)

        self.l_curr_deposit.setText(str(count_curr_deposit()))
Exemplo n.º 9
0
    def load_actor_info(self):
        session = db.get_session()
        actor = session.query(Actor).filter(Actor.id == self.actor_id).first()

        self.le_name.setText(actor.name if actor else "")
Exemplo n.º 10
0
    def load_genre_info(self):
        session = db.get_session()
        genre = session.query(Genre).filter(Genre.id == self.genre_id).first()

        self.le_name.setText(genre.film_genre if genre else "")