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 ...@@ -8,6 +8,7 @@ from views.home import HomeView
from views.autocomplete import ( from views.autocomplete import (
ProposalAutocomplete, ProposalAutocomplete,
RepresentativeAutocomplete, RepresentativeAutocomplete,
ThemeAutocomplete,
) )
from views.charts import ThemeScoresJSONView, ChamberScoresJSONView from views.charts import ThemeScoresJSONView, ChamberScoresJSONView
...@@ -132,12 +133,19 @@ urlpatterns = [ ...@@ -132,12 +133,19 @@ urlpatterns = [
ProposalAutocomplete.as_view(), ProposalAutocomplete.as_view(),
name='proposal-autocomplete', name='proposal-autocomplete',
), ),
url( url(
r'^autocomplete/representative/$', r'^autocomplete/representative/$',
RepresentativeAutocomplete.as_view(), RepresentativeAutocomplete.as_view(),
name='representative-autocomplete', name='representative-autocomplete',
), ),
url(
r'^autocomplete/theme/$',
ThemeAutocomplete.as_view(),
name='theme-autocomplete',
),
# Theme list # Theme list
......
...@@ -6,6 +6,7 @@ from django.db.models import Q ...@@ -6,6 +6,7 @@ from django.db.models import Q
from representatives.models import Representative from representatives.models import Representative
from representatives_votes.models import Proposal from representatives_votes.models import Proposal
from memopol_themes.models import Theme
class RepresentativeAutocomplete(autocomplete.Select2QuerySetView): class RepresentativeAutocomplete(autocomplete.Select2QuerySetView):
...@@ -32,3 +33,13 @@ class ProposalAutocomplete(autocomplete.Select2QuerySetView): ...@@ -32,3 +33,13 @@ class ProposalAutocomplete(autocomplete.Select2QuerySetView):
) )
return qs 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): ...@@ -11,7 +11,9 @@ class PositionForm(forms.ModelForm):
themes = forms.models.ModelMultipleChoiceField( themes = forms.models.ModelMultipleChoiceField(
queryset=Theme.objects.all(), queryset=Theme.objects.all(),
required=False, required=False,
widget=forms.CheckboxSelectMultiple widget=ModelSelect2Multiple(
url='theme-autocomplete',
)
) )
class Meta: 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