Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adiciona filtro por coleções na interface de listagem de artigos #875

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions article/migrations/0014_merge_20241008_1716.py

This file was deleted.

18 changes: 17 additions & 1 deletion article/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any
from django.core.exceptions import PermissionDenied
from django.db.models import Count
from django.db.models.query import QuerySet
from django.http import HttpResponseRedirect
from django.utils.translation import gettext as _
from wagtail_modeladmin.options import (
Expand All @@ -10,6 +12,7 @@
from wagtail_modeladmin.views import CreateView
from wagtail.snippets.views.snippets import SnippetViewSet
from wagtail.snippets.models import register_snippet
from django.contrib.admin import SimpleListFilter

from article.models import ( # AbstractModel,; Category,; Title,
Article,
Expand All @@ -19,6 +22,19 @@
from config.menu import get_menu_order


class CollectionFilter(SimpleListFilter):
title = _("Collection")
parameter_name = "collection"

def lookups(self, request, model_admin):
articles = Article.objects.all()
return [(collection.id, collection.main_name) for article in articles for collection in article.collections if collection.is_active]

def queryset(self, request, queryset):
if self.value():
return queryset.filter(journal__scielojournal__collection__id=self.value())


class ArticleCreateView(CreateView):
def form_valid(self, form):
self.object = form.save_all(self.request.user)
Expand All @@ -44,7 +60,7 @@ class ArticleAdmin(ModelAdmin):
"created",
"updated",
)
list_filter = ("valid",)
list_filter = ("valid", CollectionFilter)
search_fields = (
"titles__plain_text",
"pid_v2",
Expand Down
Loading