'>>> env = User.user_template_environment(None)
>>> env[\'__user_email__\']
\'Anonymous\'
>>> env[\'__user_id__\']
\'Anonymous\'
>>> user = User(\'foo@example.com\')
>>> user.id = 6
>>> user.username = \'foo2\'
>>> env = User.user_template_environment(user)
>>> env[\'__user_id__\']
\'6\'
>>> env[\'__user_name__\']
\'foo2\''

@staticmethod
def user_template_environment(user):

    if user:
        user_id = ('%d' % user.id)
        user_email = str(user.email)
        user_name = str(user.username)
    else:
        user = None
        user_id = 'Anonymous'
        user_email = 'Anonymous'
        user_name = 'Anonymous'
    environment = {}
    environment['__user__'] = user
    environment['__user_id__'] = environment['userId'] = user_id
    environment['__user_email__'] = environment['userEmail'] = user_email
    environment['__user_name__'] = user_name
    return environment
