def prepare_resource_relations_index(create=False): """ Creates the settings and mappings in Elasticsearch to support related resources """ index_settings = { 'mappings': { 'all': { 'properties': { 'resourcexid': {'type': 'keyword'}, 'notes': {'type': 'text'}, 'relationshiptype': {'type': 'keyword'}, 'resourceinstanceidfrom': {'type': 'keyword'}, 'resourceinstanceidto': {'type': 'keyword'} } } } } if create: se = SearchEngineFactory().create() se.create_index(index='resource_relations', body=index_settings, ignore=400) concept = Concept('00000000-0000-0000-0000-000000000007') concept.index() return index_settings
def get_resource_relationship_types(): resource_relationship_types = Concept().get_child_collections('00000000-0000-0000-0000-000000000005') default_relationshiptype_valueid = None for relationship_type in resource_relationship_types: if relationship_type[0] == '00000000-0000-0000-0000-000000000007': default_relationshiptype_valueid = relationship_type[2] relationship_type_values = {'values':[{'id':str(c[2]), 'text':str(c[1])} for c in resource_relationship_types], 'default': str(default_relationshiptype_valueid)} return relationship_type_values
def get_resource_relationship_types(): resource_relationship_types = Concept().get_child_collections("00000000-0000-0000-0000-000000000005") default_relationshiptype_valueid = None for relationship_type in resource_relationship_types: if relationship_type[0] == "00000000-0000-0000-0000-000000000007": default_relationshiptype_valueid = relationship_type[2] relationship_type_values = { "values": [{"id": str(c[2]), "text": str(c[1])} for c in resource_relationship_types], "default": str(default_relationshiptype_valueid), } return relationship_type_values
def prepare_resource_relations_index(create=False): """ Creates the settings and mappings in Elasticsearch to support related resources """ index_settings = { 'mappings': { 'all': { 'properties': { 'resourcexid': { 'type': 'keyword' }, 'notes': { 'type': 'text' }, 'relationshiptype': { 'type': 'keyword' }, 'resourceinstanceidfrom': { 'type': 'keyword' }, 'resourceinstanceidto': { 'type': 'keyword' } } } } } if create: se = SearchEngineFactory().create() se.create_index(index='resource_relations', body=index_settings, ignore=400) concept = Concept('00000000-0000-0000-0000-000000000007') concept.index() return index_settings
def get_resource_relationship_types(): resource_relationship_types = Concept().get_child_concepts( '00000000-0000-0000-0000-000000000005', ['member', 'hasTopConcept'], ['prefLabel'], 'prefLabel') default_relationshiptype_valueid = None for relationship_type in resource_relationship_types: if relationship_type[1] == '00000000-0000-0000-0000-000000000007': default_relationshiptype_valueid = relationship_type[5] relationship_type_values = { 'values': [{ 'id': str(c[5]), 'text': str(c[3]) } for c in resource_relationship_types], 'default': str(default_relationshiptype_valueid) } return relationship_type_values
def get(self, request, graphid=None, resourceid=None): if graphid is not None: # self.graph = Graph.objects.get(graphid=graphid) resource_instance = Resource.objects.create(graph_id=graphid) resource_instance.index() return redirect('resource_editor', resourceid=resource_instance.pk) if resourceid is not None: resource_instance = models.ResourceInstance.objects.get( pk=resourceid) resource_graphs = Graph.objects.exclude( pk=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID).exclude( isresource=False).exclude(isactive=False) graph = Graph.objects.get(graphid=resource_instance.graph.pk) resource_relationship_types = Concept().get_child_concepts( '00000000-0000-0000-0000-000000000005', ['member', 'hasTopConcept'], ['prefLabel'], 'prefLabel') default_relationshiptype_valueid = None for relationship_type in resource_relationship_types: if relationship_type[ 1] == '00000000-0000-0000-0000-000000000007': default_relationshiptype_valueid = relationship_type[5] relationship_type_values = { 'values': [{ 'id': str(c[5]), 'text': str(c[3]) } for c in resource_relationship_types], 'default': str(default_relationshiptype_valueid) } form = Form(resource_instance.pk) datatypes = models.DDataType.objects.all() widgets = models.Widget.objects.all() map_layers = models.MapLayer.objects.all() map_sources = models.MapSource.objects.all() forms = resource_instance.graph.form_set.filter(visible=True) forms_x_cards = models.FormXCard.objects.filter(form__in=forms) forms_w_cards = [form_x_card.form for form_x_card in forms_x_cards] displayname = Resource.objects.get(pk=resourceid).displayname if displayname == 'undefined': displayname = 'Unnamed Resource' date_nodes = models.Node.objects.filter(datatype='date', graph__isresource=True, graph__isactive=True) context = self.get_context_data( main_script='views/resource/editor', resource_type=resource_instance.graph.name, relationship_types=relationship_type_values, iconclass=resource_instance.graph.iconclass, form=JSONSerializer().serialize(form), forms=JSONSerializer().serialize(forms_w_cards), datatypes_json=JSONSerializer().serialize(datatypes), widgets=widgets, date_nodes=date_nodes, map_layers=map_layers, map_sources=map_sources, widgets_json=JSONSerializer().serialize(widgets), resourceid=resourceid, resource_graphs=resource_graphs, graph_json=JSONSerializer().serialize(graph), displayname=displayname, ) if graph.iconclass: context['nav']['icon'] = graph.iconclass context['nav']['title'] = graph.name context['nav']['menu'] = True context['nav']['edit_history'] = True context['nav']['help'] = (_('Creating and Editing Resources'), '') return render(request, 'views/resource/editor.htm', context) return HttpResponseNotFound()