def render_visualization_page(request, pk, embed): viz = get_object_or_404(SCOTUSMap, pk=pk) increment_view_count(viz, request) status = None if viz.deleted: status = statuses.HTTP_410_GONE else: if viz.published is False and viz.user != request.user: # Not deleted, private and not the owner status = statuses.HTTP_401_UNAUTHORIZED if embed: if all([viz.published is True, viz.deleted is False]): # Log the referer if it's set, and the item is live. referer_url = request.META.get("HTTP_REFERER") if referer_url is not None: referer, created = Referer.objects.get_or_create( url=referer_url, map_id=viz.pk ) if created: # Spawn a task to try to get the title of the page. get_title.delay(referer.pk) template = "visualization_embedded.html" else: template = "visualization.html" return render( request, template, {"viz": viz, "private": False}, status=status )
def render_visualization_page(request, pk, embed): viz = get_object_or_404(SCOTUSMap, pk=pk) if not is_bot(request): cached_value = viz.view_count with suppress_autotime(viz, ["date_modified"]): viz.view_count = F("view_count") + 1 viz.save() # To get the new value, you either need to get the item from the DB a # second time, or just manipulate it manually.... viz.view_count = cached_value + 1 status = None if viz.deleted: status = statuses.HTTP_410_GONE else: if viz.published is False and viz.user != request.user: # Not deleted, private and not the owner status = statuses.HTTP_401_UNAUTHORIZED if embed: if all([viz.published is True, viz.deleted is False]): # Log the referer if it's set, and the item is live. referer_url = request.META.get("HTTP_REFERER") if referer_url is not None: referer, created = Referer.objects.get_or_create( url=referer_url, map_id=viz.pk, ) if created: # Spawn a task to try to get the title of the page. get_title.delay(referer.pk) template = "visualization_embedded.html" else: template = "visualization.html" return render(request, template, { "viz": viz, "private": True }, status=status)
def render_visualization_page(request, pk, embed): viz = get_object_or_404(SCOTUSMap, pk=pk) if not is_bot(request): cached_value = viz.view_count with suppress_autotime(viz, ['date_modified']): viz.view_count = F('view_count') + 1 viz.save() # To get the new value, you either need to get the item from the DB a # second time, or just manipulate it manually.... viz.view_count = cached_value + 1 status = None if viz.deleted: status = statuses.HTTP_410_GONE else: if viz.published is False and viz.user != request.user: # Not deleted, private and not the owner status = statuses.HTTP_401_UNAUTHORIZED if embed: if all([viz.published is True, viz.deleted is False]): # Log the referer if it's set, and the item is live. referer_url = request.META.get('HTTP_REFERER') if referer_url is not None: referer, created = Referer.objects.get_or_create( url=referer_url, map_id=viz.pk, ) if created: # Spawn a task to try to get the title of the page. get_title.delay(referer.pk) template = 'visualization_embedded.html' else: template = 'visualization.html' return render(request, template, { 'viz': viz, 'private': True }, status=status)