diff options
-rw-r--r-- | app/sightings/admin.py | 2 | ||||
-rw-r--r-- | app/sightings/autocomplete_light_registry.py | 22 | ||||
-rw-r--r-- | app/sightings/forms.py | 14 | ||||
-rw-r--r-- | app/sightings/views.py | 13 | ||||
-rw-r--r-- | config/base_urls.py | 2 | ||||
-rw-r--r-- | design/sass/_writing_details.scss | 3 |
6 files changed, 39 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 diff --git a/config/base_urls.py b/config/base_urls.py index 1e9b34f..7ecd472 100644 --- a/config/base_urls.py +++ b/config/base_urls.py @@ -18,6 +18,7 @@ from projects.models.base import ProjectSitemap import builder.views import utils.views from utils.views import TagAutocomplete +from sightings.views import APAutocomplete from locations.views import MapDataList @@ -33,6 +34,7 @@ sitemaps = { urlpatterns = [ path(r'tag-autocomplete/', TagAutocomplete.as_view(), name='tag-autocomplete'), + path(r'ap-autocomplete/', APAutocomplete.as_view(), name='ap-autocomplete'), re_path(r'^admin/build/.*', builder.views.do_build), path(r'admin/data/', include('utils.urls')), path(r'admin/', admin.site.urls), diff --git a/design/sass/_writing_details.scss b/design/sass/_writing_details.scss index f69092d..1ac0a38 100644 --- a/design/sass/_writing_details.scss +++ b/design/sass/_writing_details.scss @@ -295,6 +295,9 @@ figure.picwide img.picwide { max-width: $max_width *.99; } } +.src .picwide, .h-entry figure.picwide { + margin-left: auto !important; +} .picwide960 { clear: both; margin: 1em 0; |