original_docstring: Fix ownership for orphan objects.
docstring: Fix ownership for orphan objects.
docstring_tokens: Fix ownership for orphan objects .
code: def fix_owner(qs, dry_run=False, **options):
      """Fix ownership for orphan objects."""
      model = qs.model
      for obj in qs:
          kw = {"cls": model.__name__, "obj": obj}
          if get_object_owner(obj) is not None:
              continue
          if dry_run:
              log("  {cls} {obj} has no owner".format(**kw), **options)
              continue
          if isinstance(obj, User):
              admin = User.objects.filter(
                  is_superuser=True, is_active=True).first()
          elif isinstance(obj, models.Domain):
              admin = obj.admins.first()
          elif isinstance(obj, models.DomainAlias):
              admin = obj.target.admins.first()
          else:
              admin = obj.domain.admins.first()
          if not admin:
              # Fallback: use the first superuser found
              admin = User.objects.filter(
                  is_superuser=True, is_active=True).first()
          grant_access_to_object(admin, obj, is_owner=True)
          kw["admin"] = admin
          log("  {cls} {obj} is now owned by {admin}".format(**kw),
              **options)
code_tokens: def fix_owner ( qs , dry_run = False , ** options ) : model = qs . model for obj in qs : kw = { "cls" : model . __name__ , "obj" : obj } if get_object_owner ( obj ) is not None : continue if dry_run : log ( "  {cls} {obj} has no owner" . format ( ** kw ) , ** options ) continue if isinstance ( obj , User ) : admin = User . objects . filter ( is_superuser = True , is_active = True ) . first ( ) elif isinstance ( obj , models . Domain ) : admin = obj . admins . first ( ) elif isinstance ( obj , models . DomainAlias ) : admin = obj . target . admins . first ( ) else : admin = obj . domain . admins . first ( ) if not admin : admin = User . objects . filter ( is_superuser = True , is_active = True ) . first ( ) grant_access_to_object ( admin , obj , is_owner = True ) kw [ "admin" ] = admin log ( "  {cls} {obj} is now owned by {admin}" . format ( ** kw ) , ** options )
short_docstring: Fix ownership for orphan objects.
short_docstring_tokens: Fix ownership for orphan objects .
comment: """Fix ownership for orphan objects."""$SEP$# Fallback: use the first superuser found