import re

from allauth.account.adapter import DefaultAccountAdapter
from django.conf import settings

from apps.contrib.emails import Email
from apps.users import USERNAME_INVALID_MESSAGE
from apps.users import USERNAME_REGEX


class UserAccountEmail(Email):
    def get_receivers(self):
        return [self.object]

    @property
    def template_name(self):
        return self.kwargs['template_name']

    def get_context(self):
        context = super().get_context()
        context['contact_email'] = settings.CONTACT_EMAIL
        return context


class AccountAdapter(DefaultAccountAdapter):
    username_regex = re.compile(USERNAME_REGEX)
    error_messages = dict(
        DefaultAccountAdapter.error_messages,
        invalid_username=USERNAME_INVALID_MESSAGE
    )

    def send_mail(self, template_prefix, email, context):
        user = context['user']
        return UserAccountEmail.send_sync(
            user,
            template_name=template_prefix,
            **context
        )

import re

from allauth.account.adapter import DefaultAccountAdapter
from django.conf import settings

from adhocracy4.emails.mixins import SyncEmailMixin
from apps.contrib.emails import Email
from apps.users import USERNAME_INVALID_MESSAGE
from apps.users import USERNAME_REGEX


class UserAccountEmail(Email, SyncEmailMixin):
    def get_receivers(self):
        return [self.object]

    @property
    def template_name(self):
        return self.kwargs['template_name']

    def get_context(self):
        context = super().get_context()
        context['contact_email'] = settings.CONTACT_EMAIL
        return context


class AccountAdapter(DefaultAccountAdapter):
    username_regex = re.compile(USERNAME_REGEX)
    error_messages = dict(
        DefaultAccountAdapter.error_messages,
        invalid_username=USERNAME_INVALID_MESSAGE
    )

    def send_mail(self, template_prefix, email, context):
        user = context['user']
        return UserAccountEmail.send(
            user,
            template_name=template_prefix,
            **context
        )

Use SyncEmailMixin for account mails
Use SyncEmailMixin for account mails

  import re
  
  from allauth.account.adapter import DefaultAccountAdapter
  from django.conf import settings
  
+ from adhocracy4.emails.mixins import SyncEmailMixin
  from apps.contrib.emails import Email
  from apps.users import USERNAME_INVALID_MESSAGE
  from apps.users import USERNAME_REGEX
  
  
- class UserAccountEmail(Email):
+ class UserAccountEmail(Email, SyncEmailMixin):
      def get_receivers(self):
          return [self.object]
  
      @property
      def template_name(self):
          return self.kwargs['template_name']
  
      def get_context(self):
          context = super().get_context()
          context['contact_email'] = settings.CONTACT_EMAIL
          return context
  
  
  class AccountAdapter(DefaultAccountAdapter):
      username_regex = re.compile(USERNAME_REGEX)
      error_messages = dict(
          DefaultAccountAdapter.error_messages,
          invalid_username=USERNAME_INVALID_MESSAGE
      )
  
      def send_mail(self, template_prefix, email, context):
          user = context['user']
-         return UserAccountEmail.send_sync(
+         return UserAccountEmail.send(
              user,
              template_name=template_prefix,
              **context
          )
  
Use SyncEmailMixin for account mails
## Code Before:
import re

from allauth.account.adapter import DefaultAccountAdapter
from django.conf import settings

from apps.contrib.emails import Email
from apps.users import USERNAME_INVALID_MESSAGE
from apps.users import USERNAME_REGEX


class UserAccountEmail(Email):
    def get_receivers(self):
        return [self.object]

    @property
    def template_name(self):
        return self.kwargs['template_name']

    def get_context(self):
        context = super().get_context()
        context['contact_email'] = settings.CONTACT_EMAIL
        return context


class AccountAdapter(DefaultAccountAdapter):
    username_regex = re.compile(USERNAME_REGEX)
    error_messages = dict(
        DefaultAccountAdapter.error_messages,
        invalid_username=USERNAME_INVALID_MESSAGE
    )

    def send_mail(self, template_prefix, email, context):
        user = context['user']
        return UserAccountEmail.send_sync(
            user,
            template_name=template_prefix,
            **context
        )

## Instruction:
Use SyncEmailMixin for account mails
## Code After:
import re

from allauth.account.adapter import DefaultAccountAdapter
from django.conf import settings

from adhocracy4.emails.mixins import SyncEmailMixin
from apps.contrib.emails import Email
from apps.users import USERNAME_INVALID_MESSAGE
from apps.users import USERNAME_REGEX


class UserAccountEmail(Email, SyncEmailMixin):
    def get_receivers(self):
        return [self.object]

    @property
    def template_name(self):
        return self.kwargs['template_name']

    def get_context(self):
        context = super().get_context()
        context['contact_email'] = settings.CONTACT_EMAIL
        return context


class AccountAdapter(DefaultAccountAdapter):
    username_regex = re.compile(USERNAME_REGEX)
    error_messages = dict(
        DefaultAccountAdapter.error_messages,
        invalid_username=USERNAME_INVALID_MESSAGE
    )

    def send_mail(self, template_prefix, email, context):
        user = context['user']
        return UserAccountEmail.send(
            user,
            template_name=template_prefix,
            **context
        )
