示例#1
0
    def edit_movie_callback(new_movie: config.MovieTypedDict,
                            selected_tags: Sequence[str]):
        """ Change movie and links in database in accordance with new user supplied data,
    
        Args:
            new_movie: Fields with either original values or values modified by the user.
            selected_tags:
                Consist of:
                Previously unselected tags that have been selected by the user
                And previously selected tags that have not been deselected by the user.
                
        Raises exception.DatabaseSearchFoundNothing
        """

        # Edit the movie
        database.replace_movie(old_movie, new_movie)

        # Edit links
        old_tags = database.movie_tags(old_movie)
        new_movie = config.MovieKeyTypedDict(title=new_movie['title'],
                                             year=new_movie['year'])

        try:
            database.edit_movie_tag_links(new_movie, old_tags, selected_tags)

        # Can't add tags because new movie has been deleted.
        except exception.DatabaseSearchFoundNothing:
            missing_movie_args = (
                config.app.tk_root, 'Missing movie',
                f'The movie {new_movie} is no longer in the database. It may have '
                f'been deleted by another process. ')
            guiwidgets.gui_messagebox(*missing_movie_args)
示例#2
0
 def delete(self):
     """The user clicked the 'Delete' button. """
     if messagebox.askyesno(message='Do you want to delete this movie?',
                            icon='question', default='no', parent=self.parent):
         movie = config.MovieKeyTypedDict(title=self.entry_fields['title'].original_value,
                                          year=int(self.entry_fields['year'].original_value))
         # moviedb-#148 Handle exception for missing database record
         #   See test_guiwidgets.TestAddMovieGUI.test_commit_callback_method for test method
         self.delete_callback(movie)
         self.destroy()
示例#3
0
def add_movie_callback(movie: config.MovieTypedDict,
                       selected_tags: Sequence[str]):
    """ Add user supplied data to the database.

    Args:
        movie:
        selected_tags:
    """
    database.add_movie(movie)
    movie = config.MovieKeyTypedDict(title=movie['title'], year=movie['year'])
    for tag in selected_tags:
        database.add_movie_tag_link(tag, movie)
示例#4
0
def select_movie_callback(title: str, year: int):
    """Edit a movie selected by the user from a list of movies.
    
    Args:
        title:
        year:
    """

    # Get record from database
    movie = database.find_movies(dict(title=title, year=year))[0]
    movie_key = config.MovieKeyTypedDict(title=movie['title'],
                                         year=movie['year'])
    # PyCharm bug https://youtrack.jetbrains.com/issue/PY-41268
    # noinspection PyTypeChecker
    guiwidgets.EditMovieGUI(config.app.tk_root,
                            edit_movie_callback_wrapper(movie_key),
                            delete_movie_callback, ['commit', 'delete'],
                            database.all_tags(), movie)
示例#5
0
    # Find compliant movies.
    criteria['tags'] = tags
    # Remove empty items because SQL treats them as meaningful.
    criteria = {
        k: v
        for k, v in criteria.items()
        if v != '' and v != [] and v != () and v != ['', '']
    }
    movies = database.find_movies(criteria)

    if (movies_found := len(movies)) <= 0:
        raise exception.DatabaseSearchFoundNothing
    elif movies_found == 1:
        movie = movies[0]
        movie_key = config.MovieKeyTypedDict(title=movie['title'],
                                             year=movie['year'])
        # PyCharm bug https://youtrack.jetbrains.com/issue/PY-41268
        # noinspection PyTypeChecker
        guiwidgets.EditMovieGUI(config.app.tk_root,
                                edit_movie_callback_wrapper(movie_key),
                                delete_movie_callback, ['commit', 'delete'],
                                database.all_tags(), movie)
    else:
        guiwidgets.SelectMovieGUI(config.app.tk_root, movies,
                                  select_movie_callback)


def edit_movie_callback_wrapper(
        old_movie: config.MovieKeyTypedDict) -> Callable:
    """ Crete the edit movie callback