from django.conf import settings
#from django.contrib.auth.models import Group, User
#from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.shortcuts import render_to_response
from django.template import RequestContext
from sorl.thumbnail.images import ImageFile
from django.core.files.storage import FileSystemStorage



def home(request):
    
    im1 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/00-004125.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 1", "author":"juju"}
    im2 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/00-004543.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 2", "author":"loulou"}
    im3 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/01-017513.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 3", "author":"juju"}
    im4 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/02-009258.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 4", "author":"loulou"}
    img_list = [im1,im2,im3,im4,im3,im4,im1,im2]
    
    frg1 = {"image": im2, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"Fragment X", "author":"juju"}
    frg2 = {"image": im3, "path":"M .1 .3 L .5 .1 L .8 .7 Z", "title":"Fragment Y", "author":"loulou"}
    frg3 = {"image": im4, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"Fragment Z", "author":"juju"}
    frg4 = {"image": im1, "path":"M .2 .5 L .7 .2 L .8 .7 Z", "title":"Fragment W", "author":"loulou"}
    frg_list = [frg1,frg2,frg3,frg4,frg3,frg4,frg1,frg2]
    
    return render_to_response("egonomy_home.html",
                              {'img_list': img_list, 'fragment_list': frg_list},
                              context_instance=RequestContext(request))


def annotate_picture(request):

    im1 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/03-007695.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 1", "author":"juju"}
    im2 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/03-007696.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 2", "author":"loulou"}
    im3 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/03-007697.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 3", "author":"juju"}
    im4 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/03-007698.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 4", "author":"loulou"}
    img_list = [im1,im2,im3,im4]
    from random import choice
    im = choice(img_list)
    im.update({"description":"Ceci est la description de l'oeuvre representee dans l'image",
               "author":"Marcel Duchamp",
               "period":"XXeme siecle",
               "production_site":"Paris, France",
               "localization":"Musee du Louvre, Paris",
               "rmn_keywords":"Art contemporain, Art conceptuel, Cyclisme",
               "users_keywords":"Modernite, Ready-made"})
    
    frg1 = {"image": im, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"Fragment X", "author":"juju"}
    frg2 = {"image": im, "path":"M .1 .3 L .5 .1 L .8 .7 Z", "title":"Fragment Y", "author":"loulou"}
    frg3 = {"image": im, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"Fragment Z", "author":"juju"}
    frg4 = {"image": im, "path":"M .2 .5 L .7 .2 L .8 .7 Z", "title":"Fragment W", "author":"loulou"}
    frg_list = [frg1,frg2,frg3,frg4,frg3,frg4,frg1,frg4,frg3,frg4,frg1,frg2]
    
    return render_to_response("egonomy_annotate_picture.html",
                              {'image': im, 'fragment_list': frg_list},
                              context_instance=RequestContext(request))


def view_fragment(request):
    
    im1 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/04-000035.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 1", "author":"juju"}
    im2 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/04-000038.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 2", "author":"loulou"}
    im3 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/05-513007.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 3", "author":"juju"}
    im4 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/05-513027.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 4", "author":"loulou"}
    img_list = [im1,im2,im3,im4]
    from random import choice
    im = choice(img_list)
    im.update({"description":"Ceci est la description de l'oeuvre representee dans l'image",
               "author":"Marcel Duchamp",
               "period":"XXeme siecle",
               "production_site":"Paris, France",
               "localization":"Musee du Louvre, Paris",
               "rmn_keywords":"Art contemporain, Art conceptuel, Cyclisme",
               "users_keywords":"Modernite, Ready-made"})
    
    frg1 = {"image": im, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"Fragment X", "author":"juju", "users_keywords":"Modernite, Ready-made"}
    frg2 = {"image": im, "path":"M .1 .3 L .5 .1 L .8 .7 Z", "title":"Fragment Y", "author":"loulou", "users_keywords":"Modernite, Ready-made"}
    frg3 = {"image": im, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"Fragment Z", "author":"juju", "users_keywords":"Modernite, Ready-made"}
    frg4 = {"image": im, "path":"M .2 .5 L .7 .2 L .8 .7 Z", "title":"Fragment W", "author":"loulou", "users_keywords":"Modernite, Ready-made"}
    frg_list = [frg1,frg2,frg3,frg3,frg4,frg4,frg3,frg4,frg1,frg4,frg1]
    frg = choice(frg_list)
    
    return render_to_response("egonomy_view_fragment.html",
                              {'fragment': frg, 'fragment_list': frg_list},
                              context_instance=RequestContext(request))


def create_fragment(request):
    
    im1 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/08-551797.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 1", "author":"juju"}
    im2 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/09-508948.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 2", "author":"loulou"}
    im3 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/09-509002.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 3", "author":"juju"}
    im4 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/09-510583.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 4", "author":"loulou"}
    img_list = [im1,im2,im3,im4]
    from random import choice
    im = choice(img_list)
    im.update({"description":"Ceci est la description de l'oeuvre representee dans l'image",
               "author":"Marcel Duchamp",
               "period":"XXeme siecle",
               "production_site":"Paris, France",
               "localization":"Musee du Louvre, Paris",
               "rmn_keywords":"Art contemporain, Art conceptuel, Cyclisme",
               "users_keywords":"Modernite, Ready-made"})
    
    frg1 = {"image": im, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"Fragment X", "author":"juju"}
    frg2 = {"image": im, "path":"M .1 .3 L .5 .1 L .8 .7 Z", "title":"Fragment Y", "author":"loulou"}
    frg3 = {"image": im, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"Fragment Z", "author":"juju"}
    frg4 = {"image": im, "path":"M .2 .5 L .7 .2 L .8 .7 Z", "title":"Fragment W", "author":"loulou"}
    frg_list = [frg1,frg2,frg3,frg4,frg3,frg4,frg1,frg4,frg3,frg4,frg1,frg2]
    
    
    return render_to_response("egonomy_create_fragment.html",
                              {'image': im, 'fragment_list': frg_list},
                              context_instance=RequestContext(request))



