src/hp/forms.py
changeset 45 316a0101512e
parent 41 b6010b3d6ea8
child 65 6289931858a7
equal deleted inserted replaced
44:0931f368cb9a 45:316a0101512e
     3 Created on Nov 14, 2012
     3 Created on Nov 14, 2012
     4 
     4 
     5 @author: ymh
     5 @author: ymh
     6 '''
     6 '''
     7 
     7 
       
     8 from . import settings
       
     9 from .models import VideoKCRel
       
    10 from .utils import get_all_objects
     8 from django import forms
    11 from django import forms
     9 from .models import VideoKCRel
    12 import logging
    10 import requests
    13 
    11 from . import settings
    14 logger = logging.getLogger(__name__)
    12 
    15 
    13 class VideoKCRelForm(forms.ModelForm):
    16 class VideoKCRelForm(forms.ModelForm):
    14     
    17     
    15     iri_id = forms.CharField(max_length=255, widget=forms.widgets.Select()) 
    18     iri_id = forms.CharField(max_length=255, widget=forms.widgets.Select()) 
    16 
    19 
    17     def __init__(self, *args, **kwargs):
    20     def __init__(self, *args, **kwargs):
    18         super(VideoKCRelForm, self).__init__(*args, **kwargs)
    21         super(VideoKCRelForm, self).__init__(*args, **kwargs)
    19         
    22         
    20         url = settings.LDT_API_URL + "contents/"
    23         url = settings.LDT_API_URL + "contents/?limit=" + str(settings.LDT_MAX_FETCH)
    21         #limit=20&offset=20
    24         contents = get_all_objects(url, 'front_project')
    22         r = requests.get(url)        
    25         self.fields['iri_id'].widget.choices = [(content['iri_id'], content['title']) for content in contents]
    23         self.fields['iri_id'].widget.choices = [(content['iri_id'], content['title']) for content in r.json['objects']]
       
    24         
    26         
    25     class Meta:
    27     class Meta:
    26         model = VideoKCRel
    28         model = VideoKCRel
    27     
    29