summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2018-03-22 11:02:14 -0500
committerluxagraf <sng@luxagraf.net>2018-03-22 11:02:14 -0500
commitec28a9b734ded0ee3267c925546ba66f73b1fd34 (patch)
treefbef7f3f31b914c0628b69ea905b423230422b09 /app
parentc94a996b590a59aa4bc2c746c5ce6f7fad902189 (diff)
added autocomplete to sightings so it's easier to find APs
Diffstat (limited to 'app')
-rw-r--r--app/sightings/admin.py2
-rw-r--r--app/sightings/autocomplete_light_registry.py22
-rw-r--r--app/sightings/forms.py14
-rw-r--r--app/sightings/views.py13
4 files changed, 34 insertions, 17 deletions
diff --git a/app/sightings/admin.py b/app/sightings/admin.py
index e8a9b0a..a90cf95 100644
--- a/app/sightings/admin.py
+++ b/app/sightings/admin.py
@@ -5,6 +5,7 @@ from .models import APClass, AP, Sighting
from photos.forms import GalleryForm
from utils.util import get_latlon
from utils.widgets import CustomSelectMultiple, LGEntryForm
+from .forms import SightingsForm
class GalleryFormPlus(GalleryForm):
@@ -36,6 +37,7 @@ class APAdmin(admin.ModelAdmin):
@admin.register(Sighting)
class SightingAdmin(OSMGeoAdmin):
+ form = SightingsForm
list_filter = (('location', admin.RelatedOnlyFieldListFilter),)
list_display = ('ap', 'location')
# options for OSM map Using custom ESRI topo map
diff --git a/app/sightings/autocomplete_light_registry.py b/app/sightings/autocomplete_light_registry.py
index 1cfa881..9c113d0 100644
--- a/app/sightings/autocomplete_light_registry.py
+++ b/app/sightings/autocomplete_light_registry.py
@@ -1,24 +1,14 @@
import autocomplete_light.shortcuts as al
-from .models import Bird
+from .models import AP
-# This will generate a PersonAutocomplete class
-al.register(Bird,
- # Just like in ModelAdmin.search_fields
- search_fields=['common_name','scientific_name'],
+al.register(AP,
+ search_fields=['common_name',],
attrs={
- # This will set the input placeholder attribute:
- 'placeholder': 'Tags...',
- # This will set the yourlabs.Autocomplete.minimumCharacters
- # options, the naming conversion is handled by jQuery
- 'data-autocomplete-minimum-characters': 1,
-},
- # This will set the data-widget-maximum-values attribute on the
- # widget container element, and will be set to
- # yourlabs.Widget.maximumValues (jQuery handles the naming
- # conversion).
+ 'placeholder': 'Animal/Plant...',
+ 'data-autocomplete-minimum-characters': 2,
+ },
widget_attrs={
'data-widget-maximum-values': 4,
- # Enable modern-style widget !
'class': 'modern-style',
},
)
diff --git a/app/sightings/forms.py b/app/sightings/forms.py
new file mode 100644
index 0000000..9be7dcc
--- /dev/null
+++ b/app/sightings/forms.py
@@ -0,0 +1,14 @@
+from dal import autocomplete
+
+from .models import Sighting
+
+
+class SightingsForm(autocomplete.FutureModelForm):
+ class Meta:
+ model = Sighting
+ fields = ('ap', 'point', )
+ widgets = {
+ 'ap': autocomplete.TaggitSelect2(
+ 'ap-autocomplete'
+ )
+ }
diff --git a/app/sightings/views.py b/app/sightings/views.py
index f23898c..bf4cd81 100644
--- a/app/sightings/views.py
+++ b/app/sightings/views.py
@@ -1,7 +1,8 @@
from django.views.generic.detail import DetailView
from django.contrib.auth.models import User
from utils.views import PaginatedListView
-from .models import AP, Sighting
+from .models import AP, Sighting
+from dal import autocomplete
class SightingListView(PaginatedListView):
template_name = 'archives/sightings.html'
@@ -46,3 +47,13 @@ class SightingDetailView(DetailView):
except Sighting.DoesNotExist:
pass
return context
+
+
+class APAutocomplete(autocomplete.Select2QuerySetView):
+ def get_queryset(self):
+ if not self.request.user.is_authenticated:
+ return AP.objects.none()
+ qs = AP.objects.all()
+ if self.q:
+ qs = qs.filter(name__istartswith=self.q)
+ return qs