"""
WSGI config for django_machina_project project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""

import os
import sys

sys.path.insert(0, os.path.dirname(__file__))
#PROJECT_ROOT = "/home/whatdowh/django_machina_project"
#sys.path.insert(0, PROJECT_ROOT)


from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_machina_project.settings')

def application(environ, start_response):
    #    start_response('200 OK', [('Content-Type', 'text/plain')])
    #    message = 'It works2!\n'
    #    version = 'Python %s\n' % sys.version.split()[0]
    #    response = '\n'.join([message, version])
    #    return [response.encode()]
    #import os

    #from django.core.wsgi import get_wsgi_application

    #os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_machina_project.settings')

    application = get_wsgi_application()


    #new
    from whitenoise import WhiteNoise
    from machina import MACHINA_MAIN_STATIC_DIR

    ##from django_machina_project import MyWSGIApp

    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    #application = MyWSGIApp()
    application = WhiteNoise(application, root=os.path.join(BASE_DIR, 'static')) #django_machina_project/static
    application.add_files(os.path.join(BASE_DIR, 'staticfiles'), prefix="static/")
    #application.add_files(os.path.join(BASE_DIR, 'css'), prefix="css/")

    #application.add_files(os.path.join(BASE_DIR, 'staticfiles'), prefix="cache/")
    application.add_files(os.path.join(BASE_DIR, 'cache'), prefix="cache/")
    application.add_files(os.path.join(BASE_DIR, ''), prefix="")
    application.add_files(os.path.join(BASE_DIR, 'static'), prefix="static/")
    application.add_files(MACHINA_MAIN_STATIC_DIR)
    #return true
    start_response('200 OK', [('Content-Type', 'text/plain')])
    response = ''
    return [response.encode()]
