old_contents: from django.shortcuts import render
  from django.http import HttpResponse, HttpResponseRedirect
  from django.contrib.auth import authenticate, login, logout
  from django.contrib.auth.decorators import login_required
  import logging
  import json
  
  from .models import BlocklyBot
  
  # Get an instance of a logger
  logger = logging.getLogger(__name__)
  
  # Create your views here.
  def index_view(request):
  	return render(request, 'index.html')
  
  @login_required
  def program_view(request):
  	if len(BlocklyBot.objects.all()) == 0:
  		bot = BlocklyBot.objects.create(running = False)
  		bot.save()
  		return render(request, 'program.html', {'bot': bot})
  	else:
  		return render(request, 'program.html', {'bot': BlocklyBot.objects.all()[0]})
  
  @login_required
  def blockly_programmer_view(request):
  	if len(BlocklyBot.objects.all()) == 0:
  		bot = BlocklyBot.objects.create(running = False)
  		bot.save()
  		return render(request, 'programmer.html', {'bot': bot})
  	else:
  		return render(request, 'programmer.html', {'bot': BlocklyBot.objects.all()[0]})
  
  def login_view(request):
  	username = request.POST['username']
  	password = request.POST['password']
  	user = authenticate(username=username, password=password)
  	logger.debug(user)
  	if user is not None:
  		if user.is_active:
  			login(request, user)
  			return HttpResponseRedirect("/program")
  		else:
  			return HttpResponseRedirect("/", {"message": "account not active"})
  	else:
  		return HttpResponseRedirect("/", {"message": "username / password incorrect"})
  
  @login_required
  def logout_view(request):
  	logout(request)
  	return HttpResponseRedirect("/", {"message": "username / password incorrect"})
  
  def get_program_view(request):
  	bot = BlocklyBot.objects.all()[0]
  	return HttpResponse(json.dumps({"running": bot.running, "program": bot.program}), content_type='application/json')
  
  @login_required
  def start_program_view(request):
  	bot = BlocklyBot.objects.all()[0]
  	bot.running = True
  	bot.save()
  	return HttpResponse(json.dumps({"success": True}), content_type='application/json')
  
  @login_required
  def stop_program_view(request):
  	bot = BlocklyBot.objects.all()[0]
  	bot.running = False
  	bot.save()
  	return HttpResponse(json.dumps({"success": True}), content_type='application/json')
  
  @login_required
  def submit_program_view(request):
  	bot = BlocklyBot.objects.all()[0]
  	bot.program = request.POST['program']
  	bot.save()
  	return HttpResponse(json.dumps({"success": True}), content_type='application/json')
new_contents: from django.shortcuts import render
  from django.http import HttpResponse, HttpResponseRedirect
  from django.contrib.auth import authenticate, login, logout
  from django.contrib.auth.decorators import login_required
  import logging
  import json
  
  from .models import BlocklyBot
  
  # Get an instance of a logger
  logger = logging.getLogger(__name__)
  
  # Create your views here.
  def index_view(request):
  	return render(request, 'index.html')
  
  @login_required(login_url='/')
  def program_view(request):
  	if len(BlocklyBot.objects.all()) == 0:
  		bot = BlocklyBot.objects.create(running = False)
  		bot.save()
  		return render(request, 'program.html', {'bot': bot})
  	else:
  		return render(request, 'program.html', {'bot': BlocklyBot.objects.all()[0]})
  
  @login_required(login_url='/')
  def blockly_programmer_view(request):
  	if len(BlocklyBot.objects.all()) == 0:
  		bot = BlocklyBot.objects.create(running = False)
  		bot.save()
  		return render(request, 'programmer.html', {'bot': bot})
  	else:
  		return render(request, 'programmer.html', {'bot': BlocklyBot.objects.all()[0]})
  
  def login_view(request):
  	username = request.POST['username']
  	password = request.POST['password']
  	user = authenticate(username=username, password=password)
  	logger.debug(user)
  	if user is not None:
  		if user.is_active:
  			login(request, user)
  			return HttpResponseRedirect("/program")
  		else:
  			return HttpResponseRedirect("/", {"message": "account not active"})
  	else:
  		return HttpResponseRedirect("/", {"message": "username / password incorrect"})
  
  @login_required(login_url='/')
  def logout_view(request):
  	logout(request)
  	return HttpResponseRedirect("/", {"message": "username / password incorrect"})
  
  def get_program_view(request):
  	bot = BlocklyBot.objects.all()[0]
  	return HttpResponse(json.dumps({"running": bot.running, "program": bot.program}), content_type='application/json')
  
  @login_required(login_url='/')
  def start_program_view(request):
  	bot = BlocklyBot.objects.all()[0]
  	bot.running = True
  	bot.save()
  	return HttpResponse(json.dumps({"success": True}), content_type='application/json')
  
  @login_required(login_url='/')
  def stop_program_view(request):
  	bot = BlocklyBot.objects.all()[0]
  	bot.running = False
  	bot.save()
  	return HttpResponse(json.dumps({"success": True}), content_type='application/json')
  
  @login_required(login_url='/')
  def submit_program_view(request):
  	bot = BlocklyBot.objects.all()[0]
  	bot.program = request.POST['program']
  	bot.save()
  	return HttpResponse(json.dumps({"success": True}), content_type='application/json')
subject: fix login required decorator