from importlib import import_module

from django.apps import apps
from django.conf import settings
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from .models import UserManagedState, UserProfile

admin.site.register(UserProfile)
admin.site.register(UserManagedState)

# Monkey-patch the get_username, mostly for the admin


def get_user_model_safe():
    """
    Get the user model before it is loaded, but after the app registry
    is populated
    """
    app_label, model_name = settings.AUTH_USER_MODEL.split('.')
    app_config = apps.get_app_config(app_label)
    models_module = import_module("%s.%s" % (app_config.name, "models"))
    return getattr(models_module, model_name)


def username(self):
    return _('{fullname} <{email}>').format(
        fullname=self.get_full_name(),
        email=self.email)


get_user_model_safe().get_username = username

from importlib import import_module

from django.apps import apps
from django.conf import settings
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from .models import UserManagedState, UserProfile

admin.site.register(UserProfile)
admin.site.register(UserManagedState)

Drop the hurtinq username patching of username that also affects edition
Drop the hurtinq username patching of username that also affects edition

  from importlib import import_module
  
  from django.apps import apps
  from django.conf import settings
  from django.contrib import admin
  from django.utils.translation import ugettext_lazy as _
  
  from .models import UserManagedState, UserProfile
  
  admin.site.register(UserProfile)
  admin.site.register(UserManagedState)
  
- # Monkey-patch the get_username, mostly for the admin
- 
- 
- def get_user_model_safe():
-     """
-     Get the user model before it is loaded, but after the app registry
-     is populated
-     """
-     app_label, model_name = settings.AUTH_USER_MODEL.split('.')
-     app_config = apps.get_app_config(app_label)
-     models_module = import_module("%s.%s" % (app_config.name, "models"))
-     return getattr(models_module, model_name)
- 
- 
- def username(self):
-     return _('{fullname} <{email}>').format(
-         fullname=self.get_full_name(),
-         email=self.email)
- 
- 
- get_user_model_safe().get_username = username
- 
Drop the hurtinq username patching of username that also affects edition
## Code Before:
from importlib import import_module

from django.apps import apps
from django.conf import settings
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from .models import UserManagedState, UserProfile

admin.site.register(UserProfile)
admin.site.register(UserManagedState)

# Monkey-patch the get_username, mostly for the admin


def get_user_model_safe():
    """
    Get the user model before it is loaded, but after the app registry
    is populated
    """
    app_label, model_name = settings.AUTH_USER_MODEL.split('.')
    app_config = apps.get_app_config(app_label)
    models_module = import_module("%s.%s" % (app_config.name, "models"))
    return getattr(models_module, model_name)


def username(self):
    return _('{fullname} <{email}>').format(
        fullname=self.get_full_name(),
        email=self.email)


get_user_model_safe().get_username = username

## Instruction:
Drop the hurtinq username patching of username that also affects edition
## Code After:
from importlib import import_module

from django.apps import apps
from django.conf import settings
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from .models import UserManagedState, UserProfile

admin.site.register(UserProfile)
admin.site.register(UserManagedState)
