"""This module contains the urls for the mhr project"""

from django.conf import settings
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.http import HttpResponse
from django.views.generic import RedirectView

from mtp.apps.accounts.views import LoginUserView
from mtp.apps.api.views import ClientSettings

admin.autodiscover()


# api
# ---

urlpatterns = patterns(
    '',
    # This url should be in the api apps, but since it's not prefixed,
    # It stays here for the moment
    url(r'^settings', ClientSettings.as_view(), name='client_settings'),
    url(r'^api/', include('mtp.apps.api.urls')),
)

# cms
# ---

urlpatterns += patterns(
    '',
    url(r'^cms/accounts/', include('mtp.apps.accounts.urls', namespace='accounts')),
    url(r'^cms/assessments/', include('mtp.apps.assessments.urls', namespace='assessments')),
    url(r'^cms/brainstormers/', include('mtp.apps.brainstormers.urls', namespace='brainstormers')),
    url(r'^cms/documents/', include('mtp.apps.documents.urls', namespace='documents')),
    url(r'^cms/evaluations/', include('mtp.apps.evaluations.urls', namespace='evaluations')),
    url(r'^cms/metaplans/', include('mtp.apps.metaplans.urls', namespace='metaplans')),
    url(r'^cms/roleplays/', include('mtp.apps.roleplays.urls', namespace='roleplays')),
    url(r'^cms/stats/', include('mtp.apps.stats.urls', namespace='stats')),
    url(r'^cms/surveys/', include('mtp.apps.surveys.urls', namespace='surveys')),
    url(r'^cms/sync/', include('mtp.apps.sync.urls', namespace='sync')),

    # url(r'^cms/themes/', include('mtp.apps.themes.urls, namespace='themes')),

    url(r'^cms/trainings/', include('mtp.apps.trainings.urls', namespace='trainings')),
    url(r'^cms/translation/', include('mtp.apps.translation.urls', namespace='translation')),
    url(r'^cms/workshops/', include('mtp.apps.workshops.urls', namespace='workshops')),
    url(r'^cms/', include('mtp.apps.cms.urls', namespace='cms')),
)

# root --> redirect to cms home
# -----------------------------

urlpatterns += patterns(
    '',
    url(r'^$', RedirectView.as_view(pattern_name='cms:index')),
)

# i18n
# -----------------------------

urlpatterns += patterns(
    '',
    url(r'^i18n/', include('django.conf.urls.i18n')),
)

# admin & auth
# ------------

urlpatterns += patterns(
    '',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^auth/login', LoginUserView.as_view(), name='login'),
    url(r'^auth/', include('django.contrib.auth.urls')),
)

# robots.txt
# ----------

urlpatterns += patterns(
    '',
    url(r'^robots\.txt$', lambda r: HttpResponse(
        'User-agent: *\nDisallow: /', mimetype='text/plain'
    )),
)

# style guide
# -----------

if 'mtp.apps.style' in settings.INSTALLED_APPS:
    urlpatterns += patterns(
        '',
        url(r'^cms/style/', include('mtp.apps.style.urls', namespace='style')),
    )

# django-markdown
# ---------------

if 'django_markdown' in settings.INSTALLED_APPS:
    urlpatterns += patterns(
        '',
        url('^markdown/', include('django_markdown.urls')),
    )

# rosetta
# -------

if 'rosetta' in settings.INSTALLED_APPS:
    urlpatterns += patterns(
        '',
        url(r'^translation/', include('rosetta.urls')),
    )

# django-select2
# --------------

if 'django_select2' in settings.INSTALLED_APPS:
    urlpatterns += patterns(
        '',
        url(r'^select2/', include('django_select2.urls')),
    )

# static files serving in debug mode
# ----------------------------------

if settings.DEBUG:
    urlpatterns += patterns(
        '',
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT
        }),
        url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.STATIC_ROOT
        }),
    )
