def processing_graphs(request): if not request.user.is_superuser: raise PermissionDenied nav_options = get_nav_options(request) if not request.GET: # no parameters from user yet try: #processing_graph_form = ProcessingGraphForm() # unbound form - uses default initial form values #return render(request, "graph/processing_graphs_form.html", {'nav_options': nav_options, 'form': processing_graph_form}) end_timestamp = int(time.time()) start_timestamp = end_timestamp - 18000 # 5 hour interval response = redirect("graph:processing_graphs") query_str = "?date_format=sts_i&start_timestamp={}&end_timestamp={}&graph_variables=estserver&graph_variables=server&graph_variables=site&site_names=all".format(start_timestamp, end_timestamp) response['Location'] += query_str return response except: return HttpResponseBadRequest("Sorry, something went wrong when trying to load the Processing Graphs page.") else: # user has already filled out the form or entered parameters via the URL requestGET = request.GET.copy() context = get_processing_graphs_context(request) # gets all the info from URL, runs query, formats data requestGET = update_form_time_and_date(requestGET, context) processing_graph_form = ProcessingGraphForm(data = requestGET) context['nav_options'] = nav_options context['form'] = processing_graph_form return render(request, "graph/processing_graphs.html", context)
def dashboard_page(request): nav_options = get_nav_options(request) context = {} if not request.GET: # no parameters from user yet try: dashboard_page = DashboardForm() # unbound form - uses default initial form values context = get_context_for_all(request) context['form'] = dashboard_page context['nav_options'] = nav_options return render(request, "graph/dashboard.html", context) #return render(request, "graph/dashboard.html", {'nav_options': nav_options, 'form': dashboard_page}) except: return HttpResponseBadRequest("Sorry, something went wrong when trying to load the dashboard page.") else: # user has already filled out the form or entered parameters via the URL requestGET = request.GET.copy() context = get_context_for_all(request) requestGET['datetime_start'] = str(context['datetime_start']) dashboard_page = DashboardForm(data = requestGET) context['form'] = dashboard_page context['nav_options'] = nav_options return render(request, "graph/dashboard.html", context)
def graph_home(request): nav_options = get_nav_options(request) try: return render(request, "graph/graph_home.html", {'nav_options': nav_options}) except: return HttpResponse("Sorry, the graph home page didn't render correctly.") # what type of response should this be?
def show_users(request): """This view shows a list of registered users in the system. It is for admin use only""" user = request.user if request.method == 'GET': if user.is_superuser: users = User.objects.all() return render( request, 'account/users.html', {'users': users, 'nav_options': get_nav_options(request) }) else: raise PermissionDenied #403 return HttpResponse("Try a get!")