Repository: DDMAL/CantusDB

Issue:
need to implement sequence edit page



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
@@ -1,6 +1,6 @@
 from django import forms
 
-from .models import Chant, Office, Genre, Feast, Source, RismSiglum, Provenance, Century, Indexer
+from .models import Chant, Office, Genre, Feast, Source, RismSiglum, Provenance, Century, Indexer, Sequence
 from .widgets import (TextInputWidget,
                 VolpianoInputWidget,
                 TextAreaWidget,
@@ -361,3 +361,53 @@ class Meta:
         choices=CHOICES_COMPLETE_INV, required=False
     )
     complete_inventory.widget.attrs.update({"class": "form-control custom-select custom-select-sm"}) # what does this do?
+
+class SequenceEditForm(forms.ModelForm):
+    class Meta:
+        model = Sequence
+        fields = [
+            "title",
+            "siglum",
+            "incipit",
+            "folio",
+            "sequence",
+            "genre",
+            "rubrics",
+            "analecta_hymnica",
+            "indexing_notes",
+            "date",
+            "col1",
+            "col2",
+            "col3",
+            "ah_volume",
+            "source",
+            "cantus_id",
+            "image_link",
+        ]
+        widgets = {
+            "title": TextInputWidget(),
+            "siglum": TextInputWidget(),
+            "incipit": TextInputWidget(),
+            "folio": TextInputWidget(),
+            "sequence": TextInputWidget(),
+            "rubrics": TextInputWidget(),
+            "analecta_hymnica": TextInputWidget(),
+            "indexing_notes": TextAreaWidget(),
+            "date": TextInputWidget(),
+            "col1": TextInputWidget(),
+            "col2": TextInputWidget(),
+            "col3": TextInputWidget(),
+            "ah_volume": TextInputWidget(),
+            "cantus_id": TextInputWidget(),
+            "image_link": TextInputWidget(),
+        }
+    
+    genre = forms.ModelChoiceField(
+        queryset=Genre.objects.all().order_by("name"), required=False
+    )
+    genre.widget.attrs.update({"class": "form-control custom-select custom-select-sm"})
+    
+    source = forms.ModelChoiceField(
+        queryset=Source.objects.all().order_by("title"), required = False
+    )
+    source.widget.attrs.update({"class": "form-control custom-select custom-select-sm"})
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
@@ -1,6 +1,7 @@
 from django.urls import path, include
 from main_app.views import *
 from main_app.views import views
+from main_app.views.sequence import SequenceEditView
 from main_app.views.source import SourceCreateView, SourceEditView
 from main_app.views.chant import ChantEditVolpianoView
 from django.contrib.auth import views as auth_views
@@ -48,6 +49,7 @@
     # sequence
     path("sequences/", SequenceListView.as_view(), name="sequence-list"),
     path("sequence/<int:pk>", SequenceDetailView.as_view(), name="sequence-detail",),
+    path("edit-sequence/<int:sequence_id>", SequenceEditView.as_view(), name="sequence-edit",),
     # source
     path("sources/", SourceListView.as_view(), name="source-list"),
     path("source/<int:pk>", SourceDetailView.as_view(), name="source-detail"),
diff --git a/django/cantusdb_project/main_app/views/sequence.py b/django/cantusdb_project/main_app/views/sequence.py
--- a/django/cantusdb_project/main_app/views/sequence.py
+++ b/django/cantusdb_project/main_app/views/sequence.py
@@ -1,6 +1,9 @@
-from django.views.generic import DetailView, ListView
+from django.views.generic import DetailView, ListView, UpdateView
 from main_app.models import Sequence
 from django.db.models import Q
+from main_app.forms import SequenceEditForm
+from django.contrib.auth.mixins import LoginRequiredMixin
+from django.contrib import messages
 
 
 class SequenceDetailView(DetailView):
@@ -46,3 +49,16 @@ def get_queryset(self):
             q_obj_filter &= Q(cantus_id__icontains=cantus_id)
 
         return queryset.filter(q_obj_filter).order_by("siglum", "sequence")
+
+class SequenceEditView(LoginRequiredMixin, UpdateView):
+    template_name = "sequence_edit.html"
+    model = Sequence
+    form_class = SequenceEditForm
+    pk_url_kwarg = "sequence_id"
+
+    def form_valid(self, form):
+        messages.success(
+            self.request,
+            "Sequence updated successfully!",
+        )
+        return super().form_valid(form)


Test patch: