Source code for Happyface4.views

from django.shortcuts import render
from django.template import loader
from django.apps import apps
from django.http import HttpResponse
from django.conf import settings
from django.views.defaults import page_not_found
from . import utilities as ut


[docs] def home(request): # get the time from the request, otherwise use the current time link_date, request_time, form, reload = ut.extract_time_from_request(request) # get the list of relevant apps that are to be displayed in the categories bar analyses = ut.get_Analyses_from_apps(apps) # get the instance and category statuses from the different analyses instances and # the overall worst status from request_time 24 h into the past # used for the status display in the nav bar as well as for the status Overview module statuses = ut.get_statuses_of_instances( analyses, request_time, # one extra slot: the oldest signal of the 24 h window otherwise # falls outside the query depending on the cycle drift, which made # the first overview slot flip between filled and "no data" time_range=settings.OVERVIEW_RANGE + settings.PULL_INTERVAL, ) # optional overview sorting (HFC #2): ?sort=status puts the most severe # categories first, default remains alphabetical. The nav sidebar keeps # rendering the alphabetical order on every page. sort_key = request.GET.get("sort", "name") overview_categories = ut.sort_categories(statuses, sort_key) # fixed 15-minute slot grid (96 slots per 24 h) for the overview table: # every row is mapped onto the same slots and clicking a slot navigates # to the nearest stored status time of the instance overview = ut.build_overview_grid(overview_categories, request_time) context = { "statuses": statuses, "overview": overview, "sort": sort_key, "form": form, "time": request_time, "link_date": link_date, "reload": reload, "commit_sha": settings.COMMIT_SHA, "documentation_url": settings.DOCUMENTATION_URL, } return render(request, "home.html", context=context)
[docs] def index(request, category): # get the time from the request, otherwise use the current time link_date, request_time, form, reload = ut.extract_time_from_request(request) # get the list of relevant apps that are to be displayed in the categories bar analyses = ut.get_Analyses_from_apps(apps) # create the objects that will be displayed in the category part of the site statuses = ut.get_statuses_of_instances( analyses, request_time, time_range=settings.PULL_INTERVAL ) # render the instances in the category requested divs = ut.render_instances(analyses, category, request_time, request) # catch case where the category string doesn't match the category of any analysis if not divs: return page_not_found(request, "This category is not available.") # generate the context for the rendering of the template context = { "divs": divs, "statuses": statuses, "form": form, "time": request_time, "link_date": link_date, "reload": reload, "commit_sha": settings.COMMIT_SHA, "documentation_url": settings.DOCUMENTATION_URL, } # get the template template = loader.get_template("index.html") # return the rendered Template as a HTTP response return HttpResponse(template.render(context, request))