
import logging
logger = logging.getLogger(__name__)

from django_iceberg.auth_utils import init_iceberg, get_conf_class

def iceberg_settings(request):
    """
    Defines some template variables in context
    """
    conf = get_conf_class(request)

    if not conf:
        ICEBERG_API_URL_FULL = "https://api.iceberg.technology"
        ICEBERG_CORS = "https://api.iceberg.technology/cors/"
        iceberg_env = 'prod'
    else:
        iceberg_env = getattr(conf, 'ICEBERG_ENV', 'prod')
        ICEBERG_API_URL_FULL = conf.ICEBERG_API_URL_FULL
        ICEBERG_CORS = conf.ICEBERG_CORS

    res = {
        "ICEBERG_ENV": iceberg_env,
        "ICEBERG_API_URL": ICEBERG_API_URL_FULL,
        "ICEBERG_CORS": ICEBERG_CORS,
    }

    if request.user.is_authenticated():
        res['access_token'] = init_iceberg(request).access_token
    else:
        res['ICEBERG_ENV'] = None
        res['access_token'] = "anonymous"
    return res


import logging
logger = logging.getLogger(__name__)

from django_iceberg.auth_utils import init_iceberg, get_conf_class

def iceberg_settings(request):
    """
    Defines some template variables in context
    """
    conf = get_conf_class(request)

    if not conf:
        ICEBERG_API_URL_FULL = "https://api.iceberg.technology"
        ICEBERG_CORS = "https://api.iceberg.technology/cors/"
        iceberg_env = 'prod'
    else:
        iceberg_env = getattr(conf, 'ICEBERG_ENV', 'prod')
        ICEBERG_API_URL_FULL = conf.ICEBERG_API_URL_FULL
        ICEBERG_CORS = conf.ICEBERG_CORS

    res = {
        "ICEBERG_ENV": iceberg_env,
        "ICEBERG_API_URL": ICEBERG_API_URL_FULL,
        "ICEBERG_CORS": ICEBERG_CORS,
    }

    if request.user.is_authenticated():
        res['access_token'] = init_iceberg(request).access_token
        res['username'] = init_iceberg(request).username
    else:
        res['ICEBERG_ENV'] = None
        res['access_token'] = "anonymous"
    return res

Add username to context in iceberg_settings context processor
Add username to context in iceberg_settings context processor

  
  import logging
  logger = logging.getLogger(__name__)
  
  from django_iceberg.auth_utils import init_iceberg, get_conf_class
  
  def iceberg_settings(request):
      """
      Defines some template variables in context
      """
      conf = get_conf_class(request)
  
      if not conf:
          ICEBERG_API_URL_FULL = "https://api.iceberg.technology"
          ICEBERG_CORS = "https://api.iceberg.technology/cors/"
          iceberg_env = 'prod'
      else:
          iceberg_env = getattr(conf, 'ICEBERG_ENV', 'prod')
          ICEBERG_API_URL_FULL = conf.ICEBERG_API_URL_FULL
          ICEBERG_CORS = conf.ICEBERG_CORS
  
      res = {
          "ICEBERG_ENV": iceberg_env,
          "ICEBERG_API_URL": ICEBERG_API_URL_FULL,
          "ICEBERG_CORS": ICEBERG_CORS,
      }
  
      if request.user.is_authenticated():
          res['access_token'] = init_iceberg(request).access_token
+         res['username'] = init_iceberg(request).username
      else:
          res['ICEBERG_ENV'] = None
          res['access_token'] = "anonymous"
      return res
  
Add username to context in iceberg_settings context processor
## Code Before:

import logging
logger = logging.getLogger(__name__)

from django_iceberg.auth_utils import init_iceberg, get_conf_class

def iceberg_settings(request):
    """
    Defines some template variables in context
    """
    conf = get_conf_class(request)

    if not conf:
        ICEBERG_API_URL_FULL = "https://api.iceberg.technology"
        ICEBERG_CORS = "https://api.iceberg.technology/cors/"
        iceberg_env = 'prod'
    else:
        iceberg_env = getattr(conf, 'ICEBERG_ENV', 'prod')
        ICEBERG_API_URL_FULL = conf.ICEBERG_API_URL_FULL
        ICEBERG_CORS = conf.ICEBERG_CORS

    res = {
        "ICEBERG_ENV": iceberg_env,
        "ICEBERG_API_URL": ICEBERG_API_URL_FULL,
        "ICEBERG_CORS": ICEBERG_CORS,
    }

    if request.user.is_authenticated():
        res['access_token'] = init_iceberg(request).access_token
    else:
        res['ICEBERG_ENV'] = None
        res['access_token'] = "anonymous"
    return res

## Instruction:
Add username to context in iceberg_settings context processor
## Code After:

import logging
logger = logging.getLogger(__name__)

from django_iceberg.auth_utils import init_iceberg, get_conf_class

def iceberg_settings(request):
    """
    Defines some template variables in context
    """
    conf = get_conf_class(request)

    if not conf:
        ICEBERG_API_URL_FULL = "https://api.iceberg.technology"
        ICEBERG_CORS = "https://api.iceberg.technology/cors/"
        iceberg_env = 'prod'
    else:
        iceberg_env = getattr(conf, 'ICEBERG_ENV', 'prod')
        ICEBERG_API_URL_FULL = conf.ICEBERG_API_URL_FULL
        ICEBERG_CORS = conf.ICEBERG_CORS

    res = {
        "ICEBERG_ENV": iceberg_env,
        "ICEBERG_API_URL": ICEBERG_API_URL_FULL,
        "ICEBERG_CORS": ICEBERG_CORS,
    }

    if request.user.is_authenticated():
        res['access_token'] = init_iceberg(request).access_token
        res['username'] = init_iceberg(request).username
    else:
        res['ICEBERG_ENV'] = None
        res['access_token'] = "anonymous"
    return res
