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

Melhora ordem dos itens do menu #408

Merged
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
2 changes: 1 addition & 1 deletion article/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ArticleModelAdmin(ModelAdmin):
inspect_view_enabled = True
inspect_view_class = ArticleAdminInspectView
menu_icon = "doc-full"
menu_order = 200
menu_order = get_menu_order("article")
add_to_settings_menu = False
exclude_from_explorer = False

Expand Down
4 changes: 2 additions & 2 deletions collection/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class ClassicWebsiteConfigurationModelAdmin(ModelAdmin):
class CollectionModelAdminGroup(ModelAdminGroup):
menu_label = _("Collections")
menu_icon = "folder-open-inverse"
# menu_order = get_menu_order("collection")
menu_order = 100
menu_order = get_menu_order("collection")
# menu_order = 100
items = (
CollectionModelAdmin,
WebSiteConfigurationModelAdmin,
Expand Down
35 changes: 24 additions & 11 deletions config/menu.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
WAGTAIL_MENU_APPS_ORDER = {
"collection": 400,
"journal": 500,
"issue": 510,
"article": 520,
"upload": 700,
"migration": 710,
"location": 800,
"institution": 810,
}

WAGTAIL_MENU_APPS_ORDER = [
"Tarefas",
"unexpected-error",
"processing",
"migration",
"journal",
"issue",
"article",
"institution",
"location",
"researcher",
"collection",
"pid_provider",
"Configurações",
"Relatórios",
"Images",
"Documentos",
"Ajuda",
]

def get_menu_order(app_name):
return WAGTAIL_MENU_APPS_ORDER.get(app_name) or 100
try:
return WAGTAIL_MENU_APPS_ORDER.index(app_name) + 1
except:
return 9000

15 changes: 14 additions & 1 deletion core/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collection.models import Collection
from article.models import Article
from wagtail.admin.navigation import get_site_for_user

from config.menu import get_menu_order, WAGTAIL_MENU_APPS_ORDER

# @hooks.register("insert_global_admin_css", order=100)
# def global_admin_css():
Expand Down Expand Up @@ -77,3 +77,16 @@ def add_items_summary_items(request, items):
items.append(CollectionSummaryItem(request))
items.append(JournalSummaryItem(request))
items.append(ArticleSummaryItem(request))


@hooks.register('construct_main_menu')
def reorder_menu_items(request, menu_items):
for item in menu_items:
if item.label in WAGTAIL_MENU_APPS_ORDER:
item.order = get_menu_order(item.label)


@hooks.register('construct_main_menu')
def remove_menu_items(request, menu_items):
if not request.user.is_superuser:
menu_items[:] = [item for item in menu_items if item.name not in ['documents', 'explorer', 'reports']]
4 changes: 1 addition & 3 deletions issue/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class IssueAdmin(ModelAdmin):
menu_label = _("Issues")
create_view_class = IssueCreateView
menu_icon = "folder"
# menu_order = get_menu_order("issue")
menu_order = 300
menu_order = get_menu_order("issue")
add_to_settings_menu = False
exclude_from_explorer = False

Expand Down Expand Up @@ -63,7 +62,6 @@ class IssueModelAdminGroup(ModelAdminGroup):
IssueAdmin,
# IssueProcAdmin,
)
menu_order = get_menu_order("journal")


# modeladmin_register(IssueModelAdminGroup)
Expand Down
4 changes: 1 addition & 3 deletions journal/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ class JournalAdmin(ModelAdmin):
class JournalModelAdminGroup(ModelAdminGroup):
menu_icon = "folder"
menu_label = _("Journals")
# menu_order = get_menu_order("journal")
menu_order = 200
menu_order = get_menu_order("journal")
items = (
OfficialJournalAdmin,
JournalAdmin,
# JournalProcAdmin,
)
menu_order = get_menu_order("journal")


modeladmin_register(JournalModelAdminGroup)
1 change: 0 additions & 1 deletion migration/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ class MigrationModelAdmin(ModelAdminGroup):
MigratedArticleModelAdmin,
MigratedFileModelAdmin,
)
menu_order = get_menu_order("migration")


modeladmin_register(MigrationModelAdmin)
Expand Down
3 changes: 2 additions & 1 deletion pid_provider/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
from wagtail.contrib.modeladmin.views import CreateView

from config.menu import get_menu_order
from .models import (
PidProviderConfig,
CollectionPidRequest,
Expand Down Expand Up @@ -175,7 +176,7 @@ class PidProviderConfigAdmin(ModelAdmin):
class PidProviderAdminGroup(ModelAdminGroup):
menu_label = _("Pid Provider")
menu_icon = "folder-open-inverse" # change as required
menu_order = 6
menu_order = get_menu_order("pid_provider")
items = (
PidProviderConfigAdmin,
PidProviderXMLAdmin,
Expand Down
3 changes: 1 addition & 2 deletions proc/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ class ArticleProcModelAdmin(ModelAdmin):
class ProcessModelAdminGroup(ModelAdminGroup):
menu_label = _("Processing")
menu_icon = "folder-open-inverse"
# menu_order = get_menu_order("article")
menu_order = 400
menu_order = get_menu_order("processing")
items = (
JournalProcModelAdmin,
IssueProcModelAdmin,
Expand Down
4 changes: 2 additions & 2 deletions researcher/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from wagtail.contrib.modeladmin.views import CreateView

from .models import Researcher

from config.menu import get_menu_order

class ResearcherCreateView(CreateView):
def form_valid(self, form):
Expand All @@ -17,7 +17,7 @@ class ResearcherAdmin(ModelAdmin):
create_view_class = ResearcherCreateView
menu_label = _("Researcher")
menu_icon = "folder"
menu_order = 200
menu_order = get_menu_order("researcher")
add_to_settings_menu = False
exclude_from_explorer = False

Expand Down