Skip to content

Migrar ModelAdmin para Snippets nos wagtail_hooks.py#1354

Merged
robertatakenaka merged 4 commits intomainfrom
copilot/replace-modeladmin-with-snippets
Feb 19, 2026
Merged

Migrar ModelAdmin para Snippets nos wagtail_hooks.py#1354
robertatakenaka merged 4 commits intomainfrom
copilot/replace-modeladmin-with-snippets

Conversation

Copy link
Contributor

Copilot AI commented Feb 19, 2026

O que esse PR faz?

Migra todas as implementações de wagtail_modeladmin para wagtail.snippets nativos em 13 arquivos wagtail_hooks.py, consolidando 30+ classes admin.

Padrão de migração:

# Antes
from wagtail_modeladmin.options import ModelAdmin, modeladmin_register

class BookAdmin(ModelAdmin):
    create_view_class = BookCreateView
    exclude_from_explorer = False

modeladmin_register(BookAdmin)

# Depois
from wagtail.snippets.models import register_snippet
from wagtail.snippets.views.snippets import SnippetViewSet

@register_snippet
class BookAdmin(SnippetViewSet):
    add_view_class = BookCreateView

Arquivos migrados:

  • altmetric, book, collection, core, editorialboard, files_storage
  • journal (7 classes), location (5 classes), report
  • researcher (4 classes), thematic_areas (4 classes), tracker, vocabulary

Funcionalidades preservadas:

  • Todas as configurações de list_display, search_fields, list_filter
  • Export (list_export, export_filename)
  • Custom CreateView com save_all()
  • Button helpers e menu ordering

Onde a revisão poderia começar?

Comece por book/wagtail_hooks.py ou collection/wagtail_hooks.py - exemplos típicos com grupo e funcionalidade de export.

Para casos com custom views: location/wagtail_hooks.py, researcher/wagtail_hooks.py

Para grupos complexos: core/wagtail_hooks.py (ListCodesAdminGroup), journal/wagtail_hooks.py

Como este poderia ser testado manualmente?

  1. Executar python manage.py check para validar configuração
  2. Acessar admin Wagtail e verificar menus em:
    • Books, Collection, Location, Researchers
    • "List of codes" group no menu principal
  3. Testar criação/edição de registros nas views migradas
  4. Verificar export CSV (Collection, Location)
  5. Validar inspect views (Collection, Tracker, Researcher)

Algum cenário de contexto que queira dar?

O pacote wagtail-modeladmin está deprecated. Snippets é a API nativa do Wagtail para gerenciar modelos não-páginas desde a versão 2.x, com melhor integração e performance.

Mudanças chave:

  • create_view_classadd_view_class
  • exclude_from_explorer removido (não aplicável a Snippets)
  • inspect_view_fields_exclude removido (usar panels ao invés)

Não migrados (fora do escopo):

  • Button helpers ainda importam de wagtail_modeladmin.helpers
  • Outros módulos (institution, django_celery_beat) mantidos como estão

Screenshots

N/A - Mudanças backend sem alteração visual da interface.

Quais são tickets relevantes?

Issue com subtarefas listando os 13 arquivos a migrar.

Referências

Original prompt

This section details on the original issue you should resolve

<issue_title>Troque ModelAdmin por Snippets</issue_title>
<issue_description>### Descrição da tarefa
Troque ModelAdmin por Snippets

Subtarefas

  • altmetric/wagtail_hooks.py
  • book/wagtail_hooks.py
  • collection/wagtail_hooks.py
  • core/wagtail_hooks.py
  • editorialboard/wagtail_hooks.py
  • files_storage/wagtail_hooks.py
  • journal/wagtail_hooks.py
  • location/wagtail_hooks.py
  • report/wagtail_hooks.py
  • researcher/wagtail_hooks.py
  • thematic_areas/wagtail_hooks.py
  • tracker/wagtail_hooks.py
  • vocabulary/wagtail_hooks.py

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 19, 2026 11:30
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
…iew with Snippets CreateView

Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace ModelAdmin with Snippets in various wagtail_hooks Migrar ModelAdmin para Snippets nos wagtail_hooks.py Feb 19, 2026
@robertatakenaka robertatakenaka marked this pull request as ready for review February 19, 2026 12:37
Copilot AI review requested due to automatic review settings February 19, 2026 12:37
@robertatakenaka robertatakenaka merged commit f3184a3 into main Feb 19, 2026
7 of 9 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Este PR migra os registros administrativos baseados em wagtail_modeladmin para a API nativa de Snippets do Wagtail (SnippetViewSet / SnippetViewSetGroup) em múltiplos wagtail_hooks.py, reduzindo dependência do pacote deprecated e alinhando o admin com a integração nativa do Wagtail.

Changes:

  • Substituição de ModelAdmin/ModelAdminGroup por SnippetViewSet/SnippetViewSetGroup e troca de create_view_classadd_view_class.
  • Troca de modeladmin_register(...) por register_snippet(...) (incluindo grupos) e uso de @register_snippet em alguns ViewSets.
  • Ajustes para manter recursos de inspect, filtros, busca, export e custom CreateView com save_all().

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
altmetric/wagtail_hooks.py Migra admin de Altmetric para SnippetViewSet e registro via Snippets.
book/wagtail_hooks.py Migra admin/grupo de Books para SnippetViewSetGroup + register_snippet.
collection/wagtail_hooks.py Migra Collection admin para SnippetViewSet com CreateView custom e registro via Snippets.
core/wagtail_hooks.py Migra “List of codes” de ModelAdminGroup para SnippetViewSetGroup registrado como snippet group.
editorialboard/wagtail_hooks.py Ajusta imports para usar CreateView/Snippet ViewSets nativos e mantém group via Snippets.
files_storage/wagtail_hooks.py Migra MinioConfiguration admin para SnippetViewSet e registro via decorator Snippets.
journal/wagtail_hooks.py Converte classes de controlled lists para SnippetViewSet (consumidas pelo group em core).
location/wagtail_hooks.py Migra Location admin/group para Snippet ViewSets e mantém URLs custom registradas via hooks.
report/wagtail_hooks.py Migra ReportCSV admin para SnippetViewSet registrado via Snippets.
researcher/wagtail_hooks.py Migra grupo/administradores de Researcher para Snippet ViewSets + group registrado via Snippets.
thematic_areas/wagtail_hooks.py Migra classes para Snippet ViewSets e atualiza imports (grupos continuam comentados como antes).
tracker/wagtail_hooks.py Migra group de tracker para SnippetViewSetGroup e registro via Snippets.
vocabulary/wagtail_hooks.py Migra group de vocabulary para SnippetViewSetGroup e registro via Snippets.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 34 to 37
def link_download(self, obj):
if obj.file and obj.file.url:
return f"<a target='_blank' href={obj.file.url}>Download</a>"
return None
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

link_download is building an HTML anchor via f-string with an unquoted href value, and it does not escape obj.file.url. In Wagtail snippet listings this is likely to be auto-escaped (breaking the link) or, if marked safe elsewhere, could become an XSS vector. Prefer returning a safely-escaped HTML string (e.g., via Django’s format_html) and ensure the href attribute is properly quoted; also consider adding rel="noopener noreferrer" when using target="_blank".

Copilot uses AI. Check for mistakes.
Comment on lines 39 to 40
link_download.short_descriptions = 'Download'
link_download.allow_tags = True

modeladmin_register(ReportCSVAdmin)
link_download.allow_tags = True
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

link_download.short_descriptions looks like a typo (Django/Wagtail conventions use short_description). Also, allow_tags is a legacy Django admin flag and is not expected to be respected by Wagtail’s snippet listing, so it may be dead code. Please update the attribute name and use safe HTML rendering instead of relying on allow_tags.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Troque ModelAdmin por Snippets

2 participants

Comments