Migrar ModelAdmin para Snippets nos wagtail_hooks.py#1354
Migrar ModelAdmin para Snippets nos wagtail_hooks.py#1354robertatakenaka merged 4 commits intomainfrom
Conversation
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>
There was a problem hiding this comment.
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/ModelAdminGroupporSnippetViewSet/SnippetViewSetGroupe troca decreate_view_class→add_view_class. - Troca de
modeladmin_register(...)porregister_snippet(...)(incluindo grupos) e uso de@register_snippetem 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.
| 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 |
There was a problem hiding this comment.
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".
| link_download.short_descriptions = 'Download' | ||
| link_download.allow_tags = True | ||
|
|
||
| modeladmin_register(ReportCSVAdmin) | ||
| link_download.allow_tags = True |
There was a problem hiding this comment.
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.
O que esse PR faz?
Migra todas as implementações de
wagtail_modeladminparawagtail.snippetsnativos em 13 arquivoswagtail_hooks.py, consolidando 30+ classes admin.Padrão de migração:
Arquivos migrados:
Funcionalidades preservadas:
Onde a revisão poderia começar?
Comece por
book/wagtail_hooks.pyoucollection/wagtail_hooks.py- exemplos típicos com grupo e funcionalidade de export.Para casos com custom views:
location/wagtail_hooks.py,researcher/wagtail_hooks.pyPara grupos complexos:
core/wagtail_hooks.py(ListCodesAdminGroup),journal/wagtail_hooks.pyComo este poderia ser testado manualmente?
python manage.py checkpara validar configuraçãoAlgum cenário de contexto que queira dar?
O pacote
wagtail-modeladminestá 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_class→add_view_classexclude_from_explorerremovido (não aplicável a Snippets)inspect_view_fields_excluderemovido (usar panels ao invés)Não migrados (fora do escopo):
wagtail_modeladmin.helpersScreenshots
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
editorialboard/wagtail_hooks.pyjá existenteOriginal prompt
💡 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.