prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  TemplateDoesNotExist: account/email/account_already_exists.de.email, account/email/account_already_exists.en.email
  Sentry Issue: [MEINBERLIN-DEV-81](https://sentry.liqd.net/organizations/liqd/issues/2951/?referrer=github_integration)
  
  ```
  TemplateDoesNotExist: account/email/account_already_exists.de.email, account/email/account_already_exists.en.email
  (16 additional frame(s) were not displayed)
  ...
    File "meinberlin/apps/users/adapters.py", line 46, in send_mail
      return UserAccountEmail.send(email, template_name=template_prefix, **context)
    File "adhocracy4/emails/mixins.py", line 38, in send
      return cls().dispatch(object, *args, **kwargs)
    File "adhocracy4/emails/base.py", line 127, in dispatch
      (subject, text, html) = self.render(template, context)
    File "adhocracy4/emails/base.py", line 98, in render
      template = select_template(
    File "django/template/loader.py", line 47, in select_template
      raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `meinberlin/apps/users/forms.py`
  Content:
  ```
  1 import collections
  2 
  3 from allauth.account.forms import SignupForm
  4 from allauth.socialaccount.forms import SignupForm as SocialSignupForm
  5 from django import forms
  6 from django.contrib.auth import forms as auth_forms
  7 from django.core.exceptions import ValidationError
  8 from django.utils.translation import gettext_lazy as _
  9 from django.utils.translation import ngettext
  10 
  11 from meinberlin.apps.captcha.fields import CaptcheckCaptchaField
  12 from meinberlin.apps.organisations.models import Organisation
  13 from meinberlin.apps.users.models import User
  14 
  15 
  16 class UserAdminForm(auth_forms.UserChangeForm):
  17     def clean(self):
  18         groups = self.cleaned_data.get("groups")
  19         group_list = groups.values_list("id", flat=True)
  20         group_organisations = Organisation.objects.filter(
  21             groups__in=group_list
  22         ).values_list("name", flat=True)
  23         duplicates = [
  24             item
  25             for item, count in collections.Counter(group_organisations).items()
  26             if count > 1
  27         ]
  28         if duplicates:
  29             count = len(duplicates)
  30             message = ngettext(
  31                 "User is member in more than one group "
  32                 "in this organisation: %(duplicates)s.",
  33                 "User is member in more than one group "
  34                 "in these organisations: %(duplicates)s.",
  35                 count,
  36             ) % {"duplicates": ", ".join(duplicates)}
  37             raise ValidationError(message)
  38         return self.cleaned_data
  39 
  40     def clean_username(self):
  41 
  42         username = self.cleaned_data["username"]
  43         try:
  44             user = User.objects.get(username__iexact=username)
  45             if user != self.instance:
  46                 raise forms.ValidationError(
  47                     User._meta.get_field("username").error_messages["unique"]
  48                 )
  49         except User.DoesNotExist:
  50             pass
  51 
  52         try:
  53             user = User.objects.get(email__iexact=username)
  54             if user != self.instance:
  55                 raise forms.ValidationError(
  56                     User._meta.get_field("username").error_messages["used_as_email"]
  57                 )
  58         except User.DoesNotExist:
  59             pass
  60 
  61         return username
  62 
  63 
  64 class AddUserAdminForm(auth_forms.UserCreationForm):
  65     def clean_username(self):
  66 
  67         username = self.cleaned_data["username"]
  68         user = User.objects.filter(username__iexact=username)
  69         if user.exists():
  70             raise forms.ValidationError(
  71                 User._meta.get_field("username").error_messages["unique"]
  72             )
  73         else:
  74             user = User.objects.filter(email__iexact=username)
  75             if user.exists():
  76                 raise forms.ValidationError(
  77                     User._meta.get_field("username").error_messages["used_as_email"]
  78                 )
  79         return username
  80 
  81 
  82 class TermsSignupForm(SignupForm):
  83     terms_of_use = forms.BooleanField(label=_("Terms of use"))
  84     get_newsletters = forms.BooleanField(
  85         label=_("Newsletter"),
  86         help_text=_(
  87             "Yes, I would like to receive e-mail newsletters about "
  88             "the projects I am following."
  89         ),
  90         required=False,
  91     )
  92     get_notifications = forms.BooleanField(
  93         label=_("Notifications"),
  94         help_text=_(
  95             "Yes, I would like to be notified by e-mail about the "
  96             "start and end of participation opportunities. This "
  97             "applies to all projects I follow. I also receive an "
  98             "e-mail when someone comments on one of my "
  99             "contributions."
  100         ),
  101         required=False,
  102         initial=True,
  103     )
  104     captcha = CaptcheckCaptchaField(label=_("I am not a robot"))
  105 
  106     def __init__(self, *args, **kwargs):
  107         super().__init__(*args, **kwargs)
  108         self.fields["username"].help_text = _(
  109             "Your username will appear publicly next to your posts."
  110         )
  111         self.fields["email"].widget.attrs["autofocus"] = True
  112 
  113     def save(self, request):
  114         user = super(TermsSignupForm, self).save(request)
  115         user.get_newsletters = self.cleaned_data["get_newsletters"]
  116         user.get_notifications = self.cleaned_data["get_notifications"]
  117         user.save()
  118         return user
  119 
  120 
  121 class SocialTermsSignupForm(SocialSignupForm):
  122     terms_of_use = forms.BooleanField(label=_("Terms of use"))
  123     get_newsletters = forms.BooleanField(
  124         label=_("Newsletter"),
  125         help_text=_(
  126             "Yes, I would like to receive e-mail newsletters about "
  127             "the projects I am following."
  128         ),
  129         required=False,
  130     )
  131     get_notifications = forms.BooleanField(
  132         label=_("Notifications"),
  133         help_text=_(
  134             "Yes, I would like to be notified by e-mail about the "
  135             "start and end of participation opportunities. This "
  136             "applies to all projects I follow. I also receive an "
  137             "e-mail when someone comments on one of my "
  138             "contributions."
  139         ),
  140         required=False,
  141         initial=True,
  142     )
  143     email = forms.EmailField(widget=forms.HiddenInput())
  144 
  145     def __init__(self, *args, **kwargs):
  146         super().__init__(*args, **kwargs)
  147         self.fields["username"].help_text = _(
  148             "Your username will appear publicly next to your posts."
  149         )
  150 
  151     def save(self, request):
  152         user = super(SocialTermsSignupForm, self).save(request)
  153         user.get_newsletters = self.cleaned_data["get_newsletters"]
  154         user.get_notifications = self.cleaned_data["get_notifications"]
  155         user.save()
  156         return user
  157
  ```
  --- 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/meinberlin/apps/users/forms.py b/meinberlin/apps/users/forms.py
  --- a/meinberlin/apps/users/forms.py
  +++ b/meinberlin/apps/users/forms.py
  @@ -38,7 +38,6 @@
           return self.cleaned_data
   
       def clean_username(self):
  -
           username = self.cleaned_data["username"]
           try:
               user = User.objects.get(username__iexact=username)
  @@ -63,7 +62,6 @@
   
   class AddUserAdminForm(auth_forms.UserCreationForm):
       def clean_username(self):
  -
           username = self.cleaned_data["username"]
           user = User.objects.filter(username__iexact=username)
           if user.exists():
  @@ -112,10 +110,11 @@
   
       def save(self, request):
           user = super(TermsSignupForm, self).save(request)
  -        user.get_newsletters = self.cleaned_data["get_newsletters"]
  -        user.get_notifications = self.cleaned_data["get_notifications"]
  -        user.save()
  -        return user
  +        if user:
  +            user.get_newsletters = self.cleaned_data["get_newsletters"]
  +            user.get_notifications = self.cleaned_data["get_notifications"]
  +            user.save()
  +            return user
   
   
   class SocialTermsSignupForm(SocialSignupForm):
  
verification_info: {"golden_diff": "diff --git a/meinberlin/apps/users/forms.py b/meinberlin/apps/users/forms.py\n--- a/meinberlin/apps/users/forms.py\n+++ b/meinberlin/apps/users/forms.py\n@@ -38,7 +38,6 @@\n         return self.cleaned_data\n \n     def clean_username(self):\n-\n         username = self.cleaned_data[\"username\"]\n         try:\n             user = User.objects.get(username__iexact=username)\n@@ -63,7 +62,6 @@\n \n class AddUserAdminForm(auth_forms.UserCreationForm):\n     def clean_username(self):\n-\n         username = self.cleaned_data[\"username\"]\n         user = User.objects.filter(username__iexact=username)\n         if user.exists():\n@@ -112,10 +110,11 @@\n \n     def save(self, request):\n         user = super(TermsSignupForm, self).save(request)\n-        user.get_newsletters = self.cleaned_data[\"get_newsletters\"]\n-        user.get_notifications = self.cleaned_data[\"get_notifications\"]\n-        user.save()\n-        return user\n+        if user:\n+            user.get_newsletters = self.cleaned_data[\"get_newsletters\"]\n+            user.get_notifications = self.cleaned_data[\"get_notifications\"]\n+            user.save()\n+            return user\n \n \n class SocialTermsSignupForm(SocialSignupForm):\n", "issue": "TemplateDoesNotExist: account/email/account_already_exists.de.email, account/email/account_already_exists.en.email\nSentry Issue: [MEINBERLIN-DEV-81](https://sentry.liqd.net/organizations/liqd/issues/2951/?referrer=github_integration)\n\n```\nTemplateDoesNotExist: account/email/account_already_exists.de.email, account/email/account_already_exists.en.email\n(16 additional frame(s) were not displayed)\n...\n  File \"meinberlin/apps/users/adapters.py\", line 46, in send_mail\n    return UserAccountEmail.send(email, template_name=template_prefix, **context)\n  File \"adhocracy4/emails/mixins.py\", line 38, in send\n    return cls().dispatch(object, *args, **kwargs)\n  File \"adhocracy4/emails/base.py\", line 127, in dispatch\n    (subject, text, html) = self.render(template, context)\n  File \"adhocracy4/emails/base.py\", line 98, in render\n    template = select_template(\n  File \"django/template/loader.py\", line 47, in select_template\n    raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)\n```\n", "before_files": [{"content": "import collections\n\nfrom allauth.account.forms import SignupForm\nfrom allauth.socialaccount.forms import SignupForm as SocialSignupForm\nfrom django import forms\nfrom django.contrib.auth import forms as auth_forms\nfrom django.core.exceptions import ValidationError\nfrom django.utils.translation import gettext_lazy as _\nfrom django.utils.translation import ngettext\n\nfrom meinberlin.apps.captcha.fields import CaptcheckCaptchaField\nfrom meinberlin.apps.organisations.models import Organisation\nfrom meinberlin.apps.users.models import User\n\n\nclass UserAdminForm(auth_forms.UserChangeForm):\n    def clean(self):\n        groups = self.cleaned_data.get(\"groups\")\n        group_list = groups.values_list(\"id\", flat=True)\n        group_organisations = Organisation.objects.filter(\n            groups__in=group_list\n        ).values_list(\"name\", flat=True)\n        duplicates = [\n            item\n            for item, count in collections.Counter(group_organisations).items()\n            if count > 1\n        ]\n        if duplicates:\n            count = len(duplicates)\n            message = ngettext(\n                \"User is member in more than one group \"\n                \"in this organisation: %(duplicates)s.\",\n                \"User is member in more than one group \"\n                \"in these organisations: %(duplicates)s.\",\n                count,\n            ) % {\"duplicates\": \", \".join(duplicates)}\n            raise ValidationError(message)\n        return self.cleaned_data\n\n    def clean_username(self):\n\n        username = self.cleaned_data[\"username\"]\n        try:\n            user = User.objects.get(username__iexact=username)\n            if user != self.instance:\n                raise forms.ValidationError(\n                    User._meta.get_field(\"username\").error_messages[\"unique\"]\n                )\n        except User.DoesNotExist:\n            pass\n\n        try:\n            user = User.objects.get(email__iexact=username)\n            if user != self.instance:\n                raise forms.ValidationError(\n                    User._meta.get_field(\"username\").error_messages[\"used_as_email\"]\n                )\n        except User.DoesNotExist:\n            pass\n\n        return username\n\n\nclass AddUserAdminForm(auth_forms.UserCreationForm):\n    def clean_username(self):\n\n        username = self.cleaned_data[\"username\"]\n        user = User.objects.filter(username__iexact=username)\n        if user.exists():\n            raise forms.ValidationError(\n                User._meta.get_field(\"username\").error_messages[\"unique\"]\n            )\n        else:\n            user = User.objects.filter(email__iexact=username)\n            if user.exists():\n                raise forms.ValidationError(\n                    User._meta.get_field(\"username\").error_messages[\"used_as_email\"]\n                )\n        return username\n\n\nclass TermsSignupForm(SignupForm):\n    terms_of_use = forms.BooleanField(label=_(\"Terms of use\"))\n    get_newsletters = forms.BooleanField(\n        label=_(\"Newsletter\"),\n        help_text=_(\n            \"Yes, I would like to receive e-mail newsletters about \"\n            \"the projects I am following.\"\n        ),\n        required=False,\n    )\n    get_notifications = forms.BooleanField(\n        label=_(\"Notifications\"),\n        help_text=_(\n            \"Yes, I would like to be notified by e-mail about the \"\n            \"start and end of participation opportunities. This \"\n            \"applies to all projects I follow. I also receive an \"\n            \"e-mail when someone comments on one of my \"\n            \"contributions.\"\n        ),\n        required=False,\n        initial=True,\n    )\n    captcha = CaptcheckCaptchaField(label=_(\"I am not a robot\"))\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.fields[\"username\"].help_text = _(\n            \"Your username will appear publicly next to your posts.\"\n        )\n        self.fields[\"email\"].widget.attrs[\"autofocus\"] = True\n\n    def save(self, request):\n        user = super(TermsSignupForm, self).save(request)\n        user.get_newsletters = self.cleaned_data[\"get_newsletters\"]\n        user.get_notifications = self.cleaned_data[\"get_notifications\"]\n        user.save()\n        return user\n\n\nclass SocialTermsSignupForm(SocialSignupForm):\n    terms_of_use = forms.BooleanField(label=_(\"Terms of use\"))\n    get_newsletters = forms.BooleanField(\n        label=_(\"Newsletter\"),\n        help_text=_(\n            \"Yes, I would like to receive e-mail newsletters about \"\n            \"the projects I am following.\"\n        ),\n        required=False,\n    )\n    get_notifications = forms.BooleanField(\n        label=_(\"Notifications\"),\n        help_text=_(\n            \"Yes, I would like to be notified by e-mail about the \"\n            \"start and end of participation opportunities. This \"\n            \"applies to all projects I follow. I also receive an \"\n            \"e-mail when someone comments on one of my \"\n            \"contributions.\"\n        ),\n        required=False,\n        initial=True,\n    )\n    email = forms.EmailField(widget=forms.HiddenInput())\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.fields[\"username\"].help_text = _(\n            \"Your username will appear publicly next to your posts.\"\n        )\n\n    def save(self, request):\n        user = super(SocialTermsSignupForm, self).save(request)\n        user.get_newsletters = self.cleaned_data[\"get_newsletters\"]\n        user.get_notifications = self.cleaned_data[\"get_notifications\"]\n        user.save()\n        return user\n", "path": "meinberlin/apps/users/forms.py"}], "after_files": [{"content": "import collections\n\nfrom allauth.account.forms import SignupForm\nfrom allauth.socialaccount.forms import SignupForm as SocialSignupForm\nfrom django import forms\nfrom django.contrib.auth import forms as auth_forms\nfrom django.core.exceptions import ValidationError\nfrom django.utils.translation import gettext_lazy as _\nfrom django.utils.translation import ngettext\n\nfrom meinberlin.apps.captcha.fields import CaptcheckCaptchaField\nfrom meinberlin.apps.organisations.models import Organisation\nfrom meinberlin.apps.users.models import User\n\n\nclass UserAdminForm(auth_forms.UserChangeForm):\n    def clean(self):\n        groups = self.cleaned_data.get(\"groups\")\n        group_list = groups.values_list(\"id\", flat=True)\n        group_organisations = Organisation.objects.filter(\n            groups__in=group_list\n        ).values_list(\"name\", flat=True)\n        duplicates = [\n            item\n            for item, count in collections.Counter(group_organisations).items()\n            if count > 1\n        ]\n        if duplicates:\n            count = len(duplicates)\n            message = ngettext(\n                \"User is member in more than one group \"\n                \"in this organisation: %(duplicates)s.\",\n                \"User is member in more than one group \"\n                \"in these organisations: %(duplicates)s.\",\n                count,\n            ) % {\"duplicates\": \", \".join(duplicates)}\n            raise ValidationError(message)\n        return self.cleaned_data\n\n    def clean_username(self):\n        username = self.cleaned_data[\"username\"]\n        try:\n            user = User.objects.get(username__iexact=username)\n            if user != self.instance:\n                raise forms.ValidationError(\n                    User._meta.get_field(\"username\").error_messages[\"unique\"]\n                )\n        except User.DoesNotExist:\n            pass\n\n        try:\n            user = User.objects.get(email__iexact=username)\n            if user != self.instance:\n                raise forms.ValidationError(\n                    User._meta.get_field(\"username\").error_messages[\"used_as_email\"]\n                )\n        except User.DoesNotExist:\n            pass\n\n        return username\n\n\nclass AddUserAdminForm(auth_forms.UserCreationForm):\n    def clean_username(self):\n        username = self.cleaned_data[\"username\"]\n        user = User.objects.filter(username__iexact=username)\n        if user.exists():\n            raise forms.ValidationError(\n                User._meta.get_field(\"username\").error_messages[\"unique\"]\n            )\n        else:\n            user = User.objects.filter(email__iexact=username)\n            if user.exists():\n                raise forms.ValidationError(\n                    User._meta.get_field(\"username\").error_messages[\"used_as_email\"]\n                )\n        return username\n\n\nclass TermsSignupForm(SignupForm):\n    terms_of_use = forms.BooleanField(label=_(\"Terms of use\"))\n    get_newsletters = forms.BooleanField(\n        label=_(\"Newsletter\"),\n        help_text=_(\n            \"Yes, I would like to receive e-mail newsletters about \"\n            \"the projects I am following.\"\n        ),\n        required=False,\n    )\n    get_notifications = forms.BooleanField(\n        label=_(\"Notifications\"),\n        help_text=_(\n            \"Yes, I would like to be notified by e-mail about the \"\n            \"start and end of participation opportunities. This \"\n            \"applies to all projects I follow. I also receive an \"\n            \"e-mail when someone comments on one of my \"\n            \"contributions.\"\n        ),\n        required=False,\n        initial=True,\n    )\n    captcha = CaptcheckCaptchaField(label=_(\"I am not a robot\"))\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.fields[\"username\"].help_text = _(\n            \"Your username will appear publicly next to your posts.\"\n        )\n        self.fields[\"email\"].widget.attrs[\"autofocus\"] = True\n\n    def save(self, request):\n        user = super(TermsSignupForm, self).save(request)\n        if user:\n            user.get_newsletters = self.cleaned_data[\"get_newsletters\"]\n            user.get_notifications = self.cleaned_data[\"get_notifications\"]\n            user.save()\n            return user\n\n\nclass SocialTermsSignupForm(SocialSignupForm):\n    terms_of_use = forms.BooleanField(label=_(\"Terms of use\"))\n    get_newsletters = forms.BooleanField(\n        label=_(\"Newsletter\"),\n        help_text=_(\n            \"Yes, I would like to receive e-mail newsletters about \"\n            \"the projects I am following.\"\n        ),\n        required=False,\n    )\n    get_notifications = forms.BooleanField(\n        label=_(\"Notifications\"),\n        help_text=_(\n            \"Yes, I would like to be notified by e-mail about the \"\n            \"start and end of participation opportunities. This \"\n            \"applies to all projects I follow. I also receive an \"\n            \"e-mail when someone comments on one of my \"\n            \"contributions.\"\n        ),\n        required=False,\n        initial=True,\n    )\n    email = forms.EmailField(widget=forms.HiddenInput())\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.fields[\"username\"].help_text = _(\n            \"Your username will appear publicly next to your posts.\"\n        )\n\n    def save(self, request):\n        user = super(SocialTermsSignupForm, self).save(request)\n        user.get_newsletters = self.cleaned_data[\"get_newsletters\"]\n        user.get_notifications = self.cleaned_data[\"get_notifications\"]\n        user.save()\n        return user\n", "path": "meinberlin/apps/users/forms.py"}]}