From b05e08a165e4ab3fa01c2b9a9fd46ec4990566a1 Mon Sep 17 00:00:00 2001 From: Samuel Gaist <samuel.gaist@idiap.ch> Date: Wed, 7 Mar 2018 15:16:09 +0100 Subject: [PATCH] [backend][views] Moved from render_to_response to render render_to_response is deprecated in Django 2.0 and render has been available since 1.3. It's shorter to write and avoids the writing of context_instance=RequestContext(request) in each of its call. --- beat/web/backend/views.py | 51 ++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/beat/web/backend/views.py b/beat/web/backend/views.py index 94a71e551..de7bd1fb6 100755 --- a/beat/web/backend/views.py +++ b/beat/web/backend/views.py @@ -36,8 +36,7 @@ from django.http import Http404, HttpResponseRedirect from django.conf import settings from django.core.urlresolvers import reverse from django.shortcuts import get_object_or_404 -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.contrib.auth.decorators import login_required from django.http import HttpResponseForbidden from django.contrib import messages @@ -81,18 +80,18 @@ def scheduler(request): if request.GET.has_key('period'): refreshing_period = int(request.GET['period']) - return render_to_response('backend/scheduler.html', - dict( - jobs=state.jobs(), - experiments=state.experiments(), - workers=Worker.objects.order_by('-active', 'name'), - queues=Queue.objects.order_by('memory_limit', 'max_slots_per_user'), - cache_chart_data=simplejson.dumps(cache_chart_data), - cache_gb=cache_gb, - helper_panel=getattr(settings, 'SCHEDULING_PANEL', False), - refreshing_period=refreshing_period, - ), - context_instance=RequestContext(request)) + return render(request, + 'backend/scheduler.html', + dict( + jobs=state.jobs(), + experiments=state.experiments(), + workers=Worker.objects.order_by('-active', 'name'), + queues=Queue.objects.order_by('memory_limit', 'max_slots_per_user'), + cache_chart_data=simplejson.dumps(cache_chart_data), + cache_gb=cache_gb, + helper_panel=getattr(settings, 'SCHEDULING_PANEL', False), + refreshing_period=refreshing_period + )) #------------------------------------------------ @@ -109,11 +108,9 @@ def environment(request, name, version): raise Http404() # Render the page - return render_to_response('backend/environment.html', - { - 'environment': environment, - }, - context_instance=RequestContext(request)) + return render(request, + 'backend/environment.html', + {'environment': environment}) #---------------------------------------------------------- @@ -125,15 +122,13 @@ def list_environments(request): objects = Environment.objects.for_user(request.user, True).filter(active=True).order_by('-creation_date') # Render the page - return render_to_response( - 'backend/environment_list.html', - dict( - objects=objects, - author=request.user, - owner=True, - ), - context_instance=RequestContext(request), - ) + return render(request, + 'backend/environment_list.html', + dict( + objects=objects, + author=request.user, + owner=True + )) -- GitLab