def get_type_title(self, obj): """Get type title.""" try: return ObjectType.get_by_dict(obj['upload_type'])['title']['en'] except Exception: from flask import current_app current_app.logger.exception("Failed object {}".format(obj['upload_type'])) raise
def is_openaire_publication(record): """Determine if record is a publication for OpenAIRE.""" oatype = ObjectType.get_by_dict(record.get('resource_type')).get( 'openaire', {}) if not oatype or oatype['type'] != _OAType.publication: return False # Has grants, is part of ecfunded community or is open access. if record.get('grants') or 'ecfunded' in record.get('communities', []) or \ 'open' == record.get('access_right'): return True return False
def is_openaire_publication(record): """Determine if record is a publication for OpenAIRE.""" oatype = ObjectType.get_by_dict(record.get('resource_type')).get( 'openaire', {}) if not oatype or oatype['type'] != _OAType.publication: return False # Has grants, is part of ecfunded community or is open access. if record.get('grants') or 'ecfunded' in record.get('communities', []) or \ 'open' == record.get('access_right'): return True return False
def validate_data(self, obj): """Validate resource type.""" type_ = obj.get('resource_type.type') if type_ in ['publication', 'image']: type_dict = { 'type': type_, 'subtype': obj.get('resource_type.subtype'), } field_names = ['{0}_type'.format(type_)] else: type_dict = {'type': type_} field_names = ['upload_type'] if ObjectType.get_by_dict(type_dict) is None: raise ValidationError( _('Invalid upload, publication or image type.'), field_names=field_names, )
def validate_data(self, obj): """Validate resource type.""" type_ = obj.get('resource_type.type') if type_ in ['publication', 'image']: type_dict = { 'type': type_, 'subtype': obj.get('resource_type.subtype'), } field_names = ['{0}_type'.format(type_)] else: type_dict = {'type': type_} field_names = ['upload_type'] if ObjectType.get_by_dict(type_dict) is None: raise ValidationError( _('Invalid upload, publication or image type.'), field_names=field_names, )
def validate_data(self, obj): """Validate resource type.""" type_ = obj.get('resource_type', {}).get('type') if type_ in ['publication', 'image']: type_dict = { 'type': type_, 'subtype': obj.get('resource_type', {}).get('subtype') } field_names = ['{0}_type'.format(type_)] else: type_dict = {'type': type_} field_names = ['upload_type'] if ObjectType.get_by_dict(type_dict) is None: raise ValidationError( _('Invalid upload, publication or image type.'), field_names=field_names, ) if not is_valid_openaire_type(obj.get('resource_type', {}), obj.get('communities', [])): raise ValidationError( _('Invalid OpenAIRE subtype.'), field_names=['openaire_subtype'], )
def validate_data(self, obj): """Validate resource type.""" type_ = obj.get('resource_type', {}).get('type') if type_ in ['publication', 'image']: type_dict = { 'type': type_, 'subtype': obj.get('resource_type', {}).get('subtype') } field_names = ['{0}_type'.format(type_)] else: type_dict = {'type': type_} field_names = ['upload_type'] if ObjectType.get_by_dict(type_dict) is None: raise ValidationError( _('Invalid upload, publication or image type.'), field_names=field_names, ) if not is_valid_openaire_type(obj.get('resource_type', {}), obj.get('communities', [])): raise ValidationError( _('Invalid OpenAIRE subtype.'), field_names=['openaire_subtype'], )
def _get_schema_class(self, obj): data = obj['metadata'] obj_type = ObjectType.get_by_dict(data['resource_type']) return getattr(schemas, obj_type['schema.org'][19:])
def _openaire_type(self, obj): return ObjectType.get_by_dict( obj.get('metadata', {}).get('resource_type') ).get('openaire')
def get_type(self, obj): """Get record CSL type.""" metadata = obj['metadata'] obj_type = ObjectType.get_by_dict(metadata.get('resource_type')) return obj_type.get('csl', missing) if obj_type else missing
def is_openaire_other(record): """Determine if the record has type 'other' for OpenAIRE.""" oatype = ObjectType.get_by_dict(record.get('resource_type')).get( 'openaire', {}) return oatype and oatype['type'] == _OAType.other
def is_openaire_software(record): """Determine if the record is a software for OpenAIRE.""" oatype = ObjectType.get_by_dict(record.get('resource_type')).get( 'openaire', {}) return oatype and oatype['type'] == _OAType.software
def is_openaire_dataset(record): """Determine if record is a dataset for OpenAIRE.""" oatype = ObjectType.get_by_dict(record.get('resource_type')).get( 'openaire', {}) return oatype and oatype['type'] == _OAType.dataset
def is_openaire_other(record): """Determine if the record has type 'other' for OpenAIRE.""" oatype = ObjectType.get_by_dict(record.get('resource_type')).get( 'openaire', {}) return oatype and oatype['type'] == _OAType.other
def _get_schema_class(self, obj): data = obj['metadata'] obj_type = ObjectType.get_by_dict(data['resource_type']) return getattr(schemas, obj_type['schema.org'][19:])
def is_openaire_software(record): """Determine if the record is a software for OpenAIRE.""" oatype = ObjectType.get_by_dict(record.get('resource_type')).get( 'openaire', {}) return oatype and oatype['type'] == _OAType.software
def get_type(self, obj): """Get record CSL type.""" metadata = obj['metadata'] obj_type = ObjectType.get_by_dict(metadata.get('resource_type')) return obj_type.get('csl', 'article') if obj_type else 'article'
def is_openaire_dataset(record): """Determine if record is a dataset for OpenAIRE.""" oatype = ObjectType.get_by_dict(record.get('resource_type')).get( 'openaire', {}) return oatype and oatype['type'] == _OAType.dataset
def _openaire_type(self, obj): return ObjectType.get_by_dict( obj.get('metadata', {}).get('resource_type')).get('openaire')