from django.template.context import RequestContext
from django.shortcuts import render_to_response, get_object_or_404
from darkroom.models import Gallery, Photo, Movie, Slideshow, Webcam

def index(request):
    try:
        photos=Photo.objects.published().filter(gallery_photos=None).order_by('-created')[:3]
    except:
        pass
    try:
        galleries=Gallery.objects.published().order_by('-created')[:5]
    except:
        pass
    try:
	slideshows=Slideshow.objects.published().order_by('-created')[:1]
    except:
        pass
    try:
        movies=Movie.objects.published().order_by('-created')[:3]
    except:
        pass
    return render_to_response('darkroom/index.html', locals(),
                              context_instance=RequestContext(request))

def photo_lightbox(request, slug):
    object=get_object_or_404(Photo, slug=slug)
    return render_to_response('darkroom/photo_lightbox_detail.html', locals(),
                              context_instance=RequestContext(request))
  
def movie_index(request):
    try:
        movies=Movie.objects.filter(published=True)
        slideshows=Slideshow.objects.filter(published=True)
    except:
        pass
    return render_to_response('darkroom/movie_index.html', locals(),
                                  context_instance=RequestContext(request))
                              
def movie_detail(request, slug):
    object=get_object_or_404(Movie, slug=slug)
    return render_to_response('darkroom/movie_detail.html', locals(),
                              context_instance=RequestContext(request))
                              
def slideshow_index(request):
    try:
        slideshows=Slideshow.objects.filter(published=True)
    except:
        pass
    return render_to_response('darkroom/slideshow_index.html', locals(),
                                  context_instance=RequestContext(request))

def slideshow_detail(request, slug):
    object=get_object_or_404(Slideshow, slug=slug)
    size=object.size.split('x')
    width=size[0]
    height=size[1]
    return render_to_response('darkroom/slideshow_detail.html', locals(),
                                                            context_instance=RequestContext(request))                        

def gallery_detail(request, slug):
    object=get_object_or_404(Gallery, slug=slug)
    return render_to_response('darkroom/gallery_detail.html', locals(),
                                                            context_instance=RequestContext(request))                        

def webcam_detail(request, slug):
    object=get_object_or_404(Webcam, slug=slug)
    return render_to_response('darkroom/webcam_detail.html', locals(),
                                                            context_instance=RequestContext(request))                        
