equal
deleted
inserted
replaced
8 from . import settings |
8 from . import settings |
9 from .models import VideoKCRel |
9 from .models import VideoKCRel |
10 from .utils import get_all_objects |
10 from .utils import get_all_objects |
11 from django import forms |
11 from django import forms |
12 import logging |
12 import logging |
|
13 import requests |
13 |
14 |
14 logger = logging.getLogger(__name__) |
15 logger = logging.getLogger(__name__) |
15 |
16 |
16 class VideoKCRelForm(forms.ModelForm): |
17 class VideoKCRelForm(forms.ModelForm): |
17 |
18 |
18 iri_id = forms.CharField(max_length=255, widget=forms.widgets.Select()) |
19 iri_id = forms.CharField(max_length=255, widget=forms.widgets.Select()) |
19 project_id = forms.CharField(max_length=255, widget=forms.widgets.Select()) |
20 project_id = forms.CharField(max_length=255, widget=forms.widgets.Select()) |
20 |
21 |
21 def __init__(self, *args, **kwargs): |
22 def __init__(self, *args, **kwargs): |
22 super(VideoKCRelForm, self).__init__(*args, **kwargs) |
23 super(VideoKCRelForm, self).__init__(*args, **kwargs) |
23 |
24 |
24 url = settings.LDT_API_URL + "contents/" |
25 url = settings.LDT_API_URL + "contents/" |
30 logger.debug("projects " + repr(projects)) |
31 logger.debug("projects " + repr(projects)) |
31 values = [(None, "-----")] |
32 values = [(None, "-----")] |
32 values.extend([(project['ldt_id'], project['title']) for project in projects]) |
33 values.extend([(project['ldt_id'], project['title']) for project in projects]) |
33 |
34 |
34 self.fields['project_id'].widget.choices = values |
35 self.fields['project_id'].widget.choices = values |
|
36 |
|
37 self.fields['content_title'].widget.attrs['readonly'] = True |
35 |
38 |
|
39 def clean_content_title(self): |
|
40 iri_id = self.cleaned_data['iri_id'] |
|
41 url = settings.LDT_API_URL + "contents/%s/" % iri_id |
|
42 |
|
43 r = requests.get(url) |
|
44 if r.status_code != requests.codes.ok: #@UndefinedVariable |
|
45 logger.error("Error when requesting contents " + repr(r.status_code) + " : " + repr(r.text)) |
|
46 raise forms.ValidationError("Unable to request content %s" % url) |
|
47 return r.json.get('title', None) |
|
48 |
36 |
49 |
37 class Meta: |
50 class Meta: |
38 model = VideoKCRel |
51 model = VideoKCRel |
39 |
52 |