# Path: account/signals.py

# 
# Path: account/conf.py
# def load_path_attr(path):
#     def configure_hookset(self, value):
# class AccountAppConf(AppConf):
#     OPEN_SIGNUP = True
#     LOGIN_URL = "account_login"
#     LOGOUT_URL = "account_logout"
#     SIGNUP_REDIRECT_URL = "/"
#     LOGIN_REDIRECT_URL = "/"
#     LOGOUT_REDIRECT_URL = "/"
#     PASSWORD_CHANGE_REDIRECT_URL = "account_password"
#     PASSWORD_RESET_REDIRECT_URL = "account_login"
#     PASSWORD_RESET_TOKEN_URL = "account_password_reset_token"
#     PASSWORD_EXPIRY = 0
#     PASSWORD_USE_HISTORY = False
#     PASSWORD_STRIP = True
#     REMEMBER_ME_EXPIRY = 60 * 60 * 24 * 365 * 10
#     USER_DISPLAY = lambda user: user.username  # noqa
#     CREATE_ON_SAVE = True
#     EMAIL_UNIQUE = True
#     EMAIL_CONFIRMATION_REQUIRED = False
#     EMAIL_CONFIRMATION_EMAIL = True
#     EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
#     EMAIL_CONFIRMATION_AUTO_LOGIN = False
#     EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = "account_login"
#     EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = None
#     EMAIL_CONFIRMATION_URL = "account_confirm_email"
#     SETTINGS_REDIRECT_URL = "account_settings"
#     NOTIFY_ON_PASSWORD_CHANGE = True
#     DELETION_EXPUNGE_HOURS = 48
#     DEFAULT_HTTP_PROTOCOL = "https"
#     HOOKSET = "account.hooks.AccountDefaultHookSet"
#     TIMEZONES = TIMEZONES
#     LANGUAGES = LANGUAGES
# 
# Path: account/fields.py
# class TimeZoneField(models.CharField):
# 
#     def __init__(self, *args, **kwargs):
#         defaults = {
#             "max_length": 100,
#             "default": "",
#             "choices": settings.ACCOUNT_TIMEZONES,
#             "blank": True,
#         }
#         defaults.update(kwargs)
#         return super(TimeZoneField, self).__init__(*args, **defaults)
# 
# Path: account/hooks.py
# class AccountDefaultHookSet(object):
# class HookProxy(object):
#     def send_invitation_email(self, to, ctx):
#     def send_confirmation_email(self, to, ctx):
#     def send_password_change_email(self, to, ctx):
#     def send_password_reset_email(self, to, ctx):
#     def generate_random_token(self, extra=None, hash_func=hashlib.sha256):
#     def generate_signup_code_token(self, email=None):
#     def generate_email_confirmation_token(self, email):
#     def get_user_credentials(self, form, identifier_field):
#     def clean_password(self, password_new, password_new_confirm):
#     def account_delete_mark(self, deletion):
#     def account_delete_expunge(self, deletion):
#     def __getattr__(self, attr):
# 
# Path: account/languages.py
# DEFAULT_LANGUAGE = get_language_info(settings.LANGUAGE_CODE)["code"]
# 
# Path: account/managers.py
# class EmailAddressManager(models.Manager):
# 
#     def add_email(self, user, email, **kwargs):
#         confirm = kwargs.pop("confirm", False)
#         email_address = self.create(user=user, email=email, **kwargs)
#         if confirm and not email_address.verified:
#             email_address.send_confirmation()
#         return email_address
# 
#     def get_primary(self, user):
#         try:
#             return self.get(user=user, primary=True)
#         except self.model.DoesNotExist:
#             return None
# 
#     def get_users_for(self, email):
#         # this is a list rather than a generator because we probably want to
#         # do a len() on it right away
#         return [address.user for address in self.filter(verified=True, email=email)]
# 
# class EmailConfirmationManager(models.Manager):
# 
#     def delete_expired_confirmations(self):
#         for confirmation in self.all():
#             if confirmation.key_expired():
#                 confirmation.delete()
# 
# Path: account/signals.py



import datetime
import functools
import operator
import pytz
from urllib.parse import urlencode
from django import forms
from django.contrib.auth.models import AnonymousUser
from django.contrib.sites.models import Site
from django.db import models, transaction
from django.db.models import Q
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.urls import reverse
from django.utils import timezone, translation
from django.utils.translation import gettext_lazy as _
from account import signals
from account.conf import settings
from account.fields import TimeZoneField
from account.hooks import hookset
from account.languages import DEFAULT_LANGUAGE
from account.managers import EmailAddressManager, EmailConfirmationManager
from account.signals import signup_code_sent, signup_code_used



class Account(models.Model):

    user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name="account", verbose_name=_("user"), on_delete=models.CASCADE)
    timezone = TimeZoneField(_("timezone"))
    language = models.CharField(
        _("language"),
        max_length=10,
        choices=settings.ACCOUNT_LANGUAGES,
        default=DEFAULT_LANGUAGE,
    )

    @classmethod
    def for_request(cls, request):
        user = getattr(request, "user", None)
        if user and user.is_authenticated:
            account = user.account
            if account:
                return account
        return AnonymousAccount(request)

    @classmethod
    def create(cls, request=None, **kwargs):
        create_email = kwargs.pop("create_email", True)
        confirm_email = kwargs.pop("confirm_email", None)
        account = cls(**kwargs)
        if "language" not in kwargs:
            if request is None:

# Path: account/signals.py

# 
# Path: account/conf.py
# def load_path_attr(path):
#     def configure_hookset(self, value):
# class AccountAppConf(AppConf):
#     OPEN_SIGNUP = True
#     LOGIN_URL = "account_login"
#     LOGOUT_URL = "account_logout"
#     SIGNUP_REDIRECT_URL = "/"
#     LOGIN_REDIRECT_URL = "/"
#     LOGOUT_REDIRECT_URL = "/"
#     PASSWORD_CHANGE_REDIRECT_URL = "account_password"
#     PASSWORD_RESET_REDIRECT_URL = "account_login"
#     PASSWORD_RESET_TOKEN_URL = "account_password_reset_token"
#     PASSWORD_EXPIRY = 0
#     PASSWORD_USE_HISTORY = False
#     PASSWORD_STRIP = True
#     REMEMBER_ME_EXPIRY = 60 * 60 * 24 * 365 * 10
#     USER_DISPLAY = lambda user: user.username  # noqa
#     CREATE_ON_SAVE = True
#     EMAIL_UNIQUE = True
#     EMAIL_CONFIRMATION_REQUIRED = False
#     EMAIL_CONFIRMATION_EMAIL = True
#     EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
#     EMAIL_CONFIRMATION_AUTO_LOGIN = False
#     EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = "account_login"
#     EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = None
#     EMAIL_CONFIRMATION_URL = "account_confirm_email"
#     SETTINGS_REDIRECT_URL = "account_settings"
#     NOTIFY_ON_PASSWORD_CHANGE = True
#     DELETION_EXPUNGE_HOURS = 48
#     DEFAULT_HTTP_PROTOCOL = "https"
#     HOOKSET = "account.hooks.AccountDefaultHookSet"
#     TIMEZONES = TIMEZONES
#     LANGUAGES = LANGUAGES
# 
# Path: account/fields.py
# class TimeZoneField(models.CharField):
# 
#     def __init__(self, *args, **kwargs):
#         defaults = {
#             "max_length": 100,
#             "default": "",
#             "choices": settings.ACCOUNT_TIMEZONES,
#             "blank": True,
#         }
#         defaults.update(kwargs)
#         return super(TimeZoneField, self).__init__(*args, **defaults)
# 
# Path: account/hooks.py
# class AccountDefaultHookSet(object):
# class HookProxy(object):
#     def send_invitation_email(self, to, ctx):
#     def send_confirmation_email(self, to, ctx):
#     def send_password_change_email(self, to, ctx):
#     def send_password_reset_email(self, to, ctx):
#     def generate_random_token(self, extra=None, hash_func=hashlib.sha256):
#     def generate_signup_code_token(self, email=None):
#     def generate_email_confirmation_token(self, email):
#     def get_user_credentials(self, form, identifier_field):
#     def clean_password(self, password_new, password_new_confirm):
#     def account_delete_mark(self, deletion):
#     def account_delete_expunge(self, deletion):
#     def __getattr__(self, attr):
# 
# Path: account/languages.py
# DEFAULT_LANGUAGE = get_language_info(settings.LANGUAGE_CODE)["code"]
# 
# Path: account/managers.py
# class EmailAddressManager(models.Manager):
# 
#     def add_email(self, user, email, **kwargs):
#         confirm = kwargs.pop("confirm", False)
#         email_address = self.create(user=user, email=email, **kwargs)
#         if confirm and not email_address.verified:
#             email_address.send_confirmation()
#         return email_address
# 
#     def get_primary(self, user):
#         try:
#             return self.get(user=user, primary=True)
#         except self.model.DoesNotExist:
#             return None
# 
#     def get_users_for(self, email):
#         # this is a list rather than a generator because we probably want to
#         # do a len() on it right away
#         return [address.user for address in self.filter(verified=True, email=email)]
# 
# class EmailConfirmationManager(models.Manager):
# 
#     def delete_expired_confirmations(self):
#         for confirmation in self.all():
#             if confirmation.key_expired():
#                 confirmation.delete()
# 
# Path: account/signals.py



# Path: account/models.py
import datetime
import functools
import operator
import pytz
from urllib.parse import urlencode
from django import forms
from django.contrib.auth.models import AnonymousUser
from django.contrib.sites.models import Site
from django.db import models, transaction
from django.db.models import Q
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.urls import reverse
from django.utils import timezone, translation
from django.utils.translation import gettext_lazy as _
from account import signals
from account.conf import settings
from account.fields import TimeZoneField
from account.hooks import hookset
from account.languages import DEFAULT_LANGUAGE
from account.managers import EmailAddressManager, EmailConfirmationManager
from account.signals import signup_code_sent, signup_code_used




class Account(models.Model):

    user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name="account", verbose_name=_("user"), on_delete=models.CASCADE)
    timezone = TimeZoneField(_("timezone"))
    language = models.CharField(
        _("language"),
        max_length=10,
        choices=settings.ACCOUNT_LANGUAGES,
        default=DEFAULT_LANGUAGE,
    )

    @classmethod
    def for_request(cls, request):
        user = getattr(request, "user", None)
        if user and user.is_authenticated:
            account = user.account
            if account:
                return account
        return AnonymousAccount(request)

    @classmethod
    def create(cls, request=None, **kwargs):
        create_email = kwargs.pop("create_email", True)
        confirm_email = kwargs.pop("confirm_email", None)
        account = cls(**kwargs)
        if "language" not in kwargs:
            if request is None:

                account.language = DEFAULT_LANGUAGE