Repository: DDMAL/CantusDB

Issue:
search chant results should order by RISM siglum
Currently search results are in a strange order loosely associated with the city the source is in, as in Aberystwyth-Arras-Aosta (why is this after Arras?)-Assisi, and a strange interloping London source that also goes by "Augsburg"

![image](https://user-images.githubusercontent.com/67451875/211892851-82f7ed3d-28e4-49e9-9804-e3d1c216b865.png)


This is different from OldCantus, which (as far as I know) alphabetizes by RISM siglum, which means one gets all the A-for-Austria sources together and all the B-for-Belgium sources etc. 
![image](https://user-images.githubusercontent.com/67451875/211893543-575a7741-f3a4-434f-a813-c8cb1979fbd1.png)



Discussion:
Should have been more specific--this is true for search_bar searches (http://206.12.88.113/chant-search/?search_bar=urbis), not for keyword searches. And if I try to order the columns of search_bar searches (perhaps to compare the results to keyword ones...) I get a 502 error.
With the ordering of columns generating a 502 error, I think this amounts to a bug. Assigning a priority of medium
On production this doesn't seem to order at all. http://206.12.93.196/chant-search/?search_bar=deo&page=1
<img width="1086" alt="image" src="https://github.com/DDMAL/CantusDB/assets/67451875/fa6bf1f6-e79d-4fa0-9ed1-493520475c22">
When one tries to order by column header, the search term is lost, and you get an ordered list of all chants (http://206.12.93.196/chant-search/?&order=siglum&sort=asc)
<img width="1129" alt="image" src="https://github.com/DDMAL/CantusDB/assets/67451875/4eac2c38-9b4d-4a96-8947-7d3da529beed">

> When one tries to order by column header, the search term is lost, and you get an ordered list of all chants (http://206.12.93.196/chant-search/?&order=siglum&sort=asc)

Ah! The links in the column headers account for all the fields on the main form, but they don't make any effort to preserve the text in the global search bar.

Resolving patch:
diff --git a/django/cantusdb_project/main_app/views/chant.py b/django/cantusdb_project/main_app/views/chant.py
--- a/django/cantusdb_project/main_app/views/chant.py
+++ b/django/cantusdb_project/main_app/views/chant.py
@@ -695,43 +695,45 @@ def get_context_data(self, **kwargs) -> dict:
         # build a url containing all the search parameters, excluding ordering parameters.
         # this way, when someone clicks on a column heading, we can append the ordering parameters
         # while retaining the search parameters
-        current_url = self.request.path
-        search_parameters = []
+        current_url: str = self.request.path
+        search_parameters: list[str] = []
 
-        search_op = self.request.GET.get("op")
+        search_op: Optional[str] = self.request.GET.get("op")
         if search_op:
             search_parameters.append(f"op={search_op}")
-        search_keyword = self.request.GET.get("keyword")
+        search_keyword: Optional[str] = self.request.GET.get("keyword")
         if search_keyword:
             search_parameters.append(f"keyword={search_keyword}")
             context["keyword"] = search_keyword
-        search_office = self.request.GET.get("office")
+        search_office: Optional[str] = self.request.GET.get("office")
         if search_office:
             search_parameters.append(f"office={search_office}")
-        search_genre = self.request.GET.get("genre")
+        search_genre: Optional[str] = self.request.GET.get("genre")
         if search_genre:
             search_parameters.append(f"genre={search_genre}")
-        search_cantus_id = self.request.GET.get("cantus_id")
+        search_cantus_id: Optional[str] = self.request.GET.get("cantus_id")
         if search_cantus_id:
             search_parameters.append(f"cantus_id={search_cantus_id}")
-        search_mode = self.request.GET.get("mode")
+        search_mode: Optional[str] = self.request.GET.get("mode")
         if search_mode:
             search_parameters.append(f"mode={search_mode}")
-        search_feast = self.request.GET.get("feast")
+        search_feast: Optional[str] = self.request.GET.get("feast")
         if search_feast:
             search_parameters.append(f"feast={search_feast}")
-        search_position = self.request.GET.get("position")
+        search_position: Optional[str] = self.request.GET.get("position")
         if search_position:
             search_parameters.append(f"position={search_position}")
-        search_melodies = self.request.GET.get("melodies")
+        search_melodies: Optional[str] = self.request.GET.get("melodies")
         if search_melodies:
             search_parameters.append(f"melodies={search_melodies}")
+        search_bar: Optional[str] = self.request.GET.get("search_bar")
+        if search_bar:
+            search_parameters.append(f"search_bar={search_bar}")
 
+        url_with_search_params: str = current_url + "?"
         if search_parameters:
-            joined_search_parameters = "&".join(search_parameters)
-            url_with_search_params = current_url + "?" + joined_search_parameters
-        else:
-            url_with_search_params = current_url + "?"
+            joined_search_parameters: str = "&".join(search_parameters)
+            url_with_search_params += joined_search_parameters
 
         context["url_with_search_params"] = url_with_search_params
 
@@ -771,6 +773,7 @@ def get_queryset(self) -> QuerySet:
                     *CHANT_SEARCH_TEMPLATE_VALUES
                 )
                 queryset = chant_set.union(sequence_set, all=True)
+            queryset = queryset.order_by("source__siglum", "id")
 
         else:
             # The field names should be keys in the "GET" QueryDict if the search button has been clicked,


Test patch: