from django.conf.urls import patterns, include, url

import autocomplete_light
autocomplete_light.autodiscover()

from django.contrib import admin
admin.autodiscover()

from django.views.generic.list import ListView
from django.views.generic.base import TemplateView
from bda.models import Spectacle
from gestioncof.petits_cours_views import DemandeListView

urlpatterns = patterns('',
    url(r'^$', 'gestioncof.views.home', name = 'home'),
    url(r'^cof/denied$',  TemplateView.as_view(template_name = 'cof-denied.html'), name = "cof-denied"),
    url(r'^cas/login$', 'django_cas_ng.views.login', name = "cas_login_view"),
    url(r'^cas/logout$', 'django_cas_ng.views.logout'),
    url(r'^outsider/login$', 'gestioncof.views.login_ext'),
    url(r'^outsider/logout$', 'django.contrib.auth.views.logout', {'next_page': '/gestion/'}),
    url(r'^outsider/password-change$', 'django.contrib.auth.views.password_change'),
    url(r'^outsider/password-change-done$', 'django.contrib.auth.views.password_change_done'),
    url(r'^login$', 'gestioncof.views.login'),
    url(r'^logout$', 'gestioncof.views.logout'),
    url(r'^profile$', 'gestioncof.views.profile'),
    url(r'^export/members$', 'gestioncof.views.export_members'),
    url(r'^export/mega/avecremarques$', 'gestioncof.views.export_mega_remarksonly'),
    url(r'^export/mega/participants$', 'gestioncof.views.export_mega_participants'),
    url(r'^export/mega/orgas$', 'gestioncof.views.export_mega_orgas'),
    url(r'^export/mega/(?P<type>.+)$', 'gestioncof.views.export_mega_bytype'),
    url(r'^export/mega$', 'gestioncof.views.export_mega'),
    url(r'^registration$', 'gestioncof.views.registration'),
    url(r'^registration/clipper/(?P<login_clipper>[\w-]+)$', 'gestioncof.views.registration_form2', name = "clipper-registration"),
    url(r'^registration/user/(?P<username>.+)$', 'gestioncof.views.registration_form2', name = "user-registration"),
    url(r'^registration/empty$', 'gestioncof.views.registration_form2', name = "empty-registration"),
    url(r'^petitcours/inscription$', 'gestioncof.petits_cours_views.inscription', name = 'petits-cours-inscription'),
    url(r'^petitcours/demande$', 'gestioncof.petits_cours_views.demande', name = 'petits-cours-demande'),
    url(r'^petitcours/demande-raw$', 'gestioncof.petits_cours_views.demande_raw', name = 'petits-cours-demande-raw'),
    url(r'^petitcours/demandes$', DemandeListView.as_view(), name = 'petits-cours-demandes-list'),
    url(r'^petitcours/demandes/(?P<demande_id>\d+)$', 'gestioncof.petits_cours_views.details', name = 'petits-cours-demande-details'),
    url(r'^petitcours/demandes/(?P<demande_id>\d+)/traitement$', 'gestioncof.petits_cours_views.traitement', name = 'petits-cours-demande-traitement'),
    url(r'^petitcours/demandes/(?P<demande_id>\d+)/retraitement$', 'gestioncof.petits_cours_views.retraitement', name = 'petits-cours-demande-retraitement'),

    url(r'^bda/inscription/(?P<tirage_id>\d+)$', 'bda.views.inscription', name = 'bda-tirage-inscription'),
    url(r'^bda/places/(?P<tirage_id>\d+)$', 'bda.views.places', name = "bda-places-attribuees"),
    url(r'^bda/places/(?P<tirage_id>\d+)/places_bda.ics$', 'bda.views.places_ics', name = "bda-places-attribuees-ics"),
    url(r'^bda/revente/(?P<tirage_id>\d+)$', 'bda.views.revente', name = 'bda-revente'),
    url(r'^bda/etat-places/(?P<tirage_id>\d+)$', 'bda.views.etat_places', name = 'bda-etat-places'),
    url(r'^bda/tirage/(?P<tirage_id>\d+)$', 'bda.views.tirage'),
    # FIXME
    url(r'^bda/spectacles/(?P<tirage_id>\d+)$', lambda request, tirage_id:
                                                    ListView(model=Spectacle,
                                                        queryset=Spectacle.objects.filter(tirage__id=tirage_id)
                                                        ), name ="bda-liste-spectacles"),
    url(r'^bda/spectacles/(?P<tirage_id>\d+)/(?P<spectacle_id>\d+)$', "bda.views.spectacle", name = "bda-spectacle"),
    url(r'^bda/spectacles-ics/(?P<tirage_id>\d+)$', 'bda.views.liste_spectacles_ics', name ="bda-liste-spectacles-ics"),
    url(r'^bda/spectacles/unpaid(?P<tirage_id>\d+)$', "bda.views.unpaid", name = "bda-unpaid"),

    url(r'^survey/(?P<survey_id>\d+)$', 'gestioncof.views.survey'),
    url(r'^event/(?P<event_id>\d+)$', 'gestioncof.views.event'),
    url(r'^survey/(?P<survey_id>\d+)/status$', 'gestioncof.views.survey_status'),
    url(r'^event/(?P<event_id>\d+)/status$', 'gestioncof.views.event_status'),
    url(r'^autocomplete/registration$', 'gestioncof.autocomplete.autocomplete'),
    url(r'^autocomplete/', include('autocomplete_light.urls')),
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    url(r'^admin/(?P<app_label>[\d\w]+)/(?P<model_name>[\d\w]+)/csv/', 'gestioncof.csv_views.admin_list_export', {'fields': ['username',]}),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^grappelli/', include('grappelli.urls')),
    url(r'^utile_cof$', 'gestioncof.views.utile_cof'),
    url(r'^utile_bda$', 'gestioncof.views.utile_bda'),
    url(r'^utile_bda/bda_diff$', 'gestioncof.views.liste_bdadiff'),
    url(r'^utile_cof/diff_cof$', 'gestioncof.views.liste_diffcof'),
    url(r'^utile_bda/bda_revente$', 'gestioncof.views.liste_bdarevente'),
)
