src/hp/forms.py
changeset 95 c63f2508c34d
parent 91 eb2aa2a469e2
equal deleted inserted replaced
94:88e08fd7a160 95:c63f2508c34d
    19     iri_id = forms.CharField(max_length=255, widget=forms.widgets.Select())
    19     iri_id = forms.CharField(max_length=255, widget=forms.widgets.Select())
    20     project_id =  forms.CharField(max_length=255, widget=forms.widgets.Select())    
    20     project_id =  forms.CharField(max_length=255, widget=forms.widgets.Select())    
    21 
    21 
    22     def __init__(self, *args, **kwargs):
    22     def __init__(self, *args, **kwargs):
    23         super(VideoKCRelForm, self).__init__(*args, **kwargs)
    23         super(VideoKCRelForm, self).__init__(*args, **kwargs)
    24         
    24                 
    25         url = settings.LDT_API_URL + "contents/"
    25         url = settings.LDT_API_URL + "contents/"
    26         contents = get_all_objects(url, {'limit':settings.LDT_MAX_FETCH}, 'front_project')
    26         contents = get_all_objects(url, {'limit':settings.LDT_MAX_FETCH}, 'front_project')
    27         self.fields['iri_id'].widget.choices = [(content['iri_id'], content['title']) for content in contents]
    27         
       
    28         #remove contents that already are associated        
       
    29         associated_rel = dict([(rel.iri_id, rel) for rel in VideoKCRel.objects.all()])
       
    30         
       
    31         self.fields['iri_id'].widget.choices = [(content['iri_id'], content['title']) for content in contents if (content['iri_id'] not in associated_rel) or (content['iri_id'] == self['iri_id'].value())]
    28         
    32         
    29         url = settings.LDT_API_URL + "projects/"
    33         url = settings.LDT_API_URL + "projects/"
    30         projects = get_all_objects(url, {'state': 2, 'limit': settings.LDT_MAX_FETCH}, None)
    34         projects = get_all_objects(url, {'state': 2, 'limit': settings.LDT_MAX_FETCH}, None)
    31         logger.debug("projects " + repr(projects))
       
    32         values = [(None, "-----")]
    35         values = [(None, "-----")]
    33         values.extend([(project['ldt_id'], project['title']) for project in projects])
    36         values.extend([(project['ldt_id'], project['title']) for project in projects])
    34         
    37         
    35         self.fields['project_id'].widget.choices = values
    38         self.fields['project_id'].widget.choices = values
    36         
    39