def new_visualization(request): demo_viz = ( SCOTUSMap.objects.filter(published=True, deleted=False).annotate( Count("clusters")).filter( # Ensures that we only show good stuff on homepage clusters__count__gt=5, clusters__count__lt=15, ).order_by("-date_published", "-date_modified", "-date_created")[:1]) context = { "SCDB_LATEST_CASE": settings.SCDB_LATEST_CASE.isoformat(), "demo_viz": demo_viz, "private": True, } if request.method == "POST": form = VizForm(request.POST) context["form"] = form if form.is_valid(): # Process the data in form.cleaned_data cd = form.cleaned_data start, end = reverse_endpoints_if_needed(cd["cluster_start"], cd["cluster_end"]) viz = SCOTUSMap( user=request.user, cluster_start=start, cluster_end=end, title=cd["title"], notes=cd["notes"], ) status, viz = build_visualization(viz) if status == "too_many_nodes": msg = message_dict[status] messages.add_message(request, msg["level"], msg["message"]) return render(request, "new_visualization.html", context) elif status == "too_few_nodes": msg = message_dict[status] messages.add_message(request, msg["level"], msg["message"]) return render( request, "new_visualization.html", { "form": form, "private": True }, ) return HttpResponseRedirect( reverse( "view_visualization", kwargs={ "pk": viz.pk, "slug": viz.slug }, )) else: context["form"] = VizForm() return render(request, "new_visualization.html", context)
def new_visualization(request): demo_viz = SCOTUSMap.objects.filter( published=True, deleted=False, ).annotate( Count('clusters'), ).filter( # Ensures that we only show good stuff on homepage clusters__count__gt=5, clusters__count__lt=15, ).order_by( '-date_published', '-date_modified', '-date_created', )[:1] context = { 'SCDB_LATEST_CASE': settings.SCDB_LATEST_CASE.isoformat(), 'demo_viz': demo_viz, 'private': True, } if request.method == 'POST': form = VizForm(request.POST) context['form'] = form if form.is_valid(): # Process the data in form.cleaned_data cd = form.cleaned_data start, end = reverse_endpoints_if_needed(cd['cluster_start'], cd['cluster_end']) viz = SCOTUSMap( user=request.user, cluster_start=start, cluster_end=end, title=cd['title'], notes=cd['notes'], ) build_kwargs = { 'parent_authority': end, 'visited_nodes': {}, 'good_nodes': {}, 'max_hops': 3, } t1 = time.time() try: g = viz.build_nx_digraph(**build_kwargs) except TooManyNodes: try: # Try with fewer hops. build_kwargs['max_hops'] = 2 g = viz.build_nx_digraph(**build_kwargs) msg = message_dict['fewer_hops_delivered'] messages.add_message(request, msg['level'], msg['message']) except TooManyNodes: # Still too many hops. Abort. tally_stat('visualization.too_many_nodes_failure') msg = message_dict['too_many_nodes'] messages.add_message(request, msg['level'], msg['message']) return render(request, 'new_visualization.html', context) if len(g.edges()) == 0: tally_stat('visualization.too_few_nodes_failure') msg = message_dict['too_few_nodes'] messages.add_message(request, msg['level'], msg['message']) return render(request, 'new_visualization.html', { 'form': form, 'private': True }) t2 = time.time() viz.generation_time = t2 - t1 viz.save() viz.add_clusters(g) j = viz.to_json(g) jv = JSONVersion(map=viz, json_data=j) jv.save() return HttpResponseRedirect(reverse( 'view_visualization', kwargs={'pk': viz.pk, 'slug': viz.slug} )) else: context['form'] = VizForm() return render(request, 'new_visualization.html', context)
def new_visualization(request): demo_viz = ( SCOTUSMap.objects.filter( published=True, deleted=False, ).annotate(Count("clusters"), ).filter( # Ensures that we only show good stuff on homepage clusters__count__gt=5, clusters__count__lt=15, ).order_by( "-date_published", "-date_modified", "-date_created", )[:1]) context = { "SCDB_LATEST_CASE": settings.SCDB_LATEST_CASE.isoformat(), "demo_viz": demo_viz, "private": True, } if request.method == "POST": form = VizForm(request.POST) context["form"] = form if form.is_valid(): # Process the data in form.cleaned_data cd = form.cleaned_data start, end = reverse_endpoints_if_needed(cd["cluster_start"], cd["cluster_end"]) viz = SCOTUSMap( user=request.user, cluster_start=start, cluster_end=end, title=cd["title"], notes=cd["notes"], ) build_kwargs = { "parent_authority": end, "visited_nodes": {}, "good_nodes": {}, "max_hops": 3, } t1 = time.time() try: g = viz.build_nx_digraph(**build_kwargs) except TooManyNodes: try: # Try with fewer hops. build_kwargs["max_hops"] = 2 g = viz.build_nx_digraph(**build_kwargs) msg = message_dict["fewer_hops_delivered"] messages.add_message(request, msg["level"], msg["message"]) except TooManyNodes: # Still too many hops. Abort. tally_stat("visualization.too_many_nodes_failure") msg = message_dict["too_many_nodes"] messages.add_message(request, msg["level"], msg["message"]) return render(request, "new_visualization.html", context) if len(g.edges()) == 0: tally_stat("visualization.too_few_nodes_failure") msg = message_dict["too_few_nodes"] messages.add_message(request, msg["level"], msg["message"]) return render( request, "new_visualization.html", { "form": form, "private": True }, ) t2 = time.time() viz.generation_time = t2 - t1 viz.save() viz.add_clusters(g) j = viz.to_json(g) jv = JSONVersion(map=viz, json_data=j) jv.save() return HttpResponseRedirect( reverse( "view_visualization", kwargs={ "pk": viz.pk, "slug": viz.slug }, )) else: context["form"] = VizForm() return render(request, "new_visualization.html", context)
def new_visualization(request): demo_viz = SCOTUSMap.objects.filter( published=True, deleted=False, ).annotate( Count('clusters'), ).filter( # Ensures that we only show good stuff on homepage clusters__count__gt=5, clusters__count__lt=15, ).order_by( '-date_published', '-date_modified', '-date_created', )[:1] context = { 'SCDB_LATEST_CASE': settings.SCDB_LATEST_CASE.isoformat(), 'demo_viz': demo_viz, 'private': True, } if request.method == 'POST': form = VizForm(request.POST) context['form'] = form if form.is_valid(): # Process the data in form.cleaned_data cd = form.cleaned_data start, end = reverse_endpoints_if_needed(cd['cluster_start'], cd['cluster_end']) viz = SCOTUSMap( user=request.user, cluster_start=start, cluster_end=end, title=cd['title'], notes=cd['notes'], ) build_kwargs = { 'parent_authority': end, 'visited_nodes': {}, 'good_nodes': {}, 'max_hops': 3, } t1 = time.time() try: g = viz.build_nx_digraph(**build_kwargs) except TooManyNodes: try: # Try with fewer hops. build_kwargs['max_hops'] = 2 g = viz.build_nx_digraph(**build_kwargs) msg = message_dict['fewer_hops_delivered'] messages.add_message(request, msg['level'], msg['message']) except TooManyNodes: # Still too many hops. Abort. tally_stat('visualization.too_many_nodes_failure') msg = message_dict['too_many_nodes'] messages.add_message(request, msg['level'], msg['message']) return render_to_response( 'new_visualization.html', context, RequestContext(request), ) if len(g.edges()) == 0: tally_stat('visualization.too_few_nodes_failure') msg = message_dict['too_few_nodes'] messages.add_message(request, msg['level'], msg['message']) return render_to_response( 'new_visualization.html', {'form': form, 'private': True}, RequestContext(request), ) t2 = time.time() viz.generation_time = t2 - t1 viz.save() viz.add_clusters(g) j = viz.to_json(g) jv = JSONVersion(map=viz, json_data=j) jv.save() return HttpResponseRedirect(reverse( 'view_visualization', kwargs={'pk': viz.pk, 'slug': viz.slug} )) else: context['form'] = VizForm() return render_to_response( 'new_visualization.html', context, RequestContext(request), )