"""main URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""

from django.conf import settings
from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, re_path, reverse_lazy
from django.views.generic.base import RedirectView

from ocyan.core.fender import config
from ocyan.core.plugins import get_plugins

from .views import serve_engine_page, startup

plugins = get_plugins()

# the default
handler404 = settings.OCYAN_404_HANDLER

urlpatterns = [
    path(r"~startup/", startup),
    path(r"pages/<slug:slug>/", serve_engine_page, name="engine-page-by-slug"),
    path(r"manage/", admin.site.urls),
    re_path(r"^django_admin/.*", RedirectView.as_view(url=reverse_lazy("admin:index"))),
    re_path(r"^django-admin/.*", RedirectView.as_view(url=reverse_lazy("admin:index"))),
]
if config.i18n_enabled:
    urlpatterns = i18n_patterns(*urlpatterns, prefix_default_language=False)

urlpatterns = plugins.pipe("contribute_to_urlpatterns", urlpatterns)

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
