Repository: DDMAL/CantusDB

Issue:
Suggested Full Text for chants without specified full text
In OldCantus, there were several manuscripts which had been indexed but not transcribed. For these chants, the `Manuscript Reading Full Text (Standardized Spelling)` field was empty (someone had previously gone through and created the chants, specifying only the chants' cantusIDs and some of the smaller fields (feast, genre, and so on), without filling in the text). But if you were working through the manuscript as a transcriber, **whenever you began to edit a chant without a specified Full Text on the `edit-volpiano` page, the website would offer a suggested text, based on other chants with the same cantusID.**

The feature was useful because it allowed me to make small changes to a text (all chants with a given cantusID have similar if not identical texts) rather than having to type it out anew.

We may want to implement this in NewCantus. If a user tried to edit a chant with an empty fulltext field, we would search through the rest of the database for chants sharing a cantusID and choose one of them to provide as an initial value of the Standardized Spelling field. (it would be well worth checking with an expert on this, but) We should probably search first for chants that have been proofread and choose the chant among them with the longest text. If there are no proofread chants with the same cantusID, we should search for any chant, proofread or not, and fetch the one with the longest text. Or should we just fetch the canonical text of the chant from CantusIndex (this is what CI is for, correct?)?

It's worth noting that I haven't been able to replicate this behavior in OldCantus in the last few minutes - when I try to create a new chant in the test source, I cannot _not_ specify a Standardized Spelling fulltext, so I can't create a chant with no text and edit it on the `edit-volpiano` page. Some of the chants in https://cantus.uwaterloo.ca/source/123658 have no fulltext, but I don't have proofreader access to that manuscript, so I can only access https://cantus.uwaterloo.ca/node/437192/edit; the described feature is only implemented in `edit-volpiano`. (It seems that chants without fulltext come from old indices that included only incipits, created before CantusDB existed and later imported into the database).


Discussion:

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
@@ -1145,13 +1145,25 @@ def get_chants_with_folios(chants_in_feast):
             # ordered by sequence number
             context["folios_current_feast"] = get_chants_with_folios(self.queryset)
 
-        # this boolean let's us decide whether to show the user the instructions or the editing form
+        # this boolean lets us decide whether to show the user the instructions or the editing form
         # if the pk hasn't been specified, a user hasn't selected a specific chant they want to edit
         # if so, we should display the instructions
-        if not self.request.GET.get("pk"):
-            context["pk_specified"] = False
-        else:
-            context["pk_specified"] = True
+        pk = self.request.GET.get("pk")
+        pk_specified = bool(pk)
+        context["pk_specified"] = pk_specified
+
+        # provide a suggested_fulltext for situations in which a chant has no
+        # manuscript_full_text_std_spelling
+        context["suggested_fulltext"] = ""
+        if pk_specified:
+            current_chant = Chant.objects.filter(pk=pk).first()
+            cantus_id = current_chant.cantus_id
+
+            request = requests.get(
+                    "http://cantusindex.org/json-cid/{}".format(cantus_id)
+            )
+            context["suggested_fulltext"] = json.loads(request.text[2:])[0]["fulltext"]
+
         return context
     
     def form_valid(self, form):


Test patch: