def device_with_runreq(self, device: models.Device, runreq_autoid: str): rreq = models.RunRequest.objects.get(auto_generated_id=runreq_autoid) self.assertIsNotNone(rreq) device.run_request = rreq device.full_clean() device.save() try: yield rreq finally: device.run_request = None device.full_clean() device.save()
def claim(request): if request.method == "POST": with transaction.atomic(): device = get_object_or_404(Device, mac_address=request.POST["mac_address"]) if not request.user.has_perm(Device.get_perm("claim"), device): raise PermissionDenied() device.owner = request.user device.save() return redirect("/portal/claim/") context = {"unclaimed_devices": Device.objects.filter(owner__isnull=True)} return render(request, "portal/claim.html", context)
def claim(request): if request.method == "POST": with transaction.atomic(): device = get_object_or_404( Device, mac_address=request.POST['mac_address'], owner__isnull=True, ) if not request.user.has_perm(Device.get_perm("claim"), device): raise Exception("Not allowed to claim") device.owner = request.user device.save() return redirect("/portal/claim/") context = { "unclaimed_devices": Device.objects.filter(owner__isnull=True), } return render( request, 'portal/claim.html', context, )
def claim(request): if request.method == "POST": with transaction.atomic(): device = get_object_or_404(Device, mac_address=request.POST["mac_address"]) if not request.user.has_perm(Device.get_perm("claim"), device): raise PermissionDenied() device.owner = request.user device.save() return redirect("/portal/claim/") if request.user.is_superuser: unclaimed = Device.objects.filter(owner__isnull=True) else: remote_ip, _ = get_client_ip(request) unclaimed = Device.objects.filter(owner__isnull=True, last_ip_address=remote_ip) context = { "unclaimed_devices": unclaimed, "super": request.user.is_superuser } return render(request, "portal/claim.html", context)
) @login_required def devices(request): devices = Device.objects.filter(owner=request.user) return render( request, 'portal/devices.html', { 'devices': devices, }, ) @permission_required(Device.get_perm("provision"), fn=device_getter) def new_runreq(request, mac_addr): device = get_object_or_404(Device, mac_address=mac_addr.upper()) if request.method == "POST": rrid = request.POST["runrequest"] runreq = get_object_or_404(RunRequest, id=rrid) device.run_request = runreq device.full_clean() device.save() return redirect("portal_devices") runreqs = RunRequest.objects.filter(auto_generated_id__isnull=False) return render( request,