Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Political Memory
memopol
Commits
d609894b
Commit
d609894b
authored
Oct 08, 2016
by
Jamesie Pic
Browse files
Add autocomplete
parent
f1c19341
Pipeline
#152
passed with stages
in 18 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/memopol/urls.py
View file @
d609894b
...
...
@@ -5,7 +5,10 @@ from django.contrib import admin
from
views.home
import
HomeView
from
views.dossier_ac
import
ProposalAutocomplete
from
views.autocomplete
import
(
ProposalAutocomplete
,
RepresentativeAutocomplete
,
)
from
views.dossier_detail_base
import
DossierDetailBase
from
views.dossier_detail_recommendations
import
DossierDetailRecommendations
from
views.dossier_detail_proposals
import
DossierDetailProposals
...
...
@@ -119,13 +122,19 @@ urlpatterns = [
name
=
'dossier-documents'
),
#
Dossier a
utocomplete
for admin
#
A
utocomplete
url
(
r
'^autocomplete/proposal/$'
,
ProposalAutocomplete
.
as_view
(),
name
=
'proposal-autocomplete'
,
),
url
(
r
'^autocomplete/representative/$'
,
RepresentativeAutocomplete
.
as_view
(),
name
=
'representative-autocomplete'
,
),
# Theme list
...
...
src/memopol/views/
dossier_ac
.py
→
src/memopol/views/
autocomplete
.py
View file @
d609894b
...
...
@@ -4,9 +4,22 @@ from dal import autocomplete
from
django.db.models
import
Q
from
representatives.models
import
Representative
from
representatives_votes.models
import
Proposal
class
RepresentativeAutocomplete
(
autocomplete
.
Select2QuerySetView
):
def
get_queryset
(
self
):
qs
=
Representative
.
objects
.
all
()
if
self
.
q
:
qs
=
qs
.
filter
(
Q
(
full_name__icontains
=
self
.
q
)
)
return
qs
class
ProposalAutocomplete
(
autocomplete
.
Select2QuerySetView
):
def
get_queryset
(
self
):
qs
=
Proposal
.
objects
.
all
()
...
...
src/memopol_themes/admin.py
View file @
d609894b
from
dal
import
autocomplete
from
django
import
forms
from
django.contrib
import
admin
...
...
@@ -76,6 +78,11 @@ class ThemedPositionAdminForm(ThemedAdminForm):
model
=
Position
fields
=
(
'representative'
,
'datetime'
,
'kind'
,
'title'
,
'score'
,
'text'
,
'link'
,
'published'
,
'themes'
)
widgets
=
{
'representative'
:
autocomplete
.
ModelSelect2
(
url
=
'representative-autocomplete'
,
)
}
class
ThemedDossierAdmin
(
DossierAdmin
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment