Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
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 theme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.15"
__version__ = "0.0.16"

# set default_app_config when using django earlier than 3.2
try:
Expand Down
39 changes: 25 additions & 14 deletions theme/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,43 @@


class RelatedFieldAjaxListFilter(RelatedFieldListFilter):
template = 'admin/related_field_ajax_list_filter.html'
template = "admin/related_field_ajax_list_filter.html"

Check warning on line 10 in theme/filters.py

View check run for this annotation

Codecov / codecov/patch

theme/filters.py#L10

Added line #L10 was not covered by tests
ajax_attrs = None

def has_output(self):
return True

def field_choices(self, field, request, model_admin):
model = field.remote_field.model if hasattr(field, 'remote_field') else field.related_field.model
model = (

Check warning on line 17 in theme/filters.py

View check run for this annotation

Codecov / codecov/patch

theme/filters.py#L17

Added line #L17 was not covered by tests
field.remote_field.model
if hasattr(field, "remote_field")
else field.related_field.model
)
app_label = model._meta.app_label
model_name = model._meta.object_name

self.ajax_attrs = format_html(
'{0}',
"{0}",
flatatt(
{
'data-app-label': app_label,
'data-model': model_name,
'data-ajax--url': reverse('surface_theme:model_lookup'),
'data-queryset--lookup': self.lookup_kwarg,
"data-app-label": app_label,
"data-model": model_name,
"data-ajax--url": reverse("surface_theme:model_lookup"),
"data-queryset--lookup": self.lookup_kwarg,
}
),
)

if self.lookup_val is None:
return []

if isinstance(

Check warning on line 40 in theme/filters.py

View check run for this annotation

Codecov / codecov/patch

theme/filters.py#L40

Added line #L40 was not covered by tests
self.lookup_val, list
): # Django 5.0: filter values from query parameters can be passed as lists
self.lookup_val = self.lookup_val[0]

Check warning on line 43 in theme/filters.py

View check run for this annotation

Codecov / codecov/patch

theme/filters.py#L43

Added line #L43 was not covered by tests

other_model = get_model_from_relation(field)
if hasattr(field, 'rel'):
if hasattr(field, "rel"):

Check warning on line 46 in theme/filters.py

View check run for this annotation

Codecov / codecov/patch

theme/filters.py#L46

Added line #L46 was not covered by tests
rel_name = field.rel.get_related_field().name
else:
rel_name = other_model._meta.pk.name
Expand All @@ -52,7 +61,7 @@

class DateRangeFilter(OriginalDateRangeFilter):
def get_template(self):
return 'rangefilter/date_filter.html'
return "rangefilter/date_filter.html"

Check warning on line 64 in theme/filters.py

View check run for this annotation

Codecov / codecov/patch

theme/filters.py#L64

Added line #L64 was not covered by tests

def _get_form_fields(self):
# this is here, because in parent DateRangeFilter AdminDateWidget
Expand All @@ -62,23 +71,25 @@
(
self.lookup_kwarg_gte,
forms.DateField(
label='',
widget=AdminDateWidget(attrs={'placeholder': _('From date')}),
label="",
widget=AdminDateWidget(
attrs={"placeholder": _("From date")}
),
localize=True,
required=False,
),
),
(
self.lookup_kwarg_lte,
forms.DateField(
label='',
widget=AdminDateWidget(attrs={'placeholder': _('To date')}),
label="",
widget=AdminDateWidget(attrs={"placeholder": _("To date")}),
localize=True,
required=False,
),
),
)
)

except ImportError as e:
except ImportError:

Check warning on line 94 in theme/filters.py

View check run for this annotation

Codecov / codecov/patch

theme/filters.py#L94

Added line #L94 was not covered by tests
pass
Loading