def node(entry): """Helper function to construct a node object.""" if entry.pk not in memo: memo.append(entry.pk) data['nodes'].append({ 'id': str(entry.pk), 'label': entry.title, 'text': recross(hyper(markdown(entry.text))), 'links': '<a href="%s">View</a> | <a href="%s">Update</a>' % (entry.get_absolute_url(), entry.get_update_url()), 'weight': random() })
def node(entry): "Helper function to construct a node object." memo.append(entry.pk) return {'id': str(entry.pk), 'label': entry.title, 'text': recross(hyper(markdown(entry.text))), 'links': '<a href="%s">View</a> | <a href="%s">Update</a>' % (entry.get_absolute_url(), entry.get_update_url()), 'weight':random()}
def graph(request, template='data/graph.html'): """View that generates a data graph connecting data entries with relations.""" network = { 'dataSchema': { 'nodes': [ {'name': 'label', 'type': 'string'}, {'name': 'text', 'type': 'string'}, {'name': 'links', 'type': 'string'}, {'name': 'weight', 'type': 'number' } ], 'edges': [ {'name': 'label', 'type': 'string'}, {'name': 'text', 'type': 'string'}, {'name': 'links', 'type': 'string'}, {'name': 'weight', 'type': 'number' } ] }, 'data': { # Dummy data: 'nodes': [ {'id': '1', 'label': 'Concepts', 'text':'Denigma Concepts'}, {'id': '2', 'label': 'Aspects', 'text':'Three aspects'} ], 'edges': [ {'id': '2to1', 'label': 'belongs_to', 'text':'A belonging to relationship', 'target':'1', 'source': '2'} ] } } memo = [] def node(entry): "Helper function to construct a node object." memo.append(entry.pk) return {'id': str(entry.pk), 'label': entry.title, 'text': recross(hyper(markdown(entry.text))), 'links': '<a href="%s">View</a> | <a href="%s">Update</a>' % (entry.get_absolute_url(), entry.get_update_url()), 'weight':random()} # Getting the actually data: data = {'nodes':[], 'edges':[]} relations = Relation.objects.all() for relation in relations: fr = relation.fr be = relation.be to = relation.to if fr.pk not in memo: data['nodes'].append(node(fr)) if to.pk not in memo: data['nodes'].append(node(to)) data['edges'].append({'id': "%sto%s" % (fr.pk, to.pk), 'label': be.title, 'text': markdown(be.text), 'source': str(fr.pk), 'target': str(to.pk), 'directed': True, 'links': '<a href="%s">View</a> | <a href="%s">Update</a>' % (relation.get_absolute_url(), relation.get_update_url()), 'weight':random()}) network['data'] = data network_json = simplejson.dumps(network) return render(request, template, {'network_json': network_json})
def graph(request, template='data/graph.html'): """View that generates a data graph connecting data entries with relations.""" network = { 'dataSchema': { 'nodes': [{ 'name': 'label', 'type': 'string' }, { 'name': 'text', 'type': 'string' }, { 'name': 'links', 'type': 'string' }, { 'name': 'weight', 'type': 'number' }], 'edges': [{ 'name': 'label', 'type': 'string' }, { 'name': 'text', 'type': 'string' }, { 'name': 'links', 'type': 'string' }, { 'name': 'weight', 'type': 'number' }] }, 'data': { # Dummy data: 'nodes': [{ 'id': '1', 'label': 'Concepts', 'text': 'Denigma Concepts' }, { 'id': '2', 'label': 'Aspects', 'text': 'Three aspects' }], 'edges': [{ 'id': '2to1', 'label': 'belongs_to', 'text': 'A belonging to relationship', 'target': '1', 'source': '2' }] } } memo = [] def node(entry): """Helper function to construct a node object.""" if entry.pk not in memo: memo.append(entry.pk) data['nodes'].append({ 'id': str(entry.pk), 'label': entry.title, 'text': recross(hyper(markdown(entry.text))), 'links': '<a href="%s">View</a> | <a href="%s">Update</a>' % (entry.get_absolute_url(), entry.get_update_url()), 'weight': random() }) # Getting the actually data: data = {'nodes': [], 'edges': []} relations = Relation.objects.all() for relation in relations: fr = relation.fr be = relation.be to = relation.to node(fr) node(to) data['edges'].append({ 'id': "%sto%s" % (fr.pk, to.pk), 'label': be.title, 'text': markdown(be.text), 'source': str(fr.pk), 'target': str(to.pk), 'directed': True, 'links': '<a href="%s">View</a> | <a href="%s">Update</a>' % (relation.get_absolute_url(), relation.get_update_url()), 'weight': random() }) network['data'] = data network_json = simplejson.dumps(network) return render(request, template, {'network_json': network_json})