From 621b451dc5bf0a63b783ee95904a5db7ba5a5669 Mon Sep 17 00:00:00 2001 From: David Barnes <barnesdavidj@gmail.com> Date: Mon, 17 Oct 2022 11:04:47 -0400 Subject: [PATCH] Fix bugs where MAX_ITERATIONS and MAX_DEPTH were not working correctly. --- .../django_dump_die/partials/_attributes.html | 6 ++++-- .../django_dump_die/partials/_dump_objects.html | 2 +- django_dump_die/templatetags/dump_die.py | 10 ++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/django_dump_die/templates/django_dump_die/partials/_attributes.html b/django_dump_die/templates/django_dump_die/partials/_attributes.html index dd3797f..49eecfe 100644 --- a/django_dump_die/templates/django_dump_die/partials/_attributes.html +++ b/django_dump_die/templates/django_dump_die/partials/_attributes.html @@ -32,9 +32,11 @@ <span class="{{ css_class }}" title="{{ title }}">{{ attr }}</span>: {% endif %} {% if intermediate %} - {% dump_object value root_obj skip forloop.counter0 new_depth root_index_start root_index_end original_obj True %} - {% else %} + {% dump_object value root_obj skip 0 new_depth root_index_start root_index_end original_obj True %} + {% elif is_iterable %} {% dump_object value root_obj skip forloop.counter0 new_depth root_index_start root_index_end original_obj False %} + {% else %} + {% dump_object value root_obj skip 0 new_depth root_index_start root_index_end original_obj False %} {% endif %} {% endwith %} </li> diff --git a/django_dump_die/templates/django_dump_die/partials/_dump_objects.html b/django_dump_die/templates/django_dump_die/partials/_dump_objects.html index 19d7567..3c8e8fb 100644 --- a/django_dump_die/templates/django_dump_die/partials/_dump_objects.html +++ b/django_dump_die/templates/django_dump_die/partials/_dump_objects.html @@ -42,7 +42,7 @@ <span class="empty" title="Dumped Object">Unknown Object</span>: {% endif %} {# Use dump_object template tag to dump object #} - {% dump_object obj obj None forloop.counter0 0 root_index_start root_index_end original_obj %} + {% dump_object obj obj None 0 0 root_index_start root_index_end original_obj %} {% endif %} </div> diff --git a/django_dump_die/templatetags/dump_die.py b/django_dump_die/templatetags/dump_die.py index e869bf6..0dfeb6a 100644 --- a/django_dump_die/templatetags/dump_die.py +++ b/django_dump_die/templatetags/dump_die.py @@ -161,7 +161,7 @@ def dump_object( ) # Handle if element is iterable and we are at the root's element direct children (depth of 1), - elif is_iterable(root_obj) and current_depth == 1: + elif is_iterable(root_obj) and current_depth == 0: # Handle unique indexing logic for root element. root_index_start, root_index_end = _process_root_indices( @@ -371,14 +371,14 @@ def is_complex_type(current_depth, current_iteration): # Check if the max_recursion is set to None or we have not reached it yet. ( MAX_RECURSION_DEPTH is None - or current_depth <= MAX_RECURSION_DEPTH + or current_depth < MAX_RECURSION_DEPTH ) # And if the max_iterable_length is set to None, # or we have not reached it yet or we are at the root level. and ( MAX_ITERABLE_LENGTH is None - or current_iteration <= MAX_ITERABLE_LENGTH + or current_iteration < MAX_ITERABLE_LENGTH ) ) ) @@ -522,6 +522,8 @@ def _handle_complex_type( # Attempt to get corresponding attribute/function values of object. attributes, functions = get_obj_values(obj) + is_iterable_obj = is_iterable(obj) and not is_dict(obj) and not isinstance(obj, memoryview) + # Return information required to render object. context = { 'include_attributes': INCLUDE_ATTRIBUTES, @@ -532,7 +534,7 @@ def _handle_complex_type( 'unique': unique, 'root_count': root_count, 'type': get_obj_type(obj), - 'is_iterable': is_iterable(obj), + 'is_iterable': is_iterable_obj, 'depth': current_depth, 'root_index_start': root_index_start, 'root_index_end': root_index_end, -- GitLab