from django import forms
from models import Project, Content
import uuid
from utils import generate_uuid
from django.forms.widgets import Widget
from django.contrib.admin import widgets as admin_widgets
from django.core.urlresolvers import reverse
from ldt.settings import BASE_URL
from ldt.forms import widgets as ldt_widgets

class LdtImportForm(forms.Form):
    importFile = forms.FileField()
    videoPath = forms.CharField(required=False)
    flatten = forms.BooleanField(required=False, initial=True)   
    
class LdtAddForm(forms.ModelForm):
    title = forms.CharField()
    # contents = forms.ModelMultipleChoiceField(Content.objects.all())
    # owner = forms.ModelChoiceField(Author.objects.all())
    class Meta:
        model = Project
        exclude = ("ldt_id", "ldt", "created_by", "changed_by", "creation_date", "modification_date", "state", "owner")   

class ReindexForm(forms.Form):
    contents = forms.ModelMultipleChoiceField(Content.objects.all())

class SearchForm(forms.Form):
    search = forms.CharField()
    field = forms.ChoiceField([(u"all", u"all"), (u"title", u"title"), (u"abstract", u"resume"), (u"tags", u"tags")])

class AddProjectForm (forms.Form):
    title = forms.CharField()

class CopyProjectForm (forms.Form):
    title = forms.CharField()
    

class ContentForm(forms.ModelForm):

    #iri_id = forms.CharField(max_length=1024, widget=forms.HiddenInput, initial=generate_uuid)
    iriurl = forms.CharField(max_length=1024, widget=forms.HiddenInput, required=False)
    content_creation_date = forms.SplitDateTimeField(widget=ldt_widgets.LdtSplitDateTime, required=False)
    
    def clean_iri_id(self):
        data = self.cleaned_data.get('iri_id')
        if not data:
            data = generate_uuid()
        return data
    
    def clean(self):
        cleaned_data = self.cleaned_data
        iriurl_data = cleaned_data.get('iriurl')
        iri_id_data = cleaned_data['iri_id']
        if not iriurl_data:
            iriurl_data = "%s/%s.iri" % (iri_id_data, iri_id_data)    
        cleaned_data['iriurl'] = iriurl_data
        return cleaned_data
    
    class Meta:
        model = Content
        exclude = ("creation_date", "update_date", "authors")
        widgets = {
                   'iri_id': forms.HiddenInput,
        }
        
    class Media:
        css = {
            'all' : ('admin/css/forms.css','admin/css/base.css', 'admin/css/base.css', 'admin/css/widgets.css')
               }
        
class MediaForm(forms.ModelForm):
    
    media_creation_date = forms.SplitDateTimeField(widget=ldt_widgets.LdtSplitDateTime, required=False)

    class Meta:
        model = Content
        exclude = ("creation_date", "update_date", "creator")
    
    class Media:
        css = {
            'all' : ('admin/css/forms.css','admin/css/base.css', 'admin/css/base.css', 'admin/css/widgets.css')
               }
