Repository: DDMAL/CantusDB

Issue:
Source Create/Edit pages: RISM siglum field could be a Filterable List widget
Spinning off of #971, I fixed the immediate problem, but I still think it could be good to convert the RISM siglum field to be a Filterable List.


Discussion:

Resolving patch:
diff --git a/django/cantusdb_project/main_app/forms.py b/django/cantusdb_project/main_app/forms.py
--- a/django/cantusdb_project/main_app/forms.py
+++ b/django/cantusdb_project/main_app/forms.py
@@ -223,6 +223,7 @@ class Meta:
             "fragmentarium_id": TextInputWidget(),
             "dact_id": TextInputWidget(),
             "indexing_notes": TextAreaWidget(),
+            "rism_siglum": autocomplete.ModelSelect2(url="rismsiglum-autocomplete"),
             "current_editors": autocomplete.ModelSelect2Multiple(
                 url="current-editors-autocomplete"
             ),
@@ -244,13 +245,6 @@ class Meta:
             ),
         }
 
-    rism_siglum = forms.ModelChoiceField(
-        queryset=RismSiglum.objects.all().order_by("name"), required=False
-    )
-    rism_siglum.widget.attrs.update(
-        {"class": "form-control custom-select custom-select-sm"}
-    )
-
     provenance = forms.ModelChoiceField(
         queryset=Provenance.objects.all().order_by("name"), required=False
     )
@@ -515,6 +509,7 @@ class Meta:
         ]
         widgets = {
             "title": TextInputWidget(),
+            "rism_siglum": autocomplete.ModelSelect2(url="rismsiglum-autocomplete"),
             "siglum": TextInputWidget(),
             "provenance_notes": TextInputWidget(),
             "date": TextInputWidget(),
@@ -546,13 +541,6 @@ class Meta:
             ),
         }
 
-    rism_siglum = forms.ModelChoiceField(
-        queryset=RismSiglum.objects.all().order_by("name"), required=False
-    )
-    rism_siglum.widget.attrs.update(
-        {"class": "form-control custom-select custom-select-sm"}
-    )
-
     provenance = forms.ModelChoiceField(
         queryset=Provenance.objects.all().order_by("name"), required=False
     )
diff --git a/django/cantusdb_project/main_app/urls.py b/django/cantusdb_project/main_app/urls.py
--- a/django/cantusdb_project/main_app/urls.py
+++ b/django/cantusdb_project/main_app/urls.py
@@ -67,6 +67,7 @@
     CurrentEditorsAutocomplete,
     AllUsersAutocomplete,
     CenturyAutocomplete,
+    RismSiglumAutocomplete,
 )
 
 urlpatterns = [
@@ -460,6 +461,11 @@
         CenturyAutocomplete.as_view(),
         name="century-autocomplete",
     ),
+    path(
+        "rismsiglum-autocomplete/",
+        RismSiglumAutocomplete.as_view(),
+        name="rismsiglum-autocomplete",
+    ),
 ]
 
 handler404 = "main_app.views.views.handle404"
diff --git a/django/cantusdb_project/main_app/views/views.py b/django/cantusdb_project/main_app/views/views.py
--- a/django/cantusdb_project/main_app/views/views.py
+++ b/django/cantusdb_project/main_app/views/views.py
@@ -993,3 +993,13 @@ def get_queryset(self):
         if self.q:
             qs = qs.filter(name__istartswith=self.q)
         return qs
+
+
+class RismSiglumAutocomplete(autocomplete.Select2QuerySetView):
+    def get_queryset(self):
+        if not self.request.user.is_authenticated:
+            return RismSiglum.objects.none()
+        qs = RismSiglum.objects.all().order_by("name")
+        if self.q:
+            qs = qs.filter(name__istartswith=self.q)
+        return qs


Test patch: