Repository: carpentries/amy

Issue:
WRF Website Slug Validation
Can we add a validation message to the URL field of the self-organised notification form?

We already have the suggested format in the help text, so we are wondering if we could add a notification type validation message that could prompt correction if AMY will reject the workshop slug.

**Context**: AMY's slug field includes validation that prevents us from entering events that include underscores in the first 11 characters. For example, 2020-12-15-SITE_LESSON  is an accepted slug but 2020-12-15_SITE_LESSON or 2020_12_15-SITE_LESSON are not. That is okay. 

**Situation**: We currently follow-up on the workshop slug after the form has been submitted and we are hoping to add a validation warning so that those who can change the slug are notified that the slug might need to be changed sooner.

**Request**: For user.github.io links entered into the URL field that do not meet AMY validation for the slug field. Please add a notice that reads: Would you be able to update the slug of the workshop webpage prior to submitting this notification? If so, we recommend using the following slug: YEAR-MM-DD-site-online. If not, that's okay and please feel free to submit the form.

**Request 2**: For user.github.io links entered into the URL field in the repo format github.com/username/slug . Please add a notice that reads: Please adjust the URL format so that it points to the workshop website. The format for this is username.github.io/slug.

**Priority**: Not Urgent. We currently have a manual workaround for the workflows affected by this validation issue.


Discussion:
@maneesha  - please feel free to adjust the wording of the notifications as needed.
This looks good to me.
@Talishask which form do you mean in request 1, and which in request 2?
Hey @pbanaszkiewicz - This is all in reference to the self-organised form.

Resolving patch:
diff --git a/amy/extrequests/forms.py b/amy/extrequests/forms.py
--- a/amy/extrequests/forms.py
+++ b/amy/extrequests/forms.py
@@ -1119,6 +1119,9 @@ class Meta:
             "additional_contact": Select2TagWidget,
         }
 
+    class Media:
+        js = ("selforganisedsubmission_form.js",)
+
     @staticmethod
     def institution_label_from_instance(obj):
         """Static method that overrides ModelChoiceField choice labels,
@@ -1175,6 +1178,41 @@ def __init__(self, *args, **kwargs):
                 HTML(self.helper.hr()),
             )
 
+        # add warning alert for workshop URL
+        REPO_WARNING = (
+            "Would you be able to update the name of the workshop webpage prior to "
+            "submitting this notification? If so, we recommend using the following "
+            "name: YEAR-MM-DD-site-online. If not, that's okay and please feel free "
+            "to submit the form."
+        )
+        URL_WARNING = (
+            "Please adjust the URL format so that it points to the workshop website. "
+            "The format for this is: https://username.github.io/repo"
+        )
+        pos_index = self.helper.layout.fields.index("workshop_url")
+        self.helper.layout.insert(
+            pos_index + 1,
+            Div(
+                Div(
+                    HTML(REPO_WARNING),
+                    css_class="alert alert-warning offset-lg-2 col-lg-8 col-12",
+                ),
+                id="workshop_url_repo_warning",
+                css_class="form-group row d-none",
+            ),
+        )
+        self.helper.layout.insert(
+            pos_index + 2,
+            Div(
+                Div(
+                    HTML(URL_WARNING),
+                    css_class="alert alert-warning offset-lg-2 col-lg-8 col-12",
+                ),
+                id="workshop_url_warning",
+                css_class="form-group row d-none",
+            ),
+        )
+
     def clean(self):
         super().clean()
         errors = dict()


Test patch: