def updateActor(self, id, actor):
     actorTemp = self.getActorById(id)
     actorTemp = objectview({**actorTemp, **actor})
     DButils.executemany(ActorSql.update_actor,
                         (actorTemp.first_name, actorTemp.last_name, id),
                         True)
     return self.getActorById(id)
Exemple #2
0
    def addFilm(self, film):
        try:
            film = objectview(film)
            _sqls = [{
                'query':
                FilmSql.INSERT_FILM,
                'args':
                (film.title or None, film.description
                 or None, film.release_year or None, film.language_id
                 or None, film.original_language_id
                 or None, film.rental_duration or 0, film.rental_rate
                 or 0, film.length or None, film.replacement_cost
                 or 0, film.rating or None, film.special_features or None)
            }]

            _sqls.append({
                'query': FilmSql.INSERT_FILM_CATEGORY,
                'args': (film.category_id)
            })

            for actor_id in film.actor_ids:
                _sqls.append({
                    'query': FilmSql.INSERT_FILM_ACTOR,
                    'args': (actor_id)
                })
            DButils.executeSqls(_sqls)
            return True
        except Exception as e:
            raise Exception(e)
 def addActor(self, actor):
     try:
         actor = objectview(actor)
         DButils.execute(ActorSql.insert_actor,
                         (actor.first_name, actor.last_name), True)
         return 'OK'
     except Exception as e:
         raise e
Exemple #4
0
    def updateFilm(self, film):
        try:
            pass
            # get film
            filmDB = DButils.execute(FilmSql.SELECT_FILM_BY_ID,
                                     film['film_id'])
            film = objectview({**filmDB, **film})

            # update film film_actor film_category
            _sqls = []
            _sqls.append({
                'query':
                FilmSql.UPDATE_FILM,
                'args':
                (film.title or None, film.description
                 or None, film.release_year or None, film.language_id or None,
                 film.original_language_id or None, film.rental_duration
                 or 0, film.rental_rate or 0, film.length
                 or None, film.replacement_cost or 0, film.rating
                 or None, film.special_features or None, film.film_id)
            })

            if film.category_id is not None:
                _sqls.append({
                    'query': FilmSql.UPDATE_CATEGORY_FILM,
                    'args': (film.category_id, film.film_id)
                })

            if film.actor_ids is not None and len(film.actor_ids) > 0:

                _sqls.append({
                    'query': FilmSql.DELETE_ACTOR_FILM,
                    'args': film.film_id
                })

                for actor_id in film.actor_ids:
                    _sqls.append({
                        'query': FilmSql.INSERT_ACTOR_FILM_WITH_ID,
                        'args': (actor_id, film.film_id)
                    })

            return DButils.executeSqls(_sqls)
        except Exception as e:
            raise e
Exemple #5
0
    def deleteFilm(self, id):
        try:
            sqls = [{
                'query': FilmSql.DELETE_ACTOR_FILM,
                'args': id
            }, {
                'query': FilmSql.DELETE_CATEGORY_FILM,
                'args': id
            }, {
                'query': FilmSql.DELETE_FILM,
                'args': id
            }]

            return DButils.executeSqls(sqls)
        except Exception as e:
            raise e
Exemple #6
0
 def getFilmsByCategory(self, category):
     result = DButils.executemany(FilmSql.SELECT_FILMINFO_BY_CATEGORY,
                                  (category))
     return result
Exemple #7
0
 def getFilmsByActorName(self, name):
     result = DButils.executemany(FilmSql.SELECT_FILMINFO_BY_ACTOR, (name))
     return result
Exemple #8
0
 def getFilmsByLanguageId(self, languageId):
     result = DButils.executemany(FilmSql.SELECT_FILMINFO_BY_LANGUAGE,
                                  (languageId))
     return result
Exemple #9
0
 def getFilmsById(self, id):
     result = DButils.execute(FilmSql.SELECT_FILMINFO_BY_ID, (id))
     return result
Exemple #10
0
 def getFilms(self):
     result = DButils.executemany(FilmSql.SELECT_FILMS)
     return result
 def deleteActorById(self, id):
     try:
         DButils.executemany(ActorSql.delete_actor, id)
         return 'OK'
     except Exception as e:
         raise e
 def getActorsByFilmId(self, id):
     result = DButils.executemany(ActorSql.select_actor_by_film_id, (id))
     return result
 def getActorById(self, id):
     result = DButils.execute(ActorSql.select_actor_by_id, (id))
     return result
 def getActor(self):
     result = DButils.executemany(ActorSql.select_actor, None)
     return result