prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Fix translations in group edit & create form
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `user_management/forms.py`
  Content:
  ```
  1 from django import forms
  2 from django.contrib.auth.forms import ReadOnlyPasswordHashField
  3 from django.contrib.auth.models import Group
  4 from django.contrib.auth.password_validation import validate_password
  5 from django.forms import (
  6     ModelForm,
  7     ModelMultipleChoiceField,
  8     BooleanField,
  9     SelectMultiple,
  10     DateField,
  11 )
  12 from django_select2.forms import Select2MultipleWidget
  13 from guardian.shortcuts import assign_perm, remove_perm
  14 
  15 from jep.widgets import CustomDateInput
  16 from user_management.models import UserProfile
  17 from django.utils.translation import gettext as _
  18 
  19 from user_management.widgets import MultiUserProfileWidget
  20 
  21 
  22 class UserCreationForm(forms.ModelForm):
  23     """A form for creating new users. Includes all the required
  24     fields, plus a repeated password."""
  25 
  26     password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
  27     password_validation = forms.CharField(
  28         label=_("Password confirmation"), widget=forms.PasswordInput
  29     )
  30     field_order = ["email", "password", "password_validation"]
  31 
  32     class Meta:
  33         model = UserProfile
  34         fields = (
  35             "email",
  36             "first_name",
  37             "last_name",
  38             "date_of_birth",
  39             "phone",
  40         )
  41 
  42     def clean_password_validation(self):
  43         # Check that the two password entries match
  44         password = self.cleaned_data.get("password")
  45         password_validation = self.cleaned_data.get("password_validation")
  46         if password and password_validation and password != password_validation:
  47             raise forms.ValidationError(_("Passwords don't match"))
  48         return password_validation
  49 
  50     def _post_clean(self):
  51         super()._post_clean()
  52         # Validate the password after self.instance is updated with form data
  53         # by super().
  54         password = self.cleaned_data.get("password_validation")
  55         if password:
  56             try:
  57                 validate_password(password, self.instance)
  58             except forms.ValidationError as error:
  59                 self.add_error("password", error)
  60 
  61     def save(self, commit=True):
  62         # Save the provided password in hashed format
  63         user = super().save(commit=False)
  64         user.set_password(self.cleaned_data["password"])
  65         if commit:
  66             user.save()
  67         return user
  68 
  69 
  70 class UserChangeForm(forms.ModelForm):
  71     """A form for updating users. Includes all the fields on
  72     the user, but replaces the password field with admin's
  73     password hash display field.
  74     """
  75 
  76     password = ReadOnlyPasswordHashField()
  77 
  78     class Meta:
  79         model = UserProfile
  80         fields = (
  81             "email",
  82             "password",
  83             "first_name",
  84             "last_name",
  85             "date_of_birth",
  86             "phone",
  87             "is_active",
  88             "is_staff",
  89         )
  90 
  91     def clean_password(self):
  92         # Regardless of what the user provides, return the initial value.
  93         # This is done here, rather than on the field, because the
  94         # field does not have access to the initial value
  95         return self.initial["password"]
  96 
  97 
  98 class GroupForm(ModelForm):
  99     publish_event_for_group = ModelMultipleChoiceField(
  100         queryset=Group.objects.all(),
  101         required=False,
  102         help_text=_("Choose groups that this group can make events visible for."),
  103         widget=Select2MultipleWidget,
  104     )
  105     can_view_past_event = BooleanField(required=False, label=_("Can view past events"))
  106     can_add_event = BooleanField(required=False)
  107     users = ModelMultipleChoiceField(
  108         queryset=UserProfile.objects.all(), widget=MultiUserProfileWidget
  109     )
  110 
  111     field_order = [
  112         "name",
  113         "users",
  114         "can_view_past_event",
  115         "can_add_event",
  116         "publish_event_for_group",
  117     ]
  118 
  119     class Meta:
  120         model = Group
  121         fields = ["name"]
  122 
  123     def save(self, commit=True):
  124         group = super().save(commit)
  125 
  126         group.user_set.set(self.cleaned_data["users"])
  127 
  128         if self.cleaned_data["can_view_past_event"]:
  129             assign_perm("event_management.view_past_event", group)
  130         else:
  131             remove_perm("event_management.view_past_event", group)
  132 
  133         if self.cleaned_data["can_add_event"]:
  134             assign_perm("event_management.add_event", group)
  135             assign_perm("event_management.delete_event", group)
  136 
  137             if "publish_event_for_group" in self.changed_data:
  138                 for target_group in self.cleaned_data["publish_event_for_group"].difference(
  139                     self.initial["publish_event_for_group"]
  140                 ):
  141                     assign_perm("publish_event_for_group", group, target_group)
  142                 for target_group in self.initial["publish_event_for_group"].difference(
  143                     self.cleaned_data["publish_event_for_group"]
  144                 ):
  145                     remove_perm("publish_event_for_group", group, target_group)
  146         else:
  147             remove_perm("event_management.add_event", group)
  148             remove_perm("event_management.delete_event", group)
  149             for target_group in Group.objects.all():
  150                 remove_perm("publish_event_for_group", group, target_group)
  151 
  152 
  153 class UserProfileForm(ModelForm):
  154     groups = ModelMultipleChoiceField(
  155         label=_("Groups"), queryset=Group.objects.all(), widget=Select2MultipleWidget
  156     )
  157 
  158     field_order = [
  159         "email",
  160         "first_name",
  161         "last_name",
  162         "date_of_birth",
  163         "phone",
  164         "groups",
  165         "is_active",
  166     ]
  167 
  168     class Meta:
  169         model = UserProfile
  170         fields = ["email", "first_name", "last_name", "date_of_birth", "phone", "is_active"]
  171         widgets = {"date_of_birth": CustomDateInput(format="%Y-%m-%d")}
  172         help_texts = {
  173             "is_active": _("Inactive users cannot log in and do not get any notifications.")
  174         }
  175         labels = {"is_active": _("Active user")}
  176 
  177     def save(self, commit=True):
  178         userprofile = super().save(commit)
  179         userprofile.groups.set(self.cleaned_data["groups"])
  180         userprofile.save()
  181         return userprofile
  182
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/user_management/forms.py b/user_management/forms.py
  --- a/user_management/forms.py
  +++ b/user_management/forms.py
  @@ -97,15 +97,16 @@
   
   class GroupForm(ModelForm):
       publish_event_for_group = ModelMultipleChoiceField(
  +        label=_("Can publish event for group"),
           queryset=Group.objects.all(),
           required=False,
           help_text=_("Choose groups that this group can make events visible for."),
           widget=Select2MultipleWidget,
       )
  -    can_view_past_event = BooleanField(required=False, label=_("Can view past events"))
  -    can_add_event = BooleanField(required=False)
  +    can_view_past_event = BooleanField(label=_("Can view past events"), required=False)
  +    can_add_event = BooleanField(label=_("Can add event"), required=False)
       users = ModelMultipleChoiceField(
  -        queryset=UserProfile.objects.all(), widget=MultiUserProfileWidget
  +        label=_("Users"), queryset=UserProfile.objects.all(), widget=MultiUserProfileWidget
       )
   
       field_order = [
  
verification_info: {"golden_diff": "diff --git a/user_management/forms.py b/user_management/forms.py\n--- a/user_management/forms.py\n+++ b/user_management/forms.py\n@@ -97,15 +97,16 @@\n \n class GroupForm(ModelForm):\n     publish_event_for_group = ModelMultipleChoiceField(\n+        label=_(\"Can publish event for group\"),\n         queryset=Group.objects.all(),\n         required=False,\n         help_text=_(\"Choose groups that this group can make events visible for.\"),\n         widget=Select2MultipleWidget,\n     )\n-    can_view_past_event = BooleanField(required=False, label=_(\"Can view past events\"))\n-    can_add_event = BooleanField(required=False)\n+    can_view_past_event = BooleanField(label=_(\"Can view past events\"), required=False)\n+    can_add_event = BooleanField(label=_(\"Can add event\"), required=False)\n     users = ModelMultipleChoiceField(\n-        queryset=UserProfile.objects.all(), widget=MultiUserProfileWidget\n+        label=_(\"Users\"), queryset=UserProfile.objects.all(), widget=MultiUserProfileWidget\n     )\n \n     field_order = [\n", "issue": "Fix translations in group edit & create form\n\n", "before_files": [{"content": "from django import forms\nfrom django.contrib.auth.forms import ReadOnlyPasswordHashField\nfrom django.contrib.auth.models import Group\nfrom django.contrib.auth.password_validation import validate_password\nfrom django.forms import (\n    ModelForm,\n    ModelMultipleChoiceField,\n    BooleanField,\n    SelectMultiple,\n    DateField,\n)\nfrom django_select2.forms import Select2MultipleWidget\nfrom guardian.shortcuts import assign_perm, remove_perm\n\nfrom jep.widgets import CustomDateInput\nfrom user_management.models import UserProfile\nfrom django.utils.translation import gettext as _\n\nfrom user_management.widgets import MultiUserProfileWidget\n\n\nclass UserCreationForm(forms.ModelForm):\n    \"\"\"A form for creating new users. Includes all the required\n    fields, plus a repeated password.\"\"\"\n\n    password = forms.CharField(label=_(\"Password\"), widget=forms.PasswordInput)\n    password_validation = forms.CharField(\n        label=_(\"Password confirmation\"), widget=forms.PasswordInput\n    )\n    field_order = [\"email\", \"password\", \"password_validation\"]\n\n    class Meta:\n        model = UserProfile\n        fields = (\n            \"email\",\n            \"first_name\",\n            \"last_name\",\n            \"date_of_birth\",\n            \"phone\",\n        )\n\n    def clean_password_validation(self):\n        # Check that the two password entries match\n        password = self.cleaned_data.get(\"password\")\n        password_validation = self.cleaned_data.get(\"password_validation\")\n        if password and password_validation and password != password_validation:\n            raise forms.ValidationError(_(\"Passwords don't match\"))\n        return password_validation\n\n    def _post_clean(self):\n        super()._post_clean()\n        # Validate the password after self.instance is updated with form data\n        # by super().\n        password = self.cleaned_data.get(\"password_validation\")\n        if password:\n            try:\n                validate_password(password, self.instance)\n            except forms.ValidationError as error:\n                self.add_error(\"password\", error)\n\n    def save(self, commit=True):\n        # Save the provided password in hashed format\n        user = super().save(commit=False)\n        user.set_password(self.cleaned_data[\"password\"])\n        if commit:\n            user.save()\n        return user\n\n\nclass UserChangeForm(forms.ModelForm):\n    \"\"\"A form for updating users. Includes all the fields on\n    the user, but replaces the password field with admin's\n    password hash display field.\n    \"\"\"\n\n    password = ReadOnlyPasswordHashField()\n\n    class Meta:\n        model = UserProfile\n        fields = (\n            \"email\",\n            \"password\",\n            \"first_name\",\n            \"last_name\",\n            \"date_of_birth\",\n            \"phone\",\n            \"is_active\",\n            \"is_staff\",\n        )\n\n    def clean_password(self):\n        # Regardless of what the user provides, return the initial value.\n        # This is done here, rather than on the field, because the\n        # field does not have access to the initial value\n        return self.initial[\"password\"]\n\n\nclass GroupForm(ModelForm):\n    publish_event_for_group = ModelMultipleChoiceField(\n        queryset=Group.objects.all(),\n        required=False,\n        help_text=_(\"Choose groups that this group can make events visible for.\"),\n        widget=Select2MultipleWidget,\n    )\n    can_view_past_event = BooleanField(required=False, label=_(\"Can view past events\"))\n    can_add_event = BooleanField(required=False)\n    users = ModelMultipleChoiceField(\n        queryset=UserProfile.objects.all(), widget=MultiUserProfileWidget\n    )\n\n    field_order = [\n        \"name\",\n        \"users\",\n        \"can_view_past_event\",\n        \"can_add_event\",\n        \"publish_event_for_group\",\n    ]\n\n    class Meta:\n        model = Group\n        fields = [\"name\"]\n\n    def save(self, commit=True):\n        group = super().save(commit)\n\n        group.user_set.set(self.cleaned_data[\"users\"])\n\n        if self.cleaned_data[\"can_view_past_event\"]:\n            assign_perm(\"event_management.view_past_event\", group)\n        else:\n            remove_perm(\"event_management.view_past_event\", group)\n\n        if self.cleaned_data[\"can_add_event\"]:\n            assign_perm(\"event_management.add_event\", group)\n            assign_perm(\"event_management.delete_event\", group)\n\n            if \"publish_event_for_group\" in self.changed_data:\n                for target_group in self.cleaned_data[\"publish_event_for_group\"].difference(\n                    self.initial[\"publish_event_for_group\"]\n                ):\n                    assign_perm(\"publish_event_for_group\", group, target_group)\n                for target_group in self.initial[\"publish_event_for_group\"].difference(\n                    self.cleaned_data[\"publish_event_for_group\"]\n                ):\n                    remove_perm(\"publish_event_for_group\", group, target_group)\n        else:\n            remove_perm(\"event_management.add_event\", group)\n            remove_perm(\"event_management.delete_event\", group)\n            for target_group in Group.objects.all():\n                remove_perm(\"publish_event_for_group\", group, target_group)\n\n\nclass UserProfileForm(ModelForm):\n    groups = ModelMultipleChoiceField(\n        label=_(\"Groups\"), queryset=Group.objects.all(), widget=Select2MultipleWidget\n    )\n\n    field_order = [\n        \"email\",\n        \"first_name\",\n        \"last_name\",\n        \"date_of_birth\",\n        \"phone\",\n        \"groups\",\n        \"is_active\",\n    ]\n\n    class Meta:\n        model = UserProfile\n        fields = [\"email\", \"first_name\", \"last_name\", \"date_of_birth\", \"phone\", \"is_active\"]\n        widgets = {\"date_of_birth\": CustomDateInput(format=\"%Y-%m-%d\")}\n        help_texts = {\n            \"is_active\": _(\"Inactive users cannot log in and do not get any notifications.\")\n        }\n        labels = {\"is_active\": _(\"Active user\")}\n\n    def save(self, commit=True):\n        userprofile = super().save(commit)\n        userprofile.groups.set(self.cleaned_data[\"groups\"])\n        userprofile.save()\n        return userprofile\n", "path": "user_management/forms.py"}], "after_files": [{"content": "from django import forms\nfrom django.contrib.auth.forms import ReadOnlyPasswordHashField\nfrom django.contrib.auth.models import Group\nfrom django.contrib.auth.password_validation import validate_password\nfrom django.forms import (\n    ModelForm,\n    ModelMultipleChoiceField,\n    BooleanField,\n    SelectMultiple,\n    DateField,\n)\nfrom django_select2.forms import Select2MultipleWidget\nfrom guardian.shortcuts import assign_perm, remove_perm\n\nfrom jep.widgets import CustomDateInput\nfrom user_management.models import UserProfile\nfrom django.utils.translation import gettext as _\n\nfrom user_management.widgets import MultiUserProfileWidget\n\n\nclass UserCreationForm(forms.ModelForm):\n    \"\"\"A form for creating new users. Includes all the required\n    fields, plus a repeated password.\"\"\"\n\n    password = forms.CharField(label=_(\"Password\"), widget=forms.PasswordInput)\n    password_validation = forms.CharField(\n        label=_(\"Password confirmation\"), widget=forms.PasswordInput\n    )\n    field_order = [\"email\", \"password\", \"password_validation\"]\n\n    class Meta:\n        model = UserProfile\n        fields = (\n            \"email\",\n            \"first_name\",\n            \"last_name\",\n            \"date_of_birth\",\n            \"phone\",\n        )\n\n    def clean_password_validation(self):\n        # Check that the two password entries match\n        password = self.cleaned_data.get(\"password\")\n        password_validation = self.cleaned_data.get(\"password_validation\")\n        if password and password_validation and password != password_validation:\n            raise forms.ValidationError(_(\"Passwords don't match\"))\n        return password_validation\n\n    def _post_clean(self):\n        super()._post_clean()\n        # Validate the password after self.instance is updated with form data\n        # by super().\n        password = self.cleaned_data.get(\"password_validation\")\n        if password:\n            try:\n                validate_password(password, self.instance)\n            except forms.ValidationError as error:\n                self.add_error(\"password\", error)\n\n    def save(self, commit=True):\n        # Save the provided password in hashed format\n        user = super().save(commit=False)\n        user.set_password(self.cleaned_data[\"password\"])\n        if commit:\n            user.save()\n        return user\n\n\nclass UserChangeForm(forms.ModelForm):\n    \"\"\"A form for updating users. Includes all the fields on\n    the user, but replaces the password field with admin's\n    password hash display field.\n    \"\"\"\n\n    password = ReadOnlyPasswordHashField()\n\n    class Meta:\n        model = UserProfile\n        fields = (\n            \"email\",\n            \"password\",\n            \"first_name\",\n            \"last_name\",\n            \"date_of_birth\",\n            \"phone\",\n            \"is_active\",\n            \"is_staff\",\n        )\n\n    def clean_password(self):\n        # Regardless of what the user provides, return the initial value.\n        # This is done here, rather than on the field, because the\n        # field does not have access to the initial value\n        return self.initial[\"password\"]\n\n\nclass GroupForm(ModelForm):\n    publish_event_for_group = ModelMultipleChoiceField(\n        label=_(\"Can publish event for group\"),\n        queryset=Group.objects.all(),\n        required=False,\n        help_text=_(\"Choose groups that this group can make events visible for.\"),\n        widget=Select2MultipleWidget,\n    )\n    can_view_past_event = BooleanField(label=_(\"Can view past events\"), required=False)\n    can_add_event = BooleanField(label=_(\"Can add event\"), required=False)\n    users = ModelMultipleChoiceField(\n        label=_(\"Users\"), queryset=UserProfile.objects.all(), widget=MultiUserProfileWidget\n    )\n\n    field_order = [\n        \"name\",\n        \"users\",\n        \"can_view_past_event\",\n        \"can_add_event\",\n        \"publish_event_for_group\",\n    ]\n\n    class Meta:\n        model = Group\n        fields = [\"name\"]\n\n    def save(self, commit=True):\n        group = super().save(commit)\n\n        group.user_set.set(self.cleaned_data[\"users\"])\n\n        if self.cleaned_data[\"can_view_past_event\"]:\n            assign_perm(\"event_management.view_past_event\", group)\n        else:\n            remove_perm(\"event_management.view_past_event\", group)\n\n        if self.cleaned_data[\"can_add_event\"]:\n            assign_perm(\"event_management.add_event\", group)\n            assign_perm(\"event_management.delete_event\", group)\n\n            if \"publish_event_for_group\" in self.changed_data:\n                for target_group in self.cleaned_data[\"publish_event_for_group\"].difference(\n                    self.initial[\"publish_event_for_group\"]\n                ):\n                    assign_perm(\"publish_event_for_group\", group, target_group)\n                for target_group in self.initial[\"publish_event_for_group\"].difference(\n                    self.cleaned_data[\"publish_event_for_group\"]\n                ):\n                    remove_perm(\"publish_event_for_group\", group, target_group)\n        else:\n            remove_perm(\"event_management.add_event\", group)\n            remove_perm(\"event_management.delete_event\", group)\n            for target_group in Group.objects.all():\n                remove_perm(\"publish_event_for_group\", group, target_group)\n\n\nclass UserProfileForm(ModelForm):\n    groups = ModelMultipleChoiceField(\n        label=_(\"Groups\"), queryset=Group.objects.all(), widget=Select2MultipleWidget\n    )\n\n    field_order = [\n        \"email\",\n        \"first_name\",\n        \"last_name\",\n        \"date_of_birth\",\n        \"phone\",\n        \"groups\",\n        \"is_active\",\n    ]\n\n    class Meta:\n        model = UserProfile\n        fields = [\"email\", \"first_name\", \"last_name\", \"date_of_birth\", \"phone\", \"is_active\"]\n        widgets = {\"date_of_birth\": CustomDateInput(format=\"%Y-%m-%d\")}\n        help_texts = {\n            \"is_active\": _(\"Inactive users cannot log in and do not get any notifications.\")\n        }\n        labels = {\"is_active\": _(\"Active user\")}\n\n    def save(self, commit=True):\n        userprofile = super().save(commit)\n        userprofile.groups.set(self.cleaned_data[\"groups\"])\n        userprofile.save()\n        return userprofile\n", "path": "user_management/forms.py"}]}