Example #1
0
    def get(self, request, graphid=None, resourceid=None):
        if graphid is not None:
            # self.graph = Graph.objects.get(graphid=graphid)
            resource_instance = models.ResourceInstance.objects.create(graph_id=graphid)
            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=resource_instance.graph.pk).exclude(pk='22000000-0000-0000-0000-000000000002').exclude(isresource=False).exclude(isactive=False)
            graph = Graph.objects.get(graphid=resource_instance.graph.pk)
            form = Form(resource_instance.pk)
            datatypes = models.DDataType.objects.all()
            widgets = models.Widget.objects.all()
            map_layers = models.MapLayers.objects.all()
            map_sources = models.MapSources.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]
            context = self.get_context_data(
                main_script='views/resource/editor',
                resource_type=resource_instance.graph.name,
                iconclass=resource_instance.graph.iconclass,
                form=JSONSerializer().serialize(form),
                forms=JSONSerializer().serialize(forms_w_cards),
                datatypes_json=JSONSerializer().serialize(datatypes),
                widgets=widgets,
                map_layers=map_layers,
                map_sources=map_sources,
                widgets_json=JSONSerializer().serialize(widgets),
                resourceid=resourceid,
                resource_graphs=resource_graphs,
                graph_json=JSONSerializer().serialize(graph),
            )
            return render(request, 'views/resource/editor.htm', context)

        return HttpResponseNotFound()
Example #2
0
    def get(self, request, resourceid=None, formid=None):
        if formid is not None:
            form = Form(resourceid=resourceid,
                        formid=formid,
                        user=request.user)
            return JSONResponse(form)

        return HttpResponseNotFound()
Example #3
0
def manager(request):
    resourceinstanceid = '40000000-0000-0000-0000-000000000000'

    if request.method == 'GET':

        form = Form(resourceinstanceid)

        return render(request, 'config-manager.htm', {
            'main_script': 'config-manager',
            'active_page': 'Home',
            'forms': form.forms,
            'widgets': form.widgets,
            'blanks': JSONSerializer().serialize(form.blanks),
            'tiledata': JSONSerializer().serialize(form.tiles)
        })


    if request.method == 'POST':
        json = request.body
        if json != None:
            data = JSONDeserializer().deserialize(json)
            #print data

            def saveTile(data, parenttile_id=None):
                data['tileid'], created = uuid.get_or_create(data['tileid'])
                tile, created = models.Tile.objects.update_or_create(
                    tileid = data['tileid'], 
                    defaults = {
                        'nodegroup_id': data['nodegroup_id'], 
                        'data': data['data'],
                        'resourceinstance_id': data['resourceinstance_id'],
                        'parenttile_id': data['parenttile_id']
                    }
                )
                return data

            if 'tiles' in data and len(data['tiles']) > 0:                
                parenttile = saveTile(data)

                for key, tiles in data['tiles'].iteritems():
                    for tile in tiles:
                        tile['parenttile_id'] = parenttile['tileid']
                        saveTile(tile)
            else:
                saveTile(data)

        return JSONResponse(data)

    if request.method == 'DELETE':
        json = request.body
        if json != None:
            data = JSONDeserializer().deserialize(json)
            print data
            tile = models.Tile.objects.get(tileid = data['tileid'])
            tile.delete()
            tile.tileid = data['tileid']
        return JSONResponse(tile)
Example #4
0
    def get(self,
            request,
            graphid=None,
            resourceid=None,
            view_template='views/resource/editor.htm',
            main_script='views/resource/editor',
            nav_menu=True):
        if self.action == 'copy':
            return self.copy(request, resourceid)

        resource_instance_exists = False

        try:
            resource_instance = Resource.objects.get(pk=resourceid)
            resource_instance_exists = True
            graphid = resource_instance.graph_id

        except ObjectDoesNotExist:
            resource_instance = Resource()
            resource_instance.resourceinstanceid = resourceid
            resource_instance.graph_id = graphid

        if resourceid is not None:

            if request.is_ajax() and request.GET.get('search') == 'true':
                html = render_to_string('views/search/search-base-manager.htm',
                                        {}, request)
                return HttpResponse(html)

            resource_graphs = models.GraphModel.objects.exclude(
                pk=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID).exclude(
                    isresource=False).exclude(isactive=False)
            graph = Graph.objects.get(graphid=graphid)
            relationship_type_values = get_resource_relationship_types()
            form = Form(resource_instance.pk)
            datatypes = models.DDataType.objects.all()
            widgets = models.Widget.objects.all()
            map_layers = models.MapLayer.objects.all()
            map_markers = models.MapMarker.objects.all()
            map_sources = models.MapSource.objects.all()
            geocoding_providers = models.Geocoder.objects.all()
            forms = graph.form_set.filter(visible=True)
            forms_x_cards = models.FormXCard.objects.filter(form__in=forms)
            forms_w_cards = []
            required_widgets = []

            for form_x_card in forms_x_cards:
                if request.user.has_perm('read_nodegroup',
                                         form_x_card.card.nodegroup):
                    forms_w_cards.append(form_x_card.form)

            widget_datatypes = [v.datatype for k, v in graph.nodes.iteritems()]
            widgets = widgets.filter(datatype__in=widget_datatypes)

            if resource_instance_exists == True:
                displayname = Resource.objects.get(pk=resourceid).displayname
                if displayname == 'undefined':
                    displayname = 'Unnamed Resource'
            else:
                displayname = 'Unnamed Resource'

            date_nodes = models.Node.objects.filter(datatype='date',
                                                    graph__isresource=True,
                                                    graph__isactive=True)
            searchable_datatypes = [
                d.pk
                for d in models.DDataType.objects.filter(issearchable=True)
            ]
            searchable_nodes = models.Node.objects.filter(
                graph__isresource=True,
                graph__isactive=True,
                datatype__in=searchable_datatypes,
                issearchable=True)
            resource_cards = models.CardModel.objects.filter(
                graph__isresource=True, graph__isactive=True)
            context = self.get_context_data(
                main_script=main_script,
                resource_type=graph.name,
                relationship_types=relationship_type_values,
                iconclass=graph.iconclass,
                form=JSONSerializer().serialize(form),
                forms=JSONSerializer().serialize(forms_w_cards),
                datatypes_json=JSONSerializer().serialize(
                    datatypes,
                    exclude=['iconclass', 'modulename', 'classname']),
                datatypes=datatypes,
                widgets=widgets,
                date_nodes=date_nodes,
                map_layers=map_layers,
                map_markers=map_markers,
                map_sources=map_sources,
                geocoding_providers=geocoding_providers,
                widgets_json=JSONSerializer().serialize(widgets),
                resourceid=resourceid,
                resource_graphs=resource_graphs,
                graph_json=JSONSerializer().serialize(
                    graph,
                    exclude=[
                        'iconclass', 'functions', 'functions_x_graphs', 'name',
                        'description', 'deploymentfile', 'author',
                        'deploymentdate', 'version', 'isresource', 'isactive',
                        'iconclass', 'ontology'
                    ]),
                displayname=displayname,
                resource_cards=JSONSerializer().serialize(resource_cards,
                                                          exclude=[
                                                              'description',
                                                              'instructions',
                                                              'active',
                                                              'isvisible'
                                                          ]),
                searchable_nodes=JSONSerializer().serialize(
                    searchable_nodes,
                    exclude=[
                        'description', 'ontologyclass', 'isrequired',
                        'issearchable', 'istopnode'
                    ]),
                saved_searches=JSONSerializer().serialize(
                    settings.SAVED_SEARCHES),
                resource_instance_exists=resource_instance_exists,
                user_is_reviewer=json.dumps(
                    request.user.groups.filter(
                        name='Resource Reviewer').exists()),
                active_report_count=models.Report.objects.filter(
                    graph_id=resource_instance.graph_id, active=True).count(),
                userid=request.user.id)

            if graph.iconclass:
                context['nav']['icon'] = graph.iconclass
            context['nav']['title'] = graph.name
            context['nav']['menu'] = nav_menu
            if resourceid == settings.RESOURCE_INSTANCE_ID:
                context['nav']['help'] = (_('Managing System Settings'),
                                          'help/base-help.htm')
                context['help'] = 'system-settings-help'
            else:
                context['nav']['help'] = (_('Using the Resource Editor'),
                                          'help/base-help.htm')
                context['help'] = 'resource-editor-help'

            return render(request, view_template, context)

        return HttpResponseNotFound()
Example #5
0
    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()
Example #6
0
    def get(self,
            request,
            graphid=None,
            resourceid=None,
            view_template='views/resource/editor.htm',
            main_script='views/resource/editor',
            nav_menu=True):
        if self.action == 'copy':
            return self.copy(request, resourceid)

        if graphid is not None:
            resource_instance = Resource()
            resource_instance.graph_id = graphid
            resource_instance.save(**{'request': request})
            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)
            relationship_type_values = get_resource_relationship_types()
            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()
            geocoding_providers = models.Geocoder.objects.all()
            forms = resource_instance.graph.form_set.filter(visible=True)
            forms_x_cards = models.FormXCard.objects.filter(form__in=forms)
            forms_w_cards = []
            for form_x_card in forms_x_cards:
                cm = models.CardModel.objects.get(pk=form_x_card.card_id)
                if request.user.has_perm('read_nodegroup', cm.nodegroup):
                    forms_w_cards.append(form_x_card.form)
            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)
            searchable_datatypes = [
                d.pk
                for d in models.DDataType.objects.filter(issearchable=True)
            ]
            searchable_nodes = models.Node.objects.filter(
                graph__isresource=True,
                graph__isactive=True,
                datatype__in=searchable_datatypes,
                issearchable=True)
            resource_cards = models.CardModel.objects.filter(
                graph__isresource=True, graph__isactive=True)
            context = self.get_context_data(
                main_script=main_script,
                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,
                geocoding_providers=geocoding_providers,
                widgets_json=JSONSerializer().serialize(widgets),
                resourceid=resourceid,
                resource_graphs=resource_graphs,
                graph_json=JSONSerializer().serialize(graph),
                displayname=displayname,
                resource_cards=JSONSerializer().serialize(resource_cards),
                searchable_nodes=JSONSerializer().serialize(searchable_nodes),
                saved_searches=JSONSerializer().serialize(
                    settings.SAVED_SEARCHES),
            )

            if graph.iconclass:
                context['nav']['icon'] = graph.iconclass
            context['nav']['title'] = graph.name
            context['nav']['menu'] = nav_menu
            if resourceid == settings.RESOURCE_INSTANCE_ID:
                context['nav']['help'] = (_('Managing System Settings'),
                                          'help/system-settings-help.htm')
            else:
                context['nav']['help'] = (_('Using the Resource Editor'),
                                          'help/resource-editor-help.htm')

            return render(request, view_template, context)

        return HttpResponseNotFound()