Repository: mdn/kuma

Issue:
T - Add username to "Keep my attribution for my page changes"
When a user chooses to delete their account we have two scenarios:

1. The user has no contributions
2. The user has at least one

For the second case we show two radio buttons with the following text:

- Keep my attribution for my page changes
- Switch my attribution for my page changes to "Anonymous"

Originally it was designed that the first option should also include the user's username, for example:

- Keep my attribution for my page changes(pietpompies)

The strings used for this are defined inside the following Python file:
https://github.com/mdn/kuma/blob/master/kuma/users/forms.py#L211

In this context we have no idea what the username is. To remedy this, we need to update the following Jinja:

https://github.com/mdn/kuma/blob/master/kuma/users/jinja2/users/includes/delete-user-content.html#L13

To not use the shorthand for including all the form field but, explicitly code the fields. In this way, we can have something like(pseudo-code) for the first option field:

```
{{ form.label_for form.username.value() }}
```



Discussion:

Resolving patch:
diff --git a/kuma/users/forms.py b/kuma/users/forms.py
--- a/kuma/users/forms.py
+++ b/kuma/users/forms.py
@@ -204,17 +204,17 @@ def save(self, request):
 
 
 class UserDeleteForm(forms.Form):
+    def __init__(self, *args, username, **kwargs):
+        super().__init__(*args, **kwargs)
 
-    ATTRIBUTIONS_KEEP = "keep"
-    ATTRIBUTIONS_DONATE = "donate"
-    ATTRIBUTIONS_CHOICES = (
-        (ATTRIBUTIONS_KEEP, _("Keep my attribution for my page changes")),
-        (
-            ATTRIBUTIONS_DONATE,
-            _('Switch my attribution for my page changes to "Anonymous"'),
-        ),
-    )
+        choices = {
+            "keep": (
+                _("Keep my attribution for my page changes (%(username)s)")
+                % {"username": username}
+            ),
+            "donate": _('Switch my attribution for my page changes to "Anonymous"'),
+        }
 
-    attributions = forms.ChoiceField(
-        required=True, choices=ATTRIBUTIONS_CHOICES, widget=forms.widgets.RadioSelect()
-    )
+        self.fields["attributions"].choices = choices.items()
+
+    attributions = forms.ChoiceField(required=True, widget=forms.widgets.RadioSelect())
diff --git a/kuma/users/views.py b/kuma/users/views.py
--- a/kuma/users/views.py
+++ b/kuma/users/views.py
@@ -470,7 +470,7 @@ def user_edit(request, username):
         "edit_user": edit_user,
         "user_form": user_form,
         "username": user_form["username"].value(),
-        "form": UserDeleteForm(),
+        "form": UserDeleteForm(username=username),
         "revisions": revisions,
         "attachment_revisions": attachment_revisions,
         "subscription_info": retrieve_stripe_subscription_info(edit_user,),
@@ -548,7 +548,7 @@ def delete_user():
     if request.method == "POST":
         # If the user has no revisions there's not choices on the form.
         if revisions.exists() or attachment_revisions.exists():
-            form = UserDeleteForm(request.POST)
+            form = UserDeleteForm(request.POST, username=username)
             if form.is_valid():
                 if form.cleaned_data["attributions"] == "donate":
                     donate_attributions()
@@ -564,7 +564,7 @@ def delete_user():
             delete_user()
             return HttpResponseRedirect("/")
     else:
-        form = UserDeleteForm()
+        form = UserDeleteForm(username=username)
 
     context["form"] = form
     context["username"] = username


Test patch: