Skip to content

Commit 0948b96

Browse files
committed
Remove the not needed code to define Menu sidebar which is default
1 parent da743c2 commit 0948b96

File tree

6 files changed

+2
-885
lines changed

6 files changed

+2
-885
lines changed
Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
from collections import OrderedDict
21
from typing import TYPE_CHECKING, Any
32

4-
from django.conf import settings
53
from django.contrib import messages
64
from django.contrib.admin.models import LogEntry
75
from django.contrib.messages import add_message
86
from django.core.cache import cache as dj_cache, caches
9-
from django.http import HttpResponseRedirect
107
from django.shortcuts import render
11-
from django.template.response import TemplateResponse
128
from django.urls import path
13-
from django.utils.decorators import method_decorator
14-
from django.views.decorators.cache import never_cache
159
from unfold.sites import UnfoldAdminSite
1610

1711
from hope.apps.administration.forms import ClearCacheForm
18-
from hope.apps.administration.section_utils import SmartList, as_bool
1912

2013
if TYPE_CHECKING:
2114
from django.http import HttpRequest, HttpResponse
@@ -72,7 +65,6 @@ class HopeAdminSite(UnfoldAdminSite):
7265
site_title = "HOPE"
7366
site_header = "HOPE Administration"
7467
index_title = "Index"
75-
smart_index_template = "admin/smart_index.html"
7668

7769
def get_urls(self) -> list:
7870
from hope.apps.administration.panels import (
@@ -88,7 +80,6 @@ def get_urls(self) -> list:
8880
urls = super().get_urls()
8981
custom_urls = [
9082
path("clear-cache/", self.admin_view(clear_cache_view), name="clear_cache"),
91-
path("smart/<str:on_off>/", self.admin_view(self.smart_toggle), name="smart_toggle"),
9283
path(
9384
"panel/migrations/", self.admin_view(lambda req: panel_migrations(self, req)), name="panel_migrations"
9485
),
@@ -107,77 +98,9 @@ def get_urls(self) -> list:
10798
]
10899
return custom_urls + urls
109100

110-
def each_context(self, request: "HttpRequest") -> dict[str, Any]:
111-
context = super().each_context(request)
112-
context["smart"] = self.is_smart_enabled(request)
113-
return context
114-
115-
def is_smart_enabled(self, request: "HttpRequest") -> bool:
116-
return as_bool(request.COOKIES.get("smart", "0"))
117-
118-
def smart_toggle(self, request: "HttpRequest", on_off: str) -> HttpResponseRedirect:
119-
destination = request.GET.get("from", request.path)
120-
response = HttpResponseRedirect(destination)
121-
response.set_cookie("smart", str(int(as_bool(on_off))))
122-
return response
123-
124-
@method_decorator(never_cache)
125-
def index(self, request: "HttpRequest", extra_context: dict[str, Any] | None = None) -> "HttpResponse":
126-
extra_context = {"show_changelinks": True, **(extra_context or {})}
127-
if self.is_smart_enabled(request):
128-
context = {
129-
**self.each_context(request),
130-
"groups": dict(self._get_menu(request)),
131-
"recent_actions": LogEntry.objects.select_related("content_type", "user").order_by("-action_time")[:10],
132-
**extra_context,
133-
}
134-
request.current_app = self.name
135-
return TemplateResponse(request, self.smart_index_template, context)
136-
return super().index(request, extra_context)
137-
138101
def get_app_list(self, request: "HttpRequest", app_label: str | None = None) -> list[dict[str, Any]]:
139102
app_list = super().get_app_list(request, app_label)
140103
for app in app_list:
141104
if isinstance(app.get("name"), str):
142105
app["name"] = app["name"].upper()
143106
return app_list
144-
145-
def _get_menu(self, request: "HttpRequest") -> "OrderedDict[str, list[dict[str, Any]]]":
146-
sections_source = getattr(settings, "HOPE_ADMIN_SECTIONS", {})
147-
sections: dict[str, SmartList] = {"_hidden_": SmartList()}
148-
for name, entries in sections_source.items():
149-
sections[name] = SmartList(entries)
150-
if "Other" not in sections:
151-
sections["Other"] = SmartList()
152-
153-
groups: OrderedDict[str, list[dict[str, Any]]] = OrderedDict((k, []) for k in sections)
154-
app_list = self.get_app_list(request)
155-
156-
def get_section(model_info: dict[str, Any], app: dict[str, Any]) -> str:
157-
fqn = f"{app['app_label']}.{model_info['object_name']}"
158-
if fqn in sections["_hidden_"] or app["app_label"] in sections["_hidden_"]:
159-
return "_hidden_"
160-
for sec_name, sec_entries in sections.items():
161-
if fqn in sec_entries or app["app_label"] in sec_entries:
162-
return sec_name
163-
return "Other"
164-
165-
for app in app_list:
166-
for model_info in app["models"]:
167-
section_name = get_section(model_info, app)
168-
groups[section_name].append(
169-
{
170-
"app_label": str(app["app_label"]),
171-
"app_name": str(app["name"]),
172-
"app_url": app["app_url"],
173-
"label": f"{app['name']} - {model_info['name']}",
174-
"model_name": str(model_info["name"]),
175-
"admin_url": model_info["admin_url"],
176-
"perms": model_info["perms"],
177-
}
178-
)
179-
180-
for items in groups.values():
181-
items.sort(key=lambda x: x["label"])
182-
183-
return groups

src/hope/apps/administration/templates/admin/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends "admin/base.html" %}
2-
{% load hope_admin i18n unfold %}
2+
{% load i18n unfold %}
33

44
{% block extrahead %}
55
{{ form.media }}

src/hope/apps/administration/templates/unfold/helpers/userlinks.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
{% load hope_admin i18n static unfold %}
1+
{% load i18n static unfold %}
22

33
<div class="flex flex-row gap-4 items-center ml-auto text-sm">
44
{% if environment %}
55
{% include "unfold/helpers/label.html" with text=environment.0 type=environment.1 %}
66
{% endif %}
77

8-
<span class="hope-smart-toggler">{% smart_toggler %}</span>
98

109
{% if site_url %}
1110
<a href="{{ site_url }}" class="text-font-important-light dark:text-font-important-dark hover:underline">
Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
1-
import urllib.parse
2-
31
from django import template
4-
from django.urls import reverse
5-
from django.utils.safestring import mark_safe
6-
from django.utils.translation import gettext as _
7-
8-
from hope.apps.administration.section_utils import as_bool
92

103
register = template.Library()
11-
12-
13-
@register.simple_tag(takes_context=True)
14-
def smart_toggler(context: template.Context) -> str:
15-
"""Render the Smart Index / Standard Index toggle link.
16-
17-
Ported from ``smart_admin.templatetags.smart.smart_toggler`` so the
18-
feature survives the ``django-unfold`` migration.
19-
"""
20-
request = context["request"]
21-
page = urllib.parse.quote(request.path)
22-
if as_bool(request.COOKIES.get("smart", "0")):
23-
label = _("Standard Index")
24-
flag = "0"
25-
else:
26-
label = _("Smart Index")
27-
flag = "1"
28-
29-
toggler = reverse("admin:smart_toggle", args=[flag])
30-
return mark_safe( # noqa: S308
31-
f'<a href="{toggler}?from={page}" class="text-font-important-light '
32-
f'dark:text-font-important-dark hover:underline">{label}</a>'
33-
)

0 commit comments

Comments
 (0)