def add_multiple_references(SerializerClass, user, data, parent_resource, host_url): expressions = data.get('expressions', []) concept_expressions = data.get('concepts', []) mapping_expressions = data.get('mappings', []) uri = data.get('uri') search_term = data.get('search_term', '') if '*' in [concept_expressions, mapping_expressions]: ResourceContainer = SourceVersion if uri.split('/')[3] == 'sources' else CollectionVersion if concept_expressions == '*': url = host_url + uri + 'concepts?q=' + search_term view = ConceptVersionListView.as_view() request = APIRequestFactory().get(url) response = view(request) response.render() concepts_dict = json.loads(response.content) concept_uris = [c['url'] for c in concepts_dict] concepts = Concept.objects.filter(uri__in=concept_uris) expressions.extend(map(lambda c: c.uri, concepts)) else: expressions.extend(concept_expressions) if mapping_expressions == '*': url = host_url + uri + 'mappings?q=' + search_term view = MappingListView.as_view() request = APIRequestFactory().get(url) response = view(request) response.render() mappings_dict = json.loads(response.content) mapping_uris = [c['url'] for c in mappings_dict] mappings = Mapping.objects.filter(uri__in=mapping_uris) expressions.extend(map(lambda m: m.uri, mappings)) else: expressions.extend(mapping_expressions) expressions = set(expressions) prev_refs = parent_resource.references save_kwargs = { 'force_update': True, 'expressions': expressions, 'user': user } serializer = SerializerClass(parent_resource, partial=True) serializer.save(**save_kwargs) update_collection_in_solr.delay( serializer.object.get_head().id, CollectionReference.diff(serializer.object.references, prev_refs) ) if 'references' in serializer.errors: serializer.object.save() diff = map(lambda ref: ref.expression, CollectionReference.diff(serializer.object.references, prev_refs)) errors = serializer.errors.get('references', []) return diff, errors
def add_references(self, SerializerClass, user, data, collection, host_url, cascade_mappings=False): from concepts.models import Concept from mappings.models import Mapping from concepts.views import ConceptVersionListView from mappings.views import MappingListView from collection.models import CollectionReferenceUtils collection.get_head().add_processing(self.request.id) expressions = data.get('expressions', []) concept_expressions = data.get('concepts', []) mapping_expressions = data.get('mappings', []) uri = data.get('uri') search_term = data.get('search_term', '') if concept_expressions == '*': url = host_url + uri + 'concepts?q=' + search_term + '&limit=0' view = ConceptVersionListView.as_view() request = APIRequestFactory().get(url) response = view(request) response.render() concepts_dict = json.loads(response.content) concept_uris = [c['url'] for c in concepts_dict] concepts = Concept.objects.filter(uri__in=concept_uris) expressions.extend(map(lambda c: c.uri, concepts)) else: expressions.extend(concept_expressions) if mapping_expressions == '*': url = host_url + uri + 'mappings?q=' + search_term + '&limit=0' view = MappingListView.as_view() request = APIRequestFactory().get(url) response = view(request) response.render() mappings_dict = json.loads(response.content) mapping_uris = [c['url'] for c in mappings_dict] mappings = Mapping.objects.filter(uri__in=mapping_uris) expressions.extend(map(lambda m: m.uri, mappings)) else: expressions.extend(mapping_expressions) expressions = set(expressions) if cascade_mappings: all_related_mappings = CollectionReferenceUtils.get_all_related_mappings(expressions, collection) expressions = expressions.union(all_related_mappings) added_references, errors = collection.add_references_in_bulk(expressions) update_collection_in_solr.delay( collection.get_head().id, added_references ) collection.get_head().remove_processing(self.request.id) return added_references, errors
def add_multiple_references(SerializerClass, user, data, parent_resource, host_url): expressions = data.get('expressions', []) concept_expressions = data.get('concepts', []) mapping_expressions = data.get('mappings', []) uri = data.get('uri') search_term = data.get('search_term', '') if '*' in [concept_expressions, mapping_expressions]: ResourceContainer = SourceVersion if uri.split( '/')[3] == 'sources' else CollectionVersion if concept_expressions == '*': url = host_url + uri + 'concepts?q=' + search_term view = ConceptVersionListView.as_view() request = APIRequestFactory().get(url) response = view(request) response.render() concepts_dict = json.loads(response.content) concept_uris = [c['url'] for c in concepts_dict] concepts = Concept.objects.filter(uri__in=concept_uris) expressions.extend(map(lambda c: c.uri, concepts)) else: expressions.extend(concept_expressions) if mapping_expressions == '*': url = host_url + uri + 'mappings?q=' + search_term view = MappingListView.as_view() request = APIRequestFactory().get(url) response = view(request) response.render() mappings_dict = json.loads(response.content) mapping_uris = [c['url'] for c in mappings_dict] mappings = Mapping.objects.filter(uri__in=mapping_uris) expressions.extend(map(lambda m: m.uri, mappings)) else: expressions.extend(mapping_expressions) expressions = set(expressions) prev_refs = parent_resource.references save_kwargs = { 'force_update': True, 'expressions': expressions, 'user': user } serializer = SerializerClass(parent_resource, partial=True) serializer.save(**save_kwargs) update_collection_in_solr.delay( serializer.object.get_head().id, CollectionReference.diff(serializer.object.references, prev_refs)) if 'references' in serializer.errors: serializer.object.save() return serializer.errors['references']
CONCEPT_ID_PATTERN + ')/$', ConceptExtraRetrieveUpdateDestroyView.as_view(), name='concept-extra'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/(?P<concept_version>' + NAMESPACE_PATTERN + ')/names/$', ConceptNameListCreateView.as_view(), name='concept-names'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/(?P<concept_version>' + NAMESPACE_PATTERN + ')/names/(?P<uuid>' + NAMESPACE_PATTERN + ')/$', ConceptNameRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/mappings/$', MappingListView.as_view(), name='mapping-list'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/mappings/(?P<mapping>' + NAMESPACE_PATTERN + ')/versions/$', MappingVersionsListView.as_view(), name='mapping-version-list'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/mappings/(?P<mapping>' + NAMESPACE_PATTERN + ')/$', MappingDetailView.as_view(), name='mapping-detail'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/mappings/(?P<mapping>' + NAMESPACE_PATTERN + ')/(?P<mapping_version>' + NAMESPACE_PATTERN + ')/$', MappingVersionDetailView.as_view(), name='mappingversion-detail'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/versions/$',
url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/descriptions/$', ConceptDescriptionListCreateView.as_view(), name='concept-descriptions'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/descriptions/(?P<uuid>[a-zA-Z0-9\-\.]+)/$', ConceptDescriptionRetrieveUpdateDestroyView.as_view(), name='concept-description'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/extras/$', ConceptExtrasView.as_view(), name='concept-extras'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/extras/(?P<extra>[_a-zA-Z0-9\-\.]+)/$', ConceptExtraRetrieveUpdateDestroyView.as_view(), name='concept-extra'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/names/$', ConceptNameListCreateView.as_view(), name='concept-names'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/names/(?P<uuid>[a-zA-Z0-9\-\.]+)/$', ConceptNameRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/versions/$', ConceptVersionsView.as_view(), name='concept-version-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/mappings/$', ConceptMappingsView.as_view(), name='concept-mapping-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/$', ConceptVersionRetrieveView.as_view(), name='conceptversion-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/descriptions/$', ConceptDescriptionListCreateView.as_view(), name='concept-descriptions'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/descriptions/(?P<uuid>[a-zA-Z0-9\-\.]+)/$', ConceptDescriptionRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/extras/$', ConceptExtrasView.as_view(), name='concept-extras'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/extras/(?P<extra>[_a-zA-Z0-9\-\.]+)/$', ConceptExtraRetrieveUpdateDestroyView.as_view(), name='concept-extra'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/names/$', ConceptNameListCreateView.as_view(), name='concept-names'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/names/(?P<uuid>[a-zA-Z0-9\-\.]+)/$', ConceptNameRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/$', MappingListView.as_view(), name='mapping-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/$', MappingDetailView.as_view(), name='mapping-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/versions/$', SourceVersionListView.as_view(), extra_kwargs, name='user-sourceversion-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/latest/$', SourceVersionRetrieveUpdateView.as_view(), {'user_is_self': True, 'is_latest': True}, name='user-sourceversion-latest'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/$', SourceVersionRetrieveUpdateDestroyView.as_view(), extra_kwargs, name='user-sourceversion-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/children/$', SourceVersionChildListView.as_view(), extra_kwargs, name='user-sourceversion-child-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/concepts/$', ConceptCreateView.as_view(), name='concept-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/$', ConceptRetrieveUpdateDestroyView.as_view(), name='concept-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/mappings/$', MappingListView.as_view(), name='mapping-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/$', MappingListView.as_view(), name='mapping-detail'), url(r'^collections/$', CollectionListView.as_view(), extra_kwargs, name='user-collection-list'), url(r'^collections/(?P<collection>[a-zA-Z0-9\-\.]+)/$', CollectionRetrieveUpdateDestroyView.as_view(), extra_kwargs, name='user-collection-detail'), url(r'^collections/(?P<collection>[a-zA-Z0-9\-\.]+)/concepts/$', ConceptReferenceListCreateView.as_view(), name='user-collection-concepts'), url(r'^collections/(?P<collection>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/$', ConceptReferenceRetrieveUpdateDestroyView.as_view(), name='user-collection-concept'), url(r'^collections/(?P<collection>[a-zA-Z0-9\-\.]+)/versions/$', CollectionVersionListView.as_view(), extra_kwargs, name='user-sourceversion-list'),
from django.conf.urls import patterns, url from mappings.views import MappingListView, MappingDetailView, MappingVersionDetailView, MappingVersionsListView, MappingVersionsView from oclapi.models import NAMESPACE_PATTERN, CONCEPT_ID_PATTERN __author__ = 'misternando' urlpatterns = patterns('', url(r'^$', MappingListView.as_view(), name='mapping-list'), url(r'^(?P<mapping>' + NAMESPACE_PATTERN + ')/$', MappingDetailView.as_view(), name='mapping-detail'), url(r'^(?P<mapping>' + NAMESPACE_PATTERN + ')/versions/$', MappingVersionsView.as_view(), name='mapping-version-list'), url(r'^(?P<mapping>' + NAMESPACE_PATTERN + ')/(?P<mapping_version>' + NAMESPACE_PATTERN + ')/$', MappingVersionDetailView.as_view(), name='mappingversion-detail'), )
ConceptDescriptionRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/extras/$', ConceptExtrasView.as_view(), name='concept-extras'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/extras/(?P<extra>[_a-zA-Z0-9\-\.]+)/$', ConceptExtraRetrieveUpdateDestroyView.as_view(), name='concept-extra'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/names/$', ConceptNameListCreateView.as_view(), name='concept-names'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/names/(?P<uuid>[a-zA-Z0-9\-\.]+)/$', ConceptNameRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/$', MappingListView.as_view(), name='mapping-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/versions/$', MappingVersionsListView.as_view(), name='mapping-version-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/$', MappingDetailView.as_view(), name='mapping-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/(?P<mapping_version>[a-zA-Z0-9\-\.]+)/$', MappingVersionDetailView.as_view(), name='mappingversion-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/versions/$', SourceVersionListView.as_view(), extra_kwargs, name='user-sourceversion-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/latest/$',
url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/$', ConceptRetrieveUpdateDestroyView.as_view(), name='concept-detail'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/descriptions/$', ConceptDescriptionListCreateView.as_view(), name='concept-descriptions'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/descriptions/(?P<uuid>' + NAMESPACE_PATTERN + ')/$', ConceptDescriptionRetrieveUpdateDestroyView.as_view(), name='concept-description'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/extras/$', ConceptExtrasView.as_view(), name='concept-extras'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/extras/(?P<extra>' + CONCEPT_ID_PATTERN + ')/$', ConceptExtraRetrieveUpdateDestroyView.as_view(), name='concept-extra'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/names/$', ConceptNameListCreateView.as_view(), name='concept-names'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/names/(?P<uuid>' + NAMESPACE_PATTERN + ')/$', ConceptNameRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/versions/$', ConceptVersionsView.as_view(), name='concept-version-list'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/mappings/$', ConceptMappingsView.as_view(), name='concept-mapping-list'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/(?P<concept_version>' + NAMESPACE_PATTERN + ')/$', ConceptVersionRetrieveView.as_view(), name='conceptversion-detail'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/(?P<concept_version>' + NAMESPACE_PATTERN + ')/descriptions/$', ConceptDescriptionListCreateView.as_view(), name='concept-descriptions'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/(?P<concept_version>' + NAMESPACE_PATTERN + ')/descriptions/(?P<uuid>' + NAMESPACE_PATTERN + ')/$', ConceptDescriptionRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/(?P<concept_version>' + NAMESPACE_PATTERN + ')/extras/$', ConceptExtrasView.as_view(), name='concept-extras'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/(?P<concept_version>' + NAMESPACE_PATTERN + ')/extras/(?P<extra>' + CONCEPT_ID_PATTERN + ')/$', ConceptExtraRetrieveUpdateDestroyView.as_view(), name='concept-extra'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/(?P<concept_version>' + NAMESPACE_PATTERN + ')/names/$', ConceptNameListCreateView.as_view(), name='concept-names'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/(?P<concept_version>' + NAMESPACE_PATTERN + ')/names/(?P<uuid>' + NAMESPACE_PATTERN + ')/$', ConceptNameRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/mappings/$', MappingListView.as_view(), name='mapping-list'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/mappings/(?P<mapping>' + NAMESPACE_PATTERN + ')/versions/$', MappingVersionsListView.as_view(), name='mapping-version-list'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/mappings/(?P<mapping>' + NAMESPACE_PATTERN + ')/$', MappingDetailView.as_view(), name='mapping-detail'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/mappings/(?P<mapping>' + NAMESPACE_PATTERN + ')/(?P<mapping_version>' + NAMESPACE_PATTERN + ')/$', MappingVersionDetailView.as_view(), name='mappingversion-detail'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/versions/$', SourceVersionListView.as_view(), extra_kwargs, name='user-sourceversion-list'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/latest/$', SourceVersionRetrieveUpdateView.as_view(), {'user_is_self': True, 'is_latest': True}, name='user-sourceversion-latest'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/(?P<version>' + NAMESPACE_PATTERN + ')/$', SourceVersionRetrieveUpdateDestroyView.as_view(), extra_kwargs, name='user-sourceversion-detail'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/(?P<version>' + NAMESPACE_PATTERN + ')/children/$', SourceVersionChildListView.as_view(), extra_kwargs, name='user-sourceversion-child-list'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/(?P<version>' + NAMESPACE_PATTERN + ')/concepts/$', ConceptCreateView.as_view(), name='concept-list'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/(?P<version>' + NAMESPACE_PATTERN + ')/concepts/(?P<concept>' + CONCEPT_ID_PATTERN + ')/$', ConceptRetrieveUpdateDestroyView.as_view(), name='concept-detail'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/(?P<version>' + NAMESPACE_PATTERN + ')/mappings/$', MappingListView.as_view(), name='mapping-list'), url(r'^sources/(?P<source>' + NAMESPACE_PATTERN + ')/(?P<version>' + NAMESPACE_PATTERN + ')/mappings/(?P<mapping>' + NAMESPACE_PATTERN + ')/$', MappingListView.as_view(), name='mapping-detail'), url(r'^collections/', include('collection.urls')) )
from django.conf.urls import patterns, url from mappings.views import MappingListView, MappingDetailView, MappingVersionDetailView, MappingVersionsListView, MappingVersionsView __author__ = 'misternando' urlpatterns = patterns( '', url(r'^$', MappingListView.as_view(), name='mapping-list'), url(r'^(?P<mapping>[a-zA-Z0-9\-\.]+)/$', MappingDetailView.as_view(), name='mapping-detail'), url(r'^(?P<mapping>[a-zA-Z0-9\-\.]+)/versions/$', MappingVersionsView.as_view(), name='mapping-version-list'), url(r'^(?P<mapping>[a-zA-Z0-9\-\.]+)/(?P<mapping_version>[a-zA-Z0-9\-\.]+)/$', MappingVersionDetailView.as_view(), name='mappingversion-detail'), )
def add_references(SerializerClass, user, data, parent_resource, host_url, cascade_mappings=False): from concepts.models import Concept from mappings.models import Mapping from collection.models import CollectionVersion from sources.models import SourceVersion from concepts.views import ConceptVersionListView from mappings.views import MappingListView from collection.models import CollectionReferenceUtils from collection.models import CollectionReference expressions = data.get('expressions', []) concept_expressions = data.get('concepts', []) mapping_expressions = data.get('mappings', []) uri = data.get('uri') search_term = data.get('search_term', '') if '*' in [concept_expressions, mapping_expressions]: ResourceContainer = SourceVersion if uri.split( '/')[3] == 'sources' else CollectionVersion if concept_expressions == '*': url = host_url + uri + 'concepts?q=' + search_term + '&limit=0' view = ConceptVersionListView.as_view() request = APIRequestFactory().get(url) response = view(request) response.render() concepts_dict = json.loads(response.content) concept_uris = [c['url'] for c in concepts_dict] concepts = Concept.objects.filter(uri__in=concept_uris) expressions.extend(map(lambda c: c.uri, concepts)) else: expressions.extend(concept_expressions) if mapping_expressions == '*': url = host_url + uri + 'mappings?q=' + search_term + '&limit=0' view = MappingListView.as_view() request = APIRequestFactory().get(url) response = view(request) response.render() mappings_dict = json.loads(response.content) mapping_uris = [c['url'] for c in mappings_dict] mappings = Mapping.objects.filter(uri__in=mapping_uris) expressions.extend(map(lambda m: m.uri, mappings)) else: expressions.extend(mapping_expressions) expressions = set(expressions) if cascade_mappings: all_related_mappings = CollectionReferenceUtils.get_all_related_mappings( expressions, parent_resource) expressions = expressions.union(set(all_related_mappings)) prev_refs = parent_resource.references save_kwargs = { 'force_update': True, 'expressions': expressions, 'user': user } serializer = SerializerClass(parent_resource, partial=True) serializer.save(**save_kwargs) update_collection_in_solr.delay( serializer.object.get_head().id, CollectionReference.diff(serializer.object.references, prev_refs)) if 'references' in serializer.errors: serializer.object.save() diff = map( lambda ref: ref, CollectionReference.diff(serializer.object.references, prev_refs)) errors = serializer.errors.get('references', []) return diff, errors
url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/descriptions/$', ConceptDescriptionListCreateView.as_view(), name='concept-descriptions'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/descriptions/(?P<uuid>[a-zA-Z0-9\-\.]+)/$', ConceptDescriptionRetrieveUpdateDestroyView.as_view(), name='concept-description'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/extras/$', ConceptExtrasView.as_view(), name='concept-extras'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/extras/(?P<extra>[_a-zA-Z0-9\-\.]+)/$', ConceptExtraRetrieveUpdateDestroyView.as_view(), name='concept-extra'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/names/$', ConceptNameListCreateView.as_view(), name='concept-names'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/names/(?P<uuid>[a-zA-Z0-9\-\.]+)/$', ConceptNameRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/versions/$', ConceptVersionsView.as_view(), name='concept-version-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/mappings/$', ConceptMappingsView.as_view(), name='concept-mapping-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/$', ConceptVersionRetrieveView.as_view(), name='conceptversion-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/descriptions/$', ConceptDescriptionListCreateView.as_view(), name='concept-descriptions'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/descriptions/(?P<uuid>[a-zA-Z0-9\-\.]+)/$', ConceptDescriptionRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/extras/$', ConceptExtrasView.as_view(), name='concept-extras'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/extras/(?P<extra>[_a-zA-Z0-9\-\.]+)/$', ConceptExtraRetrieveUpdateDestroyView.as_view(), name='concept-extra'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/names/$', ConceptNameListCreateView.as_view(), name='concept-names'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/(?P<concept_version>[a-zA-Z0-9\-\.]+)/names/(?P<uuid>[a-zA-Z0-9\-\.]+)/$', ConceptNameRetrieveUpdateDestroyView.as_view(), name='concept-name'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/$', MappingListView.as_view(), name='mapping-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/versions/$', MappingVersionsListView.as_view(), name='mapping-version-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/$', MappingDetailView.as_view(), name='mapping-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/(?P<mapping_version>[a-zA-Z0-9\-\.]+)/$', MappingVersionDetailView.as_view(), name='mappingversion-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/versions/$', SourceVersionListView.as_view(), extra_kwargs, name='user-sourceversion-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/latest/$', SourceVersionRetrieveUpdateView.as_view(), {'user_is_self': True, 'is_latest': True}, name='user-sourceversion-latest'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/$', SourceVersionRetrieveUpdateDestroyView.as_view(), extra_kwargs, name='user-sourceversion-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/children/$', SourceVersionChildListView.as_view(), extra_kwargs, name='user-sourceversion-child-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/concepts/$', ConceptCreateView.as_view(), name='concept-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/concepts/(?P<concept>[a-zA-Z0-9\-\.]+)/$', ConceptRetrieveUpdateDestroyView.as_view(), name='concept-detail'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/mappings/$', MappingListView.as_view(), name='mapping-list'), url(r'^sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<version>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/$', MappingListView.as_view(), name='mapping-detail'), url(r'^collections/', include('collection.urls')), # url(r'^collections/$', CollectionListView.as_view(), extra_kwargs, name='user-collection-list'), # url(r'^collections/(?P<collection>[a-zA-Z0-9\-\.]+)/$', CollectionRetrieveUpdateDestroyView.as_view(), extra_kwargs, name='user-collection-detail'),