def display_graph(request): ''' ' Use JSON data to retrieve the appropriate datastream for rendering. ''' user = check_access(request) if isinstance(user, HttpResponse): return user.content json_data = json.loads(request.GET['json_data']) try: stream = DataStream.objects.get(id = int(json_data['stream'])) if not stream.can_view(user): raise Http404("Sorry, but you do not have permission to view this graph.") except ObjectDoesNotExist: raise Http404() reductions = reductFunc.keys() t_graph = loader.get_template('graph.html') c_graph = Context({ 'id': stream.id, 'reduction': stream.reduction_type, 'reductions': reductions }) return HttpResponse(t_graph.render(c_graph), mimetype="text/html")
def graphsIndex(request): graphs = [] t_graph = loader.get_template('graph.html') reductions = reductFunc.keys() tmpDefaultGraphs = [] for graphId in DEFAULT_GRAPHS: try: stream = DataStream.objects.get(id=graphId) tmpDefaultGraphs.append(graphId) except DataStream.DoesNotExist: print "Invalid stream id %s given for default!" % str(graphId) continue c_graph = Context({ 'id': graphId ,'reduction': stream.reduction_type ,'reductions': reductions }) graphs.append(t_graph.render(c_graph)) t = loader.get_template('graphs.html') c = RequestContext(request, { 'graphs': graphs ,'defaultGraphs': tmpDefaultGraphs }) return HttpResponse(t.render(c))
def display_simple_graph(request): json_data = json.loads(request.GET['json_data']) try: stream = DataStream.objects.get(id = int(json_data['datastream_id'])) except ObjectDoesNotExist: raise Http404() perm = True if not stream.is_public: token = json_data['token'] try: key = Key.objects.get(key = token) if not key.isCurrent() or key not in stream.can_read.all(): perm = False except Key.DoesNotExist: perm = False reductions = reductFunc.keys() t_graph = loader.get_template('graph.html') c_graph = Context({ 'id': stream.id, 'reduction': stream.reduction_type, 'reductions': reductions, 'permission': perm }) r_graph = t_graph.render(c_graph) resp = HttpResponse(json.dumps({'graph': r_graph, "perm": perm}), mimetype="application/json") resp['Access-Control-Allow-Origin'] = '*' return resp
def saved_view(request, token): ''' ' This view will render the main page for sharing views, with the divs ' for widgets. The widgets will be loaded with ajax after page load. ' ' TODO: When other kinds of widgets are added, add them to the page also. ''' # validate the token, consuming a use if applicable key = Key.objects.validate(token) if not isinstance(key, Key): raise Http404(key) # Load the instance, if there is one. view = SavedView.objects.get(key = key) reductions = reductFunc.keys() graphs = [] t_graph = loader.get_template('graph.html') for w in view.widget.all(): c_graph = Context({ 'id': w.saveddsgraph.datastream.id, 'reductions': reductions, 'widget_id': w.id }) graphs.append(t_graph.render(c_graph)) t = loader.get_template('content_container.html') c = RequestContext(request, { 'widgets': graphs, 'token': token, }) return HttpResponse(t.render(c))