Commit 8e971b10 authored by Nicolas Joyard's avatar Nicolas Joyard

Use autocomplete for themes in position form

parent 2a3afb72
......@@ -8,6 +8,7 @@ from views.home import HomeView
from views.autocomplete import (
ProposalAutocomplete,
RepresentativeAutocomplete,
ThemeAutocomplete,
)
from views.charts import ThemeScoresJSONView, ChamberScoresJSONView
......@@ -132,12 +133,19 @@ urlpatterns = [
ProposalAutocomplete.as_view(),
name='proposal-autocomplete',
),
url(
r'^autocomplete/representative/$',
RepresentativeAutocomplete.as_view(),
name='representative-autocomplete',
),
url(
r'^autocomplete/theme/$',
ThemeAutocomplete.as_view(),
name='theme-autocomplete',
),
# Theme list
......
......@@ -6,6 +6,7 @@ from django.db.models import Q
from representatives.models import Representative
from representatives_votes.models import Proposal
from memopol_themes.models import Theme
class RepresentativeAutocomplete(autocomplete.Select2QuerySetView):
......@@ -32,3 +33,13 @@ class ProposalAutocomplete(autocomplete.Select2QuerySetView):
)
return qs
class ThemeAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
qs = Theme.objects.all()
if self.q:
qs = qs.filter(name__icontains=self.q)
return qs
......@@ -11,7 +11,9 @@ class PositionForm(forms.ModelForm):
themes = forms.models.ModelMultipleChoiceField(
queryset=Theme.objects.all(),
required=False,
widget=forms.CheckboxSelectMultiple
widget=ModelSelect2Multiple(
url='theme-autocomplete',
)
)
class Meta:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment