def enable_tool(request): tool = Tool.objects.get(id=request.POST['tool_id']) customer = User.objects.get(id=request.POST['customer_id']) project = Project.objects.get(id=request.POST['project_id']) response = check_policy_to_enable_tool(tool, operator=customer, user=customer, project=project, staff_charge=False) if response.status_code != HTTPStatus.OK: dictionary = { 'message': 'You are not authorized to enable this tool. {}'.format(response), 'delay': 10, } return render(request, 'kiosk/acknowledgement.html', dictionary) # All policy checks passed so enable the tool for the user. if tool.interlock and not tool.interlock.unlock(): raise Exception("The interlock command for this tool failed. The error message returned: " + str(tool.interlock.most_recent_reply)) # Create a new usage event to track how long the user uses the tool. new_usage_event = UsageEvent() new_usage_event.operator = customer new_usage_event.user = customer new_usage_event.project = project new_usage_event.tool = tool new_usage_event.save() dictionary = {'message': 'You can now use the {}'.format(tool)} return render(request, 'kiosk/acknowledgement.html', dictionary)
def enable_tool(request, tool_id, user_id, project_id, staff_charge): """ Enable a tool for a user. The user must be qualified to do so based on the lab usage policy. """ if not settings.ALLOW_CONDITIONAL_URLS: return HttpResponseBadRequest('Tool control is only available on campus. We\'re working to change that! Thanks for your patience.') tool = get_object_or_404(Tool, id=tool_id) operator = request.user user = get_object_or_404(User, id=user_id) project = get_object_or_404(Project, id=project_id) staff_charge = staff_charge == 'true' response = check_policy_to_enable_tool(tool, operator, user, project, staff_charge) if response.status_code != HTTPStatus.OK: return response # All policy checks passed so enable the tool for the user. if tool.interlock and not tool.interlock.unlock(): raise Exception("The interlock command for this tool failed. The error message returned: " + str(tool.interlock.most_recent_reply)) # Create a new usage event to track how long the user uses the tool. new_usage_event = UsageEvent() new_usage_event.operator = operator new_usage_event.user = user new_usage_event.project = project new_usage_event.tool = tool new_usage_event.save() if staff_charge: new_staff_charge = StaffCharge() new_staff_charge.staff_member = request.user new_staff_charge.customer = user new_staff_charge.project = project new_staff_charge.save() return response
def enable_tool(request, tool_id, user_id, project_id, staff_charge): """ Enable a tool for a user. The user must be qualified to do so based on the lab usage policy. """ if not settings.ALLOW_CONDITIONAL_URLS: return HttpResponseBadRequest( "Tool control is only available on campus. We're working to change that! Thanks for your patience." ) tool = get_object_or_404(Tool, id=tool_id) operator = request.user user = get_object_or_404(User, id=user_id) project = get_object_or_404(Project, id=project_id) staff_charge = staff_charge == "true" bypass_interlock = request.POST.get("bypass", 'False') == 'True' response = check_policy_to_enable_tool(tool, operator, user, project, staff_charge) if response.status_code != HTTPStatus.OK: return response # All policy checks passed so enable the tool for the user. if tool.interlock and not tool.interlock.unlock(): if bypass_interlock and interlock_bypass_allowed(user): pass else: return interlock_error("Enable", user) # Start staff charge before tool usage if staff_charge: new_staff_charge = StaffCharge() new_staff_charge.staff_member = request.user new_staff_charge.customer = user new_staff_charge.project = project new_staff_charge.save() # If the tool requires area access, start charging area access time #At Princeton, removing automatic area access charge #if tool.requires_area_access: #area_access = AreaAccessRecord() #area_access.area = tool.requires_area_access #area_access.staff_charge = new_staff_charge #area_access.customer = new_staff_charge.customer #area_access.project = new_staff_charge.project #area_access.save() # Create a new usage event to track how long the user uses the tool. new_usage_event = UsageEvent() new_usage_event.operator = operator new_usage_event.user = user new_usage_event.project = project new_usage_event.tool = tool new_usage_event.save() return response
def do_enable_tool(request, tool_id): tool = Tool.objects.get(id=tool_id) customer = User.objects.get(id=request.POST["customer_id"]) project = Project.objects.get(id=request.POST["project_id"]) bypass_interlock = request.POST.get("bypass", 'False') == 'True' response = check_policy_to_enable_tool(tool, operator=customer, user=customer, project=project, staff_charge=False) if response.status_code != HTTPStatus.OK: dictionary = { "message": "You are not authorized to enable this tool. {}".format( response.content.decode()), "delay": 10, } return render(request, "kiosk/acknowledgement.html", dictionary) # All policy checks passed so enable the tool for the user. if tool.interlock and not tool.interlock.unlock(): if bypass_interlock and interlock_bypass_allowed(customer): pass else: return interlock_error("Enable", customer) # Create a new usage event to track how long the user uses the tool. new_usage_event = UsageEvent() new_usage_event.operator = customer new_usage_event.user = customer new_usage_event.project = project new_usage_event.tool = tool new_usage_event.save() dictionary = { "message": "You can now use the {}".format(tool), "badge_number": customer.badge_number } return render(request, "kiosk/acknowledgement.html", dictionary)