-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize multiselect dropdown widget
We need a generic multiselect dropdown widget all over the place and the one specialized for selecting sources in the filterbox was *almost* all we needed.
- Loading branch information
Showing
5 changed files
with
35 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Generalized the multiselect dropdown widget used for the source field in the | ||
filterbox so that we can use it for other dropdowns on other pages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
...mx/incidents/_incident_source_select.html → ...dents/widgets/incident_source_select.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
{% extends "htmx/forms/dropdown_select_multiple.html" %} | ||
{% block field_control %} | ||
{{ block.super }} | ||
hx-get="{% url 'htmx:incidents-filter' %}" | ||
{% endblock field_control %} | ||
{% block show_selected %} | ||
<span class="badge badge-primary">{{ option.label }}</span> | ||
{% endblock show_selected %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django import forms | ||
|
||
|
||
class ExtraWidgetMixin: | ||
def __init__(self, extra=None, **kwargs): | ||
super().__init__(**kwargs) | ||
self.extra = {} if extra is None else extra | ||
|
||
def __deepcopy__(self, memo): | ||
obj = super().__deepcopy__(memo) | ||
obj.extra = self.extra.copy() | ||
memo[id(self)] = obj | ||
return obj | ||
|
||
def get_context(self, name, value, attrs): | ||
context = super().get_context(name, value, attrs) | ||
context["widget"]["extra"] = self.extra | ||
return context | ||
|
||
|
||
class DropdownMultiSelect(ExtraWidgetMixin, forms.CheckboxSelectMultiple): | ||
template_name = "htmx/forms/dropdown_select_multiple.html" | ||
option_template_name = "htmx/forms/checkbox_select_multiple.html" |