Skip to content

Commit

Permalink
ICMSLST-1088 Use select2 in search for country selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Osku Salerma committed Sep 13, 2021
1 parent 0bc5f28 commit e9b53a9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
25 changes: 23 additions & 2 deletions web/domains/case/forms_search.py
Expand Up @@ -2,10 +2,12 @@
from typing import Optional

from django import forms
from django_select2.forms import Select2MultipleWidget

from web.domains.case._import.models import ImportApplicationType
from web.domains.case.export.models import ExportApplicationType
from web.domains.case.models import ApplicationBase
from web.domains.country.models import Country
from web.forms.widgets import DateInput
from web.models.shared import YesNoChoices

Expand Down Expand Up @@ -103,8 +105,19 @@ class ExportSearchForm(SearchFormBase):
closed_from = forms.DateField(label="Closed date", required=False, widget=DateInput)
closed_to = forms.DateField(label="To", required=False, widget=DateInput)

cert_country = forms.CharField(label="Certificate country", required=False)
manufacture_country = forms.CharField(label="Country of manufacture", required=False)
cert_country = forms.ModelMultipleChoiceField(
label="Certificate country",
required=False,
queryset=Country.objects.none(),
widget=Select2MultipleWidget,
)

manufacture_country = forms.ModelMultipleChoiceField(
label="Country of manufacture",
required=False,
queryset=Country.objects.none(),
widget=Select2MultipleWidget,
)

pending_firs = forms.ChoiceField(
label="Pending Further Information Requests",
Expand All @@ -118,6 +131,14 @@ class ExportSearchForm(SearchFormBase):
required=False,
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

countries = Country.objects.filter(is_active=True, type=Country.SOVEREIGN_TERRITORY)

self.fields["cert_country"].queryset = countries
self.fields["manufacture_country"].queryset = countries

def clean(self):
cd = super().clean()

Expand Down
2 changes: 2 additions & 0 deletions web/domains/case/views_search.py
Expand Up @@ -81,4 +81,6 @@ def _get_search_terms_from_form(case_type: str, form: SearchForm) -> SearchTerms
issue_date_end=cd.get("issue_to"),
reassignment_search=cd.get("reassignment"),
# TODO: add all the export search fields
# cert_country=cd.get("cert_country"),
# manufacture_country=cd.get("manufacture_country"),
)
1 change: 1 addition & 0 deletions web/templates/web/domains/case/search/search.html
Expand Up @@ -3,6 +3,7 @@
{% import "forms/fields.html" as fields %}

{% block css %}
{{ form.media.css }}
<link rel="stylesheet" type="text/css" href="{{ static('web/css/pages/search.css') }}">
{% endblock %}

Expand Down

0 comments on commit e9b53a9

Please sign in to comment.