django-mptt-admin 2.5.1__py3.11.egg

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.
Files changed (60) hide show
  1. EGG-INFO/PKG-INFO +39 -0
  2. EGG-INFO/SOURCES.txt +65 -0
  3. EGG-INFO/dependency_links.txt +1 -0
  4. EGG-INFO/not-zip-safe +1 -0
  5. EGG-INFO/requires.txt +1 -0
  6. EGG-INFO/top_level.txt +1 -0
  7. django_mptt_admin/__init__.py +0 -0
  8. django_mptt_admin/admin.py +11 -0
  9. django_mptt_admin/django_mptt_admin_mixin.py +337 -0
  10. django_mptt_admin/locale/ca/LC_MESSAGES/django.mo +0 -0
  11. django_mptt_admin/locale/ca/LC_MESSAGES/django.po +30 -0
  12. django_mptt_admin/locale/ca/LC_MESSAGES/djangojs.mo +0 -0
  13. django_mptt_admin/locale/ca/LC_MESSAGES/djangojs.po +34 -0
  14. django_mptt_admin/locale/de/LC_MESSAGES/django.mo +0 -0
  15. django_mptt_admin/locale/de/LC_MESSAGES/django.po +31 -0
  16. django_mptt_admin/locale/de/LC_MESSAGES/djangojs.mo +0 -0
  17. django_mptt_admin/locale/de/LC_MESSAGES/djangojs.po +35 -0
  18. django_mptt_admin/locale/es/LC_MESSAGES/django.mo +0 -0
  19. django_mptt_admin/locale/es/LC_MESSAGES/django.po +30 -0
  20. django_mptt_admin/locale/es/LC_MESSAGES/djangojs.mo +0 -0
  21. django_mptt_admin/locale/es/LC_MESSAGES/djangojs.po +34 -0
  22. django_mptt_admin/locale/fr/LC_MESSAGES/django.mo +0 -0
  23. django_mptt_admin/locale/fr/LC_MESSAGES/django.po +30 -0
  24. django_mptt_admin/locale/fr/LC_MESSAGES/djangojs.mo +0 -0
  25. django_mptt_admin/locale/fr/LC_MESSAGES/djangojs.po +35 -0
  26. django_mptt_admin/locale/he/LC_MESSAGES/django.mo +0 -0
  27. django_mptt_admin/locale/he/LC_MESSAGES/django.po +19 -0
  28. django_mptt_admin/locale/he/LC_MESSAGES/djangojs.mo +0 -0
  29. django_mptt_admin/locale/he/LC_MESSAGES/djangojs.po +25 -0
  30. django_mptt_admin/locale/hu/LC_MESSAGES/django.mo +0 -0
  31. django_mptt_admin/locale/hu/LC_MESSAGES/django.po +24 -0
  32. django_mptt_admin/locale/hu/LC_MESSAGES/djangojs.mo +0 -0
  33. django_mptt_admin/locale/hu/LC_MESSAGES/djangojs.po +24 -0
  34. django_mptt_admin/locale/pl/LC_MESSAGES/django.mo +0 -0
  35. django_mptt_admin/locale/pl/LC_MESSAGES/django.po +31 -0
  36. django_mptt_admin/locale/pl/LC_MESSAGES/djangojs.mo +0 -0
  37. django_mptt_admin/locale/pl/LC_MESSAGES/djangojs.po +35 -0
  38. django_mptt_admin/locale/ru/LC_MESSAGES/django.mo +0 -0
  39. django_mptt_admin/locale/ru/LC_MESSAGES/django.po +20 -0
  40. django_mptt_admin/locale/ru/LC_MESSAGES/djangojs.mo +0 -0
  41. django_mptt_admin/locale/ru/LC_MESSAGES/djangojs.po +32 -0
  42. django_mptt_admin/locale/tr/LC_MESSAGES/django.mo +0 -0
  43. django_mptt_admin/locale/tr/LC_MESSAGES/django.po +19 -0
  44. django_mptt_admin/locale/tr/LC_MESSAGES/djangojs.mo +0 -0
  45. django_mptt_admin/locale/tr/LC_MESSAGES/djangojs.po +25 -0
  46. django_mptt_admin/static/django_mptt_admin/django_mptt_admin.css +260 -0
  47. django_mptt_admin/static/django_mptt_admin/django_mptt_admin.css.map +1 -0
  48. django_mptt_admin/static/django_mptt_admin/django_mptt_admin.debug.js +5014 -0
  49. django_mptt_admin/static/django_mptt_admin/django_mptt_admin.debug.js.map +1 -0
  50. django_mptt_admin/static/django_mptt_admin/django_mptt_admin.js +3 -0
  51. django_mptt_admin/static/django_mptt_admin/django_mptt_admin.js.LICENSE.txt +6 -0
  52. django_mptt_admin/static/django_mptt_admin/django_mptt_admin.js.map +1 -0
  53. django_mptt_admin/static/django_mptt_admin/jqtree-circle.png +0 -0
  54. django_mptt_admin/static/django_mptt_admin/jquery_namespace.js +2 -0
  55. django_mptt_admin/templates/django_mptt_admin/change_list.html +53 -0
  56. django_mptt_admin/templates/django_mptt_admin/grid_view.html +9 -0
  57. django_mptt_admin/templatetags/__init__.py +0 -0
  58. django_mptt_admin/templatetags/javascript_value.py +21 -0
  59. django_mptt_admin/tree_change_list.py +67 -0
  60. django_mptt_admin/util.py +111 -0
@@ -0,0 +1,2 @@
1
+ window.$ = django.jQuery;
2
+ window.jQuery = django.jQuery;
@@ -0,0 +1,53 @@
1
+ {% extends 'admin/change_list.html' %}
2
+ {% load i18n admin_list javascript_value %}
3
+
4
+ {% block extrastyle %}
5
+ {{ block.super }}
6
+ <script type="text/javascript" src="{{ jsi18n_url }}"></script>
7
+ {% endblock %}
8
+
9
+ {% block search %}{% endblock %}
10
+
11
+ {% block result_list %}
12
+ <div
13
+ id="tree"
14
+ class="block-style"
15
+ data-auto_open="{{ tree_auto_open|javascript_value }}"
16
+ data-autoescape="{{ autoescape|javascript_value }}"
17
+ data-csrf-cookie-name="{{ csrf_cookie_name }}"
18
+ data-insert_at_url="{{ insert_at_url }}"
19
+ data-drag-and-drop="{{ drag_and_drop|javascript_value }}"
20
+ data-has-add-permission="{{ has_add_permission|javascript_value }}"
21
+ data-has-change-permission="{{ has_change_permission|javascript_value }}"
22
+ {% if LANGUAGE_BIDI %}
23
+ data-rtl
24
+ {% endif %}
25
+ data-save_state="{{ app_label }}_{{ model_name }}"
26
+ {% if tree_animation_speed is not None %}
27
+ data-tree-animation-speed="{{ tree_animation_speed|javascript_value }}"
28
+ {% endif %}
29
+ {% if tree_mouse_delay is not None %}
30
+ data-tree-mouse-delay="{{ tree_mouse_delay|javascript_value }}"
31
+ {% endif %}
32
+ data-url="{{ tree_json_url }}"
33
+ data-use_context_menu="{{ use_context_menu|javascript_value }}"
34
+ ></div>
35
+ {% endblock %}
36
+
37
+ {% block filters %}
38
+ {% if cl.has_filters %}
39
+ <div id="changelist-filter">
40
+ <h2>{% trans 'Filter' %}</h2>
41
+ {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
42
+ </div>
43
+ {% endif %}
44
+ {% endblock %}
45
+
46
+ {% block pagination %}{% endblock %}
47
+
48
+ {% block object-tools-items %}
49
+ {{ block.super }}
50
+ <li>
51
+ <a href="{{ grid_url }}">{% trans "Grid view" %}</a>
52
+ </li>
53
+ {% endblock %}
@@ -0,0 +1,9 @@
1
+ {% extends 'admin/change_list.html' %}
2
+ {% load i18n %}
3
+
4
+ {% block object-tools-items %}
5
+ {{ block.super }}
6
+ <li>
7
+ <a href="{{ tree_url }}">{% trans "Tree view" %}</a>
8
+ </li>
9
+ {% endblock %}
File without changes
@@ -0,0 +1,21 @@
1
+ import json
2
+ from django import template
3
+
4
+ register = template.Library()
5
+ @register.filter
6
+ def javascript_value(value):
7
+ """
8
+ Get javascript value for python value.
9
+
10
+ >>> get_javascript_value(True)
11
+ true
12
+ >>> get_javascript_value(10)
13
+ 10
14
+ """
15
+ if isinstance(value, bool):
16
+ if value:
17
+ return "true"
18
+ else:
19
+ return "false"
20
+ else:
21
+ return json.dumps(value)
@@ -0,0 +1,67 @@
1
+ from django.contrib.admin.views.main import ChangeList, IGNORED_PARAMS
2
+ import django
3
+
4
+ from . import util
5
+
6
+
7
+ class TreeChangeList(ChangeList):
8
+ TREE_IGNORED_PARAMS = IGNORED_PARAMS + ("_", "node", "selected_node")
9
+
10
+ def __init__(self, request, model, model_admin, list_filter, node_id, max_level):
11
+ self.node_id = node_id
12
+ self.max_level = max_level
13
+
14
+ params = dict(
15
+ request=request,
16
+ model=model,
17
+ list_filter=list_filter,
18
+ model_admin=model_admin,
19
+ list_display=(),
20
+ list_display_links=(),
21
+ date_hierarchy=None,
22
+ search_fields=(),
23
+ list_select_related=(),
24
+ list_per_page=100,
25
+ list_editable=(),
26
+ list_max_show_all=200,
27
+ sortable_by=[],
28
+ )
29
+
30
+ if django.VERSION >= (4, 0):
31
+ params['search_help_text'] = ''
32
+
33
+ super().__init__(**params)
34
+
35
+ def get_filters_params(self, params=None):
36
+ if not params:
37
+ params = self.params
38
+
39
+ lookup_params = params.copy()
40
+
41
+ for ignored in self.TREE_IGNORED_PARAMS:
42
+ if ignored in lookup_params:
43
+ del lookup_params[ignored]
44
+
45
+ return lookup_params
46
+
47
+ def get_queryset(self, request):
48
+ (
49
+ self.filter_specs,
50
+ self.has_filters,
51
+ remaining_lookup_params,
52
+ filters_use_distinct,
53
+ self.has_active_filters,
54
+ ) = self.get_filters(request)
55
+
56
+ qs = util.get_tree_queryset(
57
+ model=self.model,
58
+ node_id=self.node_id,
59
+ max_level=self.max_level,
60
+ )
61
+
62
+ for filter_spec in self.filter_specs:
63
+ new_qs = filter_spec.queryset(request, qs)
64
+ if new_qs is not None:
65
+ qs = new_qs
66
+
67
+ return qs
@@ -0,0 +1,111 @@
1
+ def serialize_id(pk):
2
+ if isinstance(pk, (int, str)):
3
+ return pk
4
+ else:
5
+ # Nb. special case for uuid field
6
+ return str(pk)
7
+
8
+
9
+ def get_tree_from_queryset(
10
+ queryset, on_create_node=None, max_level=None, item_label_field_name=None
11
+ ):
12
+ """
13
+ Return tree data that is suitable for jqTree.
14
+ The queryset must be sorted by 'tree_id' and 'left' fields.
15
+ """
16
+ pk_attname = queryset.model._meta.pk.attname
17
+
18
+ # Result tree
19
+ tree = []
20
+
21
+ # Dict of all nodes; used for building the tree
22
+ # - key is node id
23
+ # - value is node info (label, id)
24
+ node_dict = dict()
25
+
26
+ # The lowest level of the tree; used for building the tree
27
+ # - Initial value is None; set later
28
+ # - For the whole tree this is 0, for a subtree this is higher
29
+ min_level = None
30
+
31
+ for instance in queryset:
32
+ if min_level is None or instance.level < min_level:
33
+ min_level = instance.level
34
+
35
+ pk = getattr(instance, pk_attname)
36
+
37
+ if item_label_field_name:
38
+ label = getattr(instance, item_label_field_name)
39
+ else:
40
+ label = str(instance)
41
+
42
+ node_info = dict(name=label, id=serialize_id(pk))
43
+ if on_create_node:
44
+ on_create_node(instance, node_info)
45
+
46
+ if max_level is not None and not instance.is_leaf_node():
47
+ # If there is a maximum level and this node has children, then initially set property 'load_on_demand' to true.
48
+ node_info["load_on_demand"] = True
49
+
50
+ if instance.level == min_level:
51
+ # This is the lowest level. Skip finding a parent.
52
+ # Add node to the tree
53
+ tree.append(node_info)
54
+ else:
55
+ # NB: use instance's local value for parent attribute - consistent values for uuid
56
+ parent_field = instance._meta.get_field(instance._mptt_meta.parent_attr)
57
+ parent_attname = parent_field.get_attname()
58
+ parent_id = getattr(instance, parent_attname)
59
+
60
+ # Get parent from node dict
61
+ parent_info = node_dict.get(parent_id)
62
+
63
+ # Check for corner case: parent is deleted.
64
+ if parent_info:
65
+ if "children" not in parent_info:
66
+ parent_info["children"] = []
67
+
68
+ # Add node to the tree
69
+ parent_info["children"].append(node_info)
70
+
71
+ # If there is a maximum level, then reset property 'load_on_demand' for parent
72
+ if max_level is not None:
73
+ parent_info["load_on_demand"] = False
74
+
75
+ # Update node dict
76
+ node_dict[pk] = node_info
77
+
78
+ return tree
79
+
80
+
81
+ def get_tree_queryset(model, node_id=None, max_level=None, include_root=True):
82
+ if node_id:
83
+ node = model.objects.get(pk=node_id)
84
+
85
+ if max_level is None:
86
+ max_level = node.level + 1
87
+
88
+ qs = node.get_descendants().filter(level__lte=max_level)
89
+ else:
90
+ qs = model._default_manager.all()
91
+
92
+ if max_level is True:
93
+ max_level = 1
94
+
95
+ if isinstance(max_level, int) and max_level is not False:
96
+ qs = qs.filter(level__lte=max_level)
97
+
98
+ if not include_root:
99
+ qs = qs.exclude(level=0)
100
+
101
+ return qs.order_by("tree_id", "lft")
102
+
103
+
104
+ def get_model_name(model):
105
+ """
106
+ Get the name of a Django model
107
+
108
+ >>> get_model_name(Country)
109
+ country
110
+ """
111
+ return model._meta.model_name