django-lineup 0.3.2__tar.gz → 0.3.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django-lineup-0.3.2 → django-lineup-0.3.4}/HISTORY.rst +11 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/PKG-INFO +15 -1
- {django-lineup-0.3.2 → django-lineup-0.3.4}/README.rst +3 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/django_lineup.egg-info/PKG-INFO +15 -1
- {django-lineup-0.3.2 → django-lineup-0.3.4}/django_lineup.egg-info/SOURCES.txt +1 -0
- django-lineup-0.3.4/lineup/__init__.py +1 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/admin.py +3 -0
- django-lineup-0.3.4/lineup/forms.py +10 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/models.py +9 -1
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/templatetags/lineup_tags.py +34 -11
- {django-lineup-0.3.2 → django-lineup-0.3.4}/setup.cfg +1 -1
- django-lineup-0.3.2/lineup/__init__.py +0 -1
- {django-lineup-0.3.2 → django-lineup-0.3.4}/AUTHORS.rst +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/CONTRIBUTING.rst +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/LICENSE +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/MANIFEST.in +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/django_lineup.egg-info/dependency_links.txt +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/django_lineup.egg-info/not-zip-safe +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/django_lineup.egg-info/requires.txt +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/django_lineup.egg-info/top_level.txt +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/apps.py +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/exceptions.py +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/management/commands/import_menu_from_json.py +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/managers.py +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/migrations/0001_initial.py +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/migrations/0002_auto_20201213_0856.py +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/migrations/0003_menuitem_extras.py +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/migrations/__init__.py +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/static/css/lineup.css +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/static/js/lineup.js +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/templates/admin/lineup/menuitem/change_list.html +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/templates/lineup/base.html +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/templates/lineup/breadcrumbs.html +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/templates/lineup/menu.html +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/urls.py +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/views.py +0 -0
- {django-lineup-0.3.2 → django-lineup-0.3.4}/setup.py +0 -0
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
History
|
|
4
4
|
-------
|
|
5
5
|
|
|
6
|
+
0.3.4 (2024-06-18)
|
|
7
|
+
++++++++++++++++++
|
|
8
|
+
|
|
9
|
+
* Fix caching with multiple menus
|
|
10
|
+
|
|
11
|
+
0.3.3 (2024-06-18)
|
|
12
|
+
++++++++++++++++++
|
|
13
|
+
|
|
14
|
+
* Improve overall performance
|
|
15
|
+
* Add cache
|
|
16
|
+
|
|
6
17
|
0.3.2 (2024-05-30)
|
|
7
18
|
++++++++++++++++++
|
|
8
19
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: django-lineup
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Navigation system for django sites
|
|
5
5
|
Home-page: https://github.com/otto-torino/django-lineup
|
|
6
6
|
Author: abidibo
|
|
@@ -37,6 +37,9 @@ Django Lineup
|
|
|
37
37
|
.. image:: https://codecov.io/gh/otto-torino/django-lineup/branch/master/graph/badge.svg
|
|
38
38
|
:target: https://codecov.io/gh/otto-torino/django-lineup
|
|
39
39
|
|
|
40
|
+
.. image:: https://static.pepy.tech/badge/django-lineup
|
|
41
|
+
:target: https://pepy.tech/project/django-lineup
|
|
42
|
+
|
|
40
43
|
Multiple navigation system for django sites.
|
|
41
44
|
|
|
42
45
|
Django Lineup lets you manage a tree of items. Each first level node represents a menu you can include in your templates.
|
|
@@ -238,6 +241,17 @@ Tools used in rendering this package:
|
|
|
238
241
|
History
|
|
239
242
|
-------
|
|
240
243
|
|
|
244
|
+
0.3.4 (2024-06-18)
|
|
245
|
+
++++++++++++++++++
|
|
246
|
+
|
|
247
|
+
* Fix caching with multiple menus
|
|
248
|
+
|
|
249
|
+
0.3.3 (2024-06-18)
|
|
250
|
+
++++++++++++++++++
|
|
251
|
+
|
|
252
|
+
* Improve overall performance
|
|
253
|
+
* Add cache
|
|
254
|
+
|
|
241
255
|
0.3.2 (2024-05-30)
|
|
242
256
|
++++++++++++++++++
|
|
243
257
|
|
|
@@ -11,6 +11,9 @@ Django Lineup
|
|
|
11
11
|
.. image:: https://codecov.io/gh/otto-torino/django-lineup/branch/master/graph/badge.svg
|
|
12
12
|
:target: https://codecov.io/gh/otto-torino/django-lineup
|
|
13
13
|
|
|
14
|
+
.. image:: https://static.pepy.tech/badge/django-lineup
|
|
15
|
+
:target: https://pepy.tech/project/django-lineup
|
|
16
|
+
|
|
14
17
|
Multiple navigation system for django sites.
|
|
15
18
|
|
|
16
19
|
Django Lineup lets you manage a tree of items. Each first level node represents a menu you can include in your templates.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: django-lineup
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Navigation system for django sites
|
|
5
5
|
Home-page: https://github.com/otto-torino/django-lineup
|
|
6
6
|
Author: abidibo
|
|
@@ -37,6 +37,9 @@ Django Lineup
|
|
|
37
37
|
.. image:: https://codecov.io/gh/otto-torino/django-lineup/branch/master/graph/badge.svg
|
|
38
38
|
:target: https://codecov.io/gh/otto-torino/django-lineup
|
|
39
39
|
|
|
40
|
+
.. image:: https://static.pepy.tech/badge/django-lineup
|
|
41
|
+
:target: https://pepy.tech/project/django-lineup
|
|
42
|
+
|
|
40
43
|
Multiple navigation system for django sites.
|
|
41
44
|
|
|
42
45
|
Django Lineup lets you manage a tree of items. Each first level node represents a menu you can include in your templates.
|
|
@@ -238,6 +241,17 @@ Tools used in rendering this package:
|
|
|
238
241
|
History
|
|
239
242
|
-------
|
|
240
243
|
|
|
244
|
+
0.3.4 (2024-06-18)
|
|
245
|
+
++++++++++++++++++
|
|
246
|
+
|
|
247
|
+
* Fix caching with multiple menus
|
|
248
|
+
|
|
249
|
+
0.3.3 (2024-06-18)
|
|
250
|
+
++++++++++++++++++
|
|
251
|
+
|
|
252
|
+
* Improve overall performance
|
|
253
|
+
* Add cache
|
|
254
|
+
|
|
241
255
|
0.3.2 (2024-05-30)
|
|
242
256
|
++++++++++++++++++
|
|
243
257
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.3.4'
|
|
@@ -7,6 +7,7 @@ from django.utils.translation import gettext_lazy as _
|
|
|
7
7
|
from mptt.admin import MPTTModelAdmin
|
|
8
8
|
|
|
9
9
|
from .models import MenuItem
|
|
10
|
+
from .forms import MenuItemForm
|
|
10
11
|
|
|
11
12
|
baton = 'baton' in sys.modules
|
|
12
13
|
|
|
@@ -19,6 +20,7 @@ class MenuItemInline(admin.StackedInline):
|
|
|
19
20
|
Tabular Inline View for MenuItem
|
|
20
21
|
'''
|
|
21
22
|
model = MenuItem
|
|
23
|
+
form = MenuItemForm
|
|
22
24
|
extra = 1
|
|
23
25
|
classes = ('collapse-entry', 'expand-first', )
|
|
24
26
|
prepopulated_fields = {'slug': ('label',)}
|
|
@@ -26,6 +28,7 @@ class MenuItemInline(admin.StackedInline):
|
|
|
26
28
|
|
|
27
29
|
@admin.register(MenuItem)
|
|
28
30
|
class MenuItemAdmin(MPTTModelAdmin):
|
|
31
|
+
form = MenuItemForm
|
|
29
32
|
change_list_template = "admin/lineup/menuitem/change_list.html"
|
|
30
33
|
list_display = ('slug', 'label', 'parent', 'link', 'order', 'login_required', 'enabled', )
|
|
31
34
|
list_filter = (('parent', RelatedDropdownFilter, ) if baton else 'parent', 'enabled', 'login_required', )
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from django import forms
|
|
2
|
+
|
|
3
|
+
class MenuItemForm(forms.ModelForm):
|
|
4
|
+
def __init__(self, *args, **kwargs):
|
|
5
|
+
super().__init__(*args, **kwargs)
|
|
6
|
+
permissions = self.fields.get("permissions")
|
|
7
|
+
if permissions:
|
|
8
|
+
permissions.queryset = permissions.queryset.select_related(
|
|
9
|
+
"content_type"
|
|
10
|
+
)
|
|
@@ -8,6 +8,9 @@ from django.db import models
|
|
|
8
8
|
from django.utils.translation import gettext_lazy as _
|
|
9
9
|
from django.utils.safestring import mark_safe
|
|
10
10
|
from django.db import transaction
|
|
11
|
+
from django.db.models.signals import post_delete, post_save
|
|
12
|
+
from django.dispatch import receiver
|
|
13
|
+
from django.core.cache import cache
|
|
11
14
|
|
|
12
15
|
from mptt.models import MPTTModel, TreeForeignKey
|
|
13
16
|
|
|
@@ -118,7 +121,7 @@ class MenuItem(MPTTModel):
|
|
|
118
121
|
|
|
119
122
|
return item
|
|
120
123
|
|
|
121
|
-
def is_active(self, path):
|
|
124
|
+
def is_active(self, path, prefix=""):
|
|
122
125
|
return self.link and self.link == path
|
|
123
126
|
|
|
124
127
|
def extras_dict(self):
|
|
@@ -129,3 +132,8 @@ class MenuItem(MPTTModel):
|
|
|
129
132
|
)
|
|
130
133
|
except Exception:
|
|
131
134
|
return {}
|
|
135
|
+
|
|
136
|
+
@receiver(post_save, sender=MenuItem)
|
|
137
|
+
@receiver(post_delete, sender=MenuItem)
|
|
138
|
+
def clear_lineup_cache(sender , **kwargs):
|
|
139
|
+
cache.delete("lineup")
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import logging
|
|
3
|
+
from django.core.cache import cache
|
|
3
4
|
|
|
4
5
|
from django import template
|
|
5
6
|
from django.contrib.auth.models import Permission
|
|
6
|
-
from django.db.models import Q
|
|
7
|
+
from django.db.models import Q, Count
|
|
8
|
+
from django.urls import LocalePrefixPattern
|
|
7
9
|
|
|
8
10
|
from ..models import MenuItem
|
|
9
11
|
|
|
@@ -24,13 +26,22 @@ def get_all_user_permissions_id_list(user):
|
|
|
24
26
|
return perms + group_perms
|
|
25
27
|
|
|
26
28
|
|
|
29
|
+
def remove_prefix(text, prefix): # TODO: introduce in python 3.9, so this can be removed
|
|
30
|
+
if text.startswith(prefix):
|
|
31
|
+
return text[len(prefix):]
|
|
32
|
+
return text
|
|
33
|
+
|
|
34
|
+
|
|
27
35
|
def set_active_voice(path, items):
|
|
28
36
|
"""
|
|
29
37
|
Sets the active property to the active voice, and with_active to
|
|
30
38
|
all its parents
|
|
31
39
|
"""
|
|
40
|
+
|
|
41
|
+
l = LocalePrefixPattern(prefix_default_language=True)
|
|
42
|
+
prefix = l.language_prefix
|
|
32
43
|
for item in items:
|
|
33
|
-
if item.get("instance").is_active(path):
|
|
44
|
+
if item.get("instance").is_active(remove_prefix(path, prefix)):
|
|
34
45
|
item["active"] = True
|
|
35
46
|
parent = item.get("parent")
|
|
36
47
|
while parent is not None:
|
|
@@ -48,16 +59,16 @@ def create_tree(context, root, parent=None):
|
|
|
48
59
|
|
|
49
60
|
# if root visibility restrictions and user is not authenticated do not show children
|
|
50
61
|
if not user.is_authenticated and (
|
|
51
|
-
root.login_required or root.
|
|
62
|
+
root.login_required or root.permissions_count > 0
|
|
52
63
|
): # noqa
|
|
53
64
|
return {}
|
|
54
65
|
|
|
55
66
|
if not user.is_authenticated:
|
|
56
67
|
# unlogged user sees only public items
|
|
57
|
-
items = root.children.enabled(login_required=False, permissions=None)
|
|
68
|
+
items = root.children.enabled(login_required=False, permissions=None).annotate(permissions_count=Count("permissions"))
|
|
58
69
|
elif user.is_superuser:
|
|
59
70
|
# superuser sees all enabled items
|
|
60
|
-
items = root.children.enabled()
|
|
71
|
+
items = root.children.enabled().annotate(permissions_count=Count("permissions"))
|
|
61
72
|
else:
|
|
62
73
|
# logged in user which is not superuse should check for permissions
|
|
63
74
|
permissions = context.get("lineup_permissions", None)
|
|
@@ -68,7 +79,7 @@ def create_tree(context, root, parent=None):
|
|
|
68
79
|
|
|
69
80
|
items = root.children.enabled(
|
|
70
81
|
Q(permissions__id__in=permissions) | Q(permissions=None)
|
|
71
|
-
).distinct()
|
|
82
|
+
).annotate(permissions_count=Count("permissions")).distinct()
|
|
72
83
|
|
|
73
84
|
# parent needed to traverse upward for has-active functionality
|
|
74
85
|
el = {"instance": root, "parent": parent}
|
|
@@ -92,11 +103,23 @@ def lineup_menu(context, item):
|
|
|
92
103
|
"""
|
|
93
104
|
if isinstance(item, str):
|
|
94
105
|
try:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
# cache depends on user (permissions) and path (active item)
|
|
107
|
+
path = ""
|
|
108
|
+
user = context.get("user")
|
|
109
|
+
if "request" in context:
|
|
110
|
+
path = context["request"].META["PATH_INFO"]
|
|
111
|
+
t = cache.get_or_set("lineup", {}, None)
|
|
112
|
+
key = "%s:%s:%s" % (item, user.id, path)
|
|
113
|
+
if t.get(key, None) is None:
|
|
114
|
+
root = MenuItem.objects.prefetch_related("children", "permissions").annotate(permissions_count=Count("permissions")).get(slug=item)
|
|
115
|
+
tree = create_tree(context, root)
|
|
116
|
+
items = tree.get("children", [])
|
|
117
|
+
slug = item
|
|
118
|
+
level = root.level
|
|
119
|
+
t[key] = (items, slug, level)
|
|
120
|
+
cache.set("lineup", t, None)
|
|
121
|
+
else:
|
|
122
|
+
(items, slug, level) = t[key]
|
|
100
123
|
except MenuItem.DoesNotExist:
|
|
101
124
|
logger.error("Provided lineup menu slug %s not found" % item)
|
|
102
125
|
return context
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '0.3.2'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/management/commands/import_menu_from_json.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django-lineup-0.3.2 → django-lineup-0.3.4}/lineup/templates/admin/lineup/menuitem/change_list.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|