Add Subspecialty autocomplete and filter to QuestionFilter
This commit is contained in:
+6
-1
@@ -2,7 +2,7 @@ from django.urls import path, include
|
||||
from django.views.generic import RedirectView, TemplateView
|
||||
|
||||
|
||||
from atlas.models import Condition, Finding, Presentation, Structure
|
||||
from atlas.models import Condition, Finding, Presentation, Structure, Subspecialty
|
||||
from . import views
|
||||
|
||||
app_name = "atlas"
|
||||
@@ -528,6 +528,11 @@ urlpatterns = [
|
||||
views.StructureAutocomplete.as_view(model=Structure, create_field="name", validate_create=True),
|
||||
name="structure-autocomplete",
|
||||
),
|
||||
path(
|
||||
"subspecialty-autocomplete",
|
||||
views.SubspecialtyAutocomplete.as_view(model=Subspecialty, create_field="name"),
|
||||
name="subspecialty-autocomplete",
|
||||
),
|
||||
path("presentation/", views.PresentationView.as_view(), name="presentation_view"),
|
||||
path(
|
||||
"presentation/<int:pk>", views.presentation_detail, name="presentation_detail"
|
||||
|
||||
@@ -1978,6 +1978,24 @@ class StructureAutocomplete(autocomplete.Select2QuerySetView):
|
||||
return qs
|
||||
|
||||
|
||||
class SubspecialtyAutocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
# Don't forget to filter out results depending on the visitor !
|
||||
if not self.request.user.is_authenticated:
|
||||
return Subspecialty.objects.none()
|
||||
|
||||
qs = Subspecialty.objects.all()
|
||||
|
||||
if self.q:
|
||||
# This raises a fielderror which breaks creating a new item if not caught
|
||||
try:
|
||||
qs = qs.filter(name__icontains=self.q)
|
||||
except FieldError:
|
||||
return Subspecialty.objects.none()
|
||||
|
||||
return qs
|
||||
|
||||
|
||||
@login_required
|
||||
# @user_is_atlas_editor
|
||||
def categories_list(request):
|
||||
|
||||
Reference in New Issue
Block a user