View Single Post
Old 07-25-2021, 04:24 PM   #1122
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,160
Karma: 77304081
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I think I found the relevant section in action.py. Lines 569-622:

Code:
    def remove_books_from_list(self, list_name, book_id_list, refresh_screen=True, display_warnings=True):
        '''
        This method is designed to be called from other plugins
        list_name - must be a valid list name
        book_id_list - should be a list of calibre book ids to be removed
        refresh_screen - indicates whether to refresh the book details displayed in library view
        display_warnings - option to suppress any error/warning dialogs if books already on list
        Returns a tuple of (removed_lids_ist, any_tags_changed)
        '''
        if list_name is None:
            if display_warnings:
                return error_dialog(self.gui, _('Cannot remove from list'),
                                    _('No list name specified'), show=True)
            return None, False

        if refresh_screen:
            previous = self.gui.library_view.currentIndex()
        db = self.gui.current_db

        with self.sync_lock:
            book_ids = cfg.get_book_list(db, list_name)
            id_map = OrderedDict([(book_id, True) for book_id in book_ids])
            removed_ids = []
            for calibre_id in book_id_list:
                if calibre_id in id_map:
                    removed_ids.append(calibre_id)
                    book_ids.remove(calibre_id)

            if not removed_ids:
                if display_warnings:
                    confirm(_('The selected book(s) do not exist on this list'),
                                'reading_list_not_on_list', self.gui)
                return None, False
            cfg.set_book_list(db, list_name, book_ids)

            # Remove tags from the books if necessary
            any_tags_changed = self.apply_tags_to_list(list_name, removed_ids, add=False)
            changed_series_id_list = self.update_series_custom_column(list_name, book_ids)

            if refresh_screen:
                message = _('Removed %d books from your %s list') % (len(removed_ids), list_name)
                self.gui.status_bar.showMessage(message)
                if any_tags_changed:
                    self.gui.tags_view.recount()
                if unicode(self.gui.search.text()).startswith('marked:reading_list_'):
                    self.view_list(list_name)
                else:
                    refresh_book_ids = set(changed_series_id_list).union(set(removed_ids))
                    self.gui.library_view.model().refresh_ids(refresh_book_ids)
                    current = self.gui.library_view.currentIndex()
                    self.gui.library_view.model().current_changed(current, previous)
                return None, False
            else:
                return (removed_ids, any_tags_changed)
And 949 - 987

Code:
    def update_series_custom_column(self, list_name, book_ids):
        changed_series_book_ids = []
        db = self.gui.current_db
        list_map = cfg.get_list_info(db, list_name)
        series_column = list_map.get(cfg.KEY_SERIES_COLUMN, cfg.DEFAULT_LIST_VALUES[cfg.KEY_SERIES_COLUMN])
        if not series_column:
            return changed_series_book_ids

        series_name = list_map.get(cfg.KEY_SERIES_NAME, cfg.DEFAULT_LIST_VALUES[cfg.KEY_SERIES_NAME])
        if not series_name:
            series_name = list_name

        custom_columns = db.field_metadata.custom_field_metadata()
        col = custom_columns.get(series_column, None)
        if col is None:
            return
        label = db.field_metadata.key_to_label(series_column)

        # Find all the books currently with this series name:
        query = '#%s:"%s"' % (label, series_name)
        existing_series_book_ids = db.data.search_getting_ids(query, search_restriction='', use_virtual_library=False)

        # Go through all the books on our list and assign the series name/index
        for idx, book_id in enumerate(book_ids):
            series_idx = idx + 1
            existing_series_name = db.get_custom(book_id, label=label, index_is_id=True)
            existing_series_idx = db.get_custom_extra(book_id, label=label, index_is_id=True)
            if series_name != existing_series_name or series_idx != existing_series_idx:
                db.set_custom(book_id, series_name, label=label, commit=False, extra=series_idx)
                changed_series_book_ids.append(book_id)
            if book_id in existing_series_book_ids:
                existing_series_book_ids.remove(book_id)

        # Any books left on the existing series list are no longer on our reading list
        for book_id in existing_series_book_ids:
            db.set_custom(book_id, '', label=label, commit=False, extra=None)
            changed_series_book_ids.append(book_id)
        db.commit()
        return changed_series_book_ids

Last edited by ownedbycats; 07-26-2021 at 01:07 AM.
ownedbycats is offline   Reply With Quote