Skip to content

feat: bulk admin actions for Media.skip - #1570

Merged
tcely merged 4 commits into
meeb:mainfrom
Agi-Asi:feat/admin-bulk-actions
Aug 27, 2026
Merged

feat: bulk admin actions for Media.skip#1570
tcely merged 4 commits into
meeb:mainfrom
Agi-Asi:feat/admin-bulk-actions

Conversation

@Agi-Asi

@Agi-Asi Agi-Asi commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Problem

Managing a large library through the Django admin requires editing every media item individually to toggle Skip or Can download — the exact pain point in #493, where bulk-editing those two flags was requested ("A real time saver would be to expose actions such as enabling/disabling Skip or Can download").

Change

Adds the standard Django admin bulk actions to MediaAdmin, scoped to exactly the two fields requested:

  • Set / unset "skip" — also sets manual_skip to match, so a bulk un-skip isn't immediately re-skipped by the filtering logic, and a bulk skip is recorded as the operator's explicit decision.
  • Set / unset "can download".

Also adds list_filter for can_download / skip / downloaded, so the rows to bulk-edit can be narrowed down first (without a filter the actions are much less useful on big libraries).

Implementation uses queryset.update(), so a bulk action across thousands of rows is a single UPDATE statement rather than thousands of model saves.

Testing

  • New sync/tests/test_admin.py covers both action pairs end-to-end against real model rows (including the manual_skip coupling) plus action registration.
  • Full Django suite: manage.py test — 54 tests, OK.
  • The CI ruff gate passes.

Fixes #493

Managing large libraries through the Django admin required editing
every media item individually to toggle 'skip' or 'can download'
(meeb#493). Add the standard admin bulk actions for exactly the two
fields requested there:

- Set / unset 'skip' — also sets manual_skip to match, so a bulk
  un-skip is not immediately re-skipped by the filtering logic, and a
  bulk skip is treated as the operator's explicit decision
- Set / unset 'can download'

Also adds list_filter for can_download/skip/downloaded so the items
to bulk-edit can actually be narrowed down first.

Uses queryset.update() so a bulk action on thousands of rows is a
single UPDATE, not thousands of model saves.

Tests cover both action pairs and the action registration.

Fixes meeb#493
@tcely tcely moved this to Todo in Status Aug 27, 2026
@tcely
tcely requested a review from meeb August 27, 2026 10:16

@meeb meeb left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine with to me. @tcely is toggling flags sufficient to eventually trigger the required worker events?

@tcely

tcely commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Is toggling flags sufficient to eventually trigger the required worker events?

I don't understand the question.

@meeb

meeb commented Aug 27, 2026

Copy link
Copy Markdown
Owner

As in, is just setting can_download to True sufficient to trigger a task at a later date, or does this need to have .save() called on each object as well to re-evaluate the state of the media item.

@tcely

tcely commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

The media_post_save signal is the only place the can_download attribute is recalculated.

That is eventually triggered for every Media instance per source: A) after editing a source or B) after indexing a source.

Is this sufficient, or do you believe a save_media task needs to be added to the tasks queue?

@Agi-Asi

Agi-Asi commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Good question re: signals — since queryset.update() deliberately bypasses save()/media_post_save, the flags flip immediately but re-evaluation waits for the next source edit/index pass, as @tcely described. That felt acceptable for an admin bulk tool (it mirrors what the DB-level toggle means), but if you'd prefer eager re-evaluation I'm happy to switch the actions to iterate queryset and call save() per object (or enqueue a save_media task per item) — just tell me which shape you want.

@meeb

meeb commented Aug 27, 2026

Copy link
Copy Markdown
Owner

I'm fine with it waiting for an Indexing to trigger any events, just checking.

@tcely tcely left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement a save_media task per changed item and add a setting that enables queuing those tasks. By default, the tasks should not be queued.

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Status Aug 27, 2026
Adds SAVE_MEDIA_AFTER_BULK_ACTION (env:
TUBESYNC_SAVE_MEDIA_AFTER_BULK_ACTION, default False). When enabled,
each admin bulk action queues a save_media task per changed item so
flags are re-evaluated without waiting for the next source edit or
indexing run. When disabled (the default) behaviour is unchanged:
re-evaluation happens on the next source edit/index pass.

Requested by tcely in review.
@Agi-Asi

Agi-Asi commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Done in be4313b — implemented exactly as requested:

  • New setting SAVE_MEDIA_AFTER_BULK_ACTION (container env: TUBESYNC_SAVE_MEDIA_AFTER_BULK_ACTION), default False so nothing is queued unless explicitly enabled.
  • When enabled, each bulk action queues a save_media task per changed item (via save_media.map() over the queryset UUIDs), so flags are re-evaluated without waiting for the next source edit/index pass.
  • Documented in the README env-var table and local_settings.py.container.
  • Two new tests: default = save_media.map not called; enabled via override_settings = called once with exactly the changed UUIDs. All 5 admin tests pass locally, ruff gate clean.

Comment thread tubesync/sync/admin.py Outdated
Comment thread README.md Outdated
@tcely
tcely force-pushed the feat/admin-bulk-actions branch 2 times, most recently from 4059c19 to 2dd4b88 Compare August 27, 2026 15:49
Comment thread tubesync/sync/admin.py Outdated
@github-project-automation github-project-automation Bot moved this from In Progress to Ready in Status Aug 27, 2026
@tcely
tcely requested a review from meeb August 27, 2026 16:10
@tcely tcely changed the title Add bulk admin actions for skip and can_download on Media feat: bulk admin actions for `Mediaskip and can_download on Media Aug 27, 2026
@tcely tcely changed the title feat: bulk admin actions for `Mediaskip and can_download on Media feat: bulk admin actions for Media.skip Aug 27, 2026
@tcely
tcely merged commit 5deac47 into meeb:main Aug 27, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in Status Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

FEATURE REQUEST: Bulk editing in the Django admin control panel

3 participants