from django.conf import settings
from django.conf.urls.defaults import *
from models import *
from darkroom import views as dr_views
from darkroom.feeds import LatestPhotosFeed

# Number of random images from the gallery to display.
SAMPLE_SIZE = ":%s" % getattr(settings, "GALLERY_SAMPLE_SIZE", 5)

# galleries
gallery_args = {
    "date_field": "published_on",
    "allow_empty": True,
    "queryset": Gallery.objects.published(),
    "extra_context": {"sample_size": SAMPLE_SIZE},
}
urlpatterns = patterns(
    "django.views.generic.date_based",
    url(
        r"^gallery/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[\-\d\w]+)/$",
        "object_detail",
        {
            "date_field": "published_on",
            "slug_field": "slug",
            "queryset": Gallery.objects.published(),
            "extra_context": {"sample_size": SAMPLE_SIZE},
        },
        name="dr-gallery-detail",
    ),
    url(
        r"^gallery/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$",
        "archive_day",
        gallery_args,
        name="dr-gallery-index-day",
    ),
    url(
        r"^gallery/(?P<year>\d{4})/(?P<month>[a-z]{3})/$",
        "archive_month",
        gallery_args,
        name="dr-gallery-index-month",
    ),
    url(
        r"^gallery/(?P<year>\d{4})/$",
        "archive_year",
        gallery_args,
        name="dr-gallery-index-year",
    ),
    url(r"^galleries/?$", "archive_index", gallery_args, name="dr-gallery-index"),
)
# urlpatterns += patterns('django.views.generic.list_detail',
#    url(r'^galleries/(?P<slug>[\-\d\w]+)/$', 'object_detail', {'slug_field': 'slug', 'queryset': Gallery.objects.filter(published=True), 'extra_context':{'sample_size':SAMPLE_SIZE}}, name='dr-gallery'),
#    url(r'^gallery/page/(?P<page>[0-9]+)/$', 'object_list', {'queryset': Gallery.objects.filter(published=True), 'allow_empty': True, 'paginate_by': 5, 'extra_context':{'sample_size':SAMPLE_SIZE}}, name='dr-gallery-list'),
# )
# photographs
photo_args = {
    "date_field": "published_on",
    "allow_empty": True,
    "queryset": Photo.objects.published(),
}
urlpatterns += patterns(
    "django.views.generic.date_based",
    url(
        r"^photos/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[\-\d\w]+)/$",
        "object_detail",
        {
            "date_field": "published_on",
            "slug_field": "slug",
            "queryset": Photo.objects.published(),
        },
        name="dr-photo-detail",
    ),
    url(
        r"^photos/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$",
        "archive_day",
        photo_args,
        name="dr-photo-archive-day",
    ),
    url(
        r"^photos/(?P<year>\d{4})/(?P<month>[a-z]{3})/$",
        "archive_month",
        photo_args,
        name="dr-photo-archive-month",
    ),
    url(
        r"^photos/(?P<year>\d{4})/$",
        "archive_year",
        photo_args,
        name="dr-photo-archive-year",
    ),
    url(r"^photos/$", "archive_index", photo_args, name="dr-photo-archive"),
)

# urlpatterns += patterns('django.views.generic.list_detail',
#    url(r'^photos/(?P<slug>[\-\d\w]+)/$', 'object_detail', {'slug_field': 'slug', 'queryset': Photo.objects.filter(published=True)}, name='dr-photo-no-date'),
#    url(r'^photos/page/(?P<page>[0-9]+)/$', 'object_list', {'queryset': Photo.objects.filter(published=True), 'allow_empty': True, 'paginate_by': 20}, name='dr-photo-list'),
# )

# graphics
graphic_args = {
    "date_field": "created",
    "allow_empty": True,
    "queryset": Graphic.objects.filter(published=True),
}
urlpatterns += patterns(
    "django.views.generic.date_based",
    url(
        r"^graphics/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[\-\d\w]+)/$",
        "object_detail",
        {
            "date_field": "created",
            "slug_field": "slug",
            "queryset": Photo.objects.filter(published=True),
        },
        name="dr-graphic-detail",
    ),
    url(
        r"^graphics/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$",
        "archive_day",
        photo_args,
        name="dr-graphic-index--day",
    ),
    url(
        r"^graphics/(?P<year>\d{4})/(?P<month>[a-z]{3})/$",
        "archive_month",
        photo_args,
        name="dr-graphic-index-month",
    ),
    url(
        r"^graphics/(?P<year>\d{4})/$",
        "archive_year",
        photo_args,
        name="dr-graphic-index-year",
    ),
    url(r"^graphics/$", "archive_index", photo_args, name="dr-graphic-index"),
)

urlpatterns += patterns(
    "darkroom.views",
    url(r"^photos.xml", LatestPhotosFeed(), name="nr-photo-feed"),
    url(r"^$", view=dr_views.index, name="dr-index"),
    url(r"^movies/$", view=dr_views.movie_index, name="dr-movie-index"),
    url(
        r"^movies/(?P<slug>[\-\d\w]+)/$",
        view=dr_views.movie_detail,
        name="dr-movie-detail",
    ),
    url(r"^slideshows/$", view=dr_views.slideshow_index, name="dr-slideshow-index"),
    url(
        r"^slideshows/(?P<slug>[\-\d\w]+)/$",
        view=dr_views.slideshow_detail,
        name="dr-slideshow-detail",
    ),
    url(
        r"^photos/(?P<slug>[\-\d\w]+)/lightbox/$",
        view=dr_views.photo_lightbox,
        name="dr-photo-lightbox",
    ),
    # url(r'^webcams/$', view=dr_views.webcam_index, name="dr-webcam-index"),
    url(
        r"^webcams/(?P<slug>[\-\d\w]+)/$",
        view=dr_views.webcam_detail,
        name="dr-webcam-detail",
    ),
)
