--- a/src/ldt/ldt/api/ldt/resources/content.py Fri Jan 20 10:43:30 2017 +0100
+++ b/src/ldt/ldt/api/ldt/resources/content.py Sat Jan 21 01:26:24 2017 +0100
@@ -33,6 +33,18 @@
else:
return bundle_or_obj.videopath + bundle_or_obj.stream_src
+class ContentStatResource(ModelResource):
+
+ nb_annotations = fields.IntegerField(attribute='nb_annotations')
+ last_annotated = fields.DateTimeField(attribute='last_annotated')
+ annotation_volume_str = fields.CharField(attribute='annotation_volume_str')
+ polemics_volume_str = fields.CharField(attribute='polemics_volume_str')
+ class Meta:
+ resource_name = 'content_stats'
+ include_resource_uri = False
+
+
+
"""
Content Resource definition.
The following urls are defined:
@@ -71,12 +83,14 @@
front_project = fields.ForeignKey('ldt.api.ldt.resources.ProjectResource','front_project', null=True, full=False)
media_url = fields.ForeignKey('ldt.api.ldt.resources.content.MediaResource','media_obj', null=True, full=False)
+ stats = fields.OneToOneField('ldt.api.ldt.resources.content.ContentStatResource', 'stat_annotation', full=True)
+ tag_list = fields.ListField(readonly=True)
class Meta:
allowed_methods = ['get']
resource_name = 'contents'
authentication = MultiAuthentication(ApiKeyAuthentication(), SessionAuthentication())
- queryset = Content.objects.select_related('front_project','media_obj').all()
+ queryset = Content.objects.prefetch_related('tags').select_related('front_project','media_obj', 'stat_annotation').all()
filtering = {
'tags' : ALL_WITH_RELATIONS,
'title' : ALL,
@@ -84,7 +98,7 @@
ordering = ['title', 'creation_date', 'content_creation_date']
def get_object_list(self, request):
- return Content.safe_objects.select_related('front_project', 'media_obj').all()
+ return Content.safe_objects.select_related('front_project', 'media_obj', 'stat_annotation').prefetch_related('tags').all()
def prepend_urls(self):
return [
@@ -192,4 +206,7 @@
return qs
+ def dehydrate_tag_list(self, bundle):
+ return [t.name for t in bundle.obj.tags.all()]
+