Commit c67c7fe2 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[entities] Implement a specific adapter for File entity types

Related to #4753964.
parent 70deedd11ff0
......@@ -20,7 +20,7 @@ import re
import unicodedata
from urllib2 import urlopen
from cubicweb.predicates import relation_possible, adaptable
from cubicweb.predicates import relation_possible, adaptable, is_instance
from cubicweb.view import EntityAdapter
from cubes.ckanpublish.utils import ckan_post
......@@ -182,3 +182,14 @@ class DownloadableCKANResourceAdapter(CKANResourceAdapter):
"""Read content using IDownloadable adapter from URL."""
idownload = self.entity.cw_adapt_to('IDownloadable')
return urlopen(idownload.download_url())
class FileCKANResourceAdapter(DownloadableCKANResourceAdapter):
"""Adapter for File entities that can be mapped to a CKAN resource."""
__abstract__ = True
__select__ = (DownloadableCKANResourceAdapter.__select__ &
def read(self):
"""Read file content relying on File interface."""
return self.entity
from cubicweb.predicates import is_instance, relation_possible
from cubes.ckanpublish.entities import (CKANDatasetAdapter,
class CWDatasetCKANDatasetAdapter(CKANDatasetAdapter):
......@@ -12,9 +12,8 @@ class CWDatasetCKANDatasetAdapter(CKANDatasetAdapter):
return self.entity.maintainer[0]
class FileCKANResourceAdapter(DownloadableCKANResourceAdapter):
__select__ = (DownloadableCKANResourceAdapter.__select__ &
is_instance('File') &
class CWDatasetResourceCKANResourceAdapter(FileCKANResourceAdapter):
__select__ = (FileCKANResourceAdapter.__select__ &
relation_possible('resources', role='object'))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment