Repository: DDMAL/CantusDB

Issue:
Redirect user to source detail page after they create a source
As mentioned in Kathleen's email with feedback on our production and staging severs.

When a source or chant is created, we display a success message but with an empty form still on the source/chant create page. This is confusing to users because it looks like none of the data saved into their source. Instead, we should redirect them back to the source/chant detail page after they save. A similar issue has been addressed here (#665) from the chant edit page, so we need a similar functionality on the source and chant create pages


Discussion:

Resolving patch:
diff --git a/django/cantusdb_project/main_app/views/source.py b/django/cantusdb_project/main_app/views/source.py
--- a/django/cantusdb_project/main_app/views/source.py
+++ b/django/cantusdb_project/main_app/views/source.py
@@ -191,35 +191,56 @@ def test_func(self):
             return False
 
     def get_success_url(self):
-        return reverse("source-create")
+        return reverse("source-detail", args=[self.object.id])
 
     def form_valid(self, form):
         form.instance.created_by = self.request.user
-        source = form.save()
+        self.object = form.save()
 
         # assign this source to the "current_editors"
-        current_editors = source.current_editors.all()
-        self.request.user.sources_user_can_edit.add(source)
+        current_editors = self.object.current_editors.all()
+        self.request.user.sources_user_can_edit.add(self.object)
 
         for editor in current_editors:
-            editor.sources_user_can_edit.add(source)
+            editor.sources_user_can_edit.add(self.object)
 
         messages.success(
             self.request,
             "Source created successfully!",
         )
-
         return HttpResponseRedirect(self.get_success_url())
 
 
-class SourceEditView(
-    LoginRequiredMixin, UserPassesTestMixin, UpdateView, SourceDetailView
-):
+class SourceEditView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
     template_name = "source_edit.html"
     model = Source
     form_class = SourceEditForm
     pk_url_kwarg = "source_id"
 
+    def get_context_data(self, **kwargs):
+        source = self.get_object()
+        context = super().get_context_data(**kwargs)
+
+        if source.segment and source.segment.id == 4064:
+            # if this is a sequence source
+            context["sequences"] = source.sequence_set.order_by("s_sequence")
+            context["folios"] = (
+                source.sequence_set.values_list("folio", flat=True)
+                .distinct()
+                .order_by("folio")
+            )
+        else:
+            # if this is a chant source
+            folios = (
+                source.chant_set.values_list("folio", flat=True)
+                .distinct()
+                .order_by("folio")
+            )
+            context["folios"] = folios
+            # the options for the feast selector on the right, only chant sources have this
+            context["feasts_with_folios"] = get_feast_selector_options(source, folios)
+        return context
+
     def test_func(self):
         user = self.request.user
         source_id = self.kwargs.get(self.pk_url_kwarg)


Test patch: