#from pages import urls
from django.urls import include, path, re_path
from django.conf.urls import include, url

#from pages import urls
from pages import views
from pages.views import PageView
#from django.views.generic import PageView
#added
from machina import MACHINA_MAIN_STATIC_DIR
from django.conf import settings
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print('url pages BASE DIR')
print(BASE_DIR)
from machina.conf import settings as machina_settings

#gunicorn requires
#from machina import urls as machina_urls

'''print('views.index')
print(views.index)
print(views.terms)'''


'''from django.views.generic import TemplateView

urlpatterns = [
    path('', TemplateView.as_view(template_name="index.html")),
    path('<slug>',  TemplateView.as_view(template_name='%s'+ '.html'))
]'''
#print('urlpath')
#print(url(r'^<page>.+?$', views.load_view, name="something").get_full_path())

urlpatterns = [

    #path('', PageView.as_view(template_name="index.html"))
    #include('views.index')
    #path('terms/', views.load_view, name="something")
    # doesn't work path("^<str>$", views.load_view, name="something")

    #doesn't work url(r'^(?P<page>.+)/$', views.load_view, name="something")
    #still doesn't work path(r'(?P<str>)$', views.load_view, name="something")
    #django get path converters doesn't work return page
    #re_path(r'^.+/$', views.load_view, name="something")
    #???
    #path('forums/', include(machina_urls)),
    ############
    path('', views.index),


    #[^/]
    #re_path(r'^(?:[^/].+)\/{0,1}?$', views.load_view, name="something")
    # works before re_path(r'^(?:[^/].+)\/{0,1}$', views.load_view)

    #path( MACHINA_MAIN_STATIC_DIR + '/static/', views.load_static ),
    #re_path(r'\b^(?(cache)(?:\/{0,1})\b)[^\/]*\/{0,1}$', ''),
    # doesn't work path(r'^terms/?$', views.load_view, name="something")
]
import django.views.static
machina_attachment_regex =  "^" + machina_settings.ATTACHMENT_FILE_UPLOAD_TO + "/(?P<path>.*)$"
#r'^machina/attachments/(?P<path>.*)$'
urlpatterns += [
    #url(r'^static/(?P<path>.*)$', django.views.static.serve, {'document_root': settings.STATIC_ROOT, 'show_indexes': settings.DEBUG}),
    url(machina_attachment_regex, django.views.static.serve, {'document_root': machina_settings.ATTACHMENT_FILE_UPLOAD_TO, 'show_indexes': settings.DEBUG}),
    url(r'^cache/(?P<path>.*)$', django.views.static.serve, {'document_root': os.path.join(BASE_DIR, 'cache'), 'show_indexes': settings.DEBUG})
]

#urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
''' path('', views.index, name='main'),
path('terms/', views.terms, name='terms'),
#path('privacy/', views.privacy, name='privacy'),
re_path('^r<slug>', views.as_view())
'''
