def do_restore(request, entry_id, recv_data): user = User.objects.get(id=request.user.id) entry = Entry.objects.filter(id=entry_id, is_active=False).first() if not entry: return JsonResponse( data={'msg': 'Failed to get entry from specified parameter'}, status=400) # checks that a same name entry corresponding to the entity is existed, or not. dup_entry = Entry.objects.filter(schema=entry.schema.id, name=re.sub(r'_deleted_[0-9_]*$', '', entry.name), is_active=True).first() if dup_entry: return JsonResponse(data={ 'msg': '', 'entry_id': dup_entry.id, 'entry_name': dup_entry.name }, status=400) entry.set_status(Entry.STATUS_CREATING) # Create a new job job = Job.new_restore(user, entry) restore_entry.delay(entry.id, job.id) return HttpResponse('Success to queue a request to restore an entry')
def do_restore(request, entry_id, recv_data): entry, error = get_obj_with_check_perm(request.user, Entry, entry_id, ACLType.Full) if error: return error if entry.is_active: return JsonResponse( data={"msg": "Failed to get entry from specified parameter"}, status=400) # checks that a same name entry corresponding to the entity is existed, or not. dup_entry = Entry.objects.filter( schema=entry.schema.id, name=re.sub(r"_deleted_[0-9_]*$", "", entry.name), is_active=True, ).first() if dup_entry: return JsonResponse( data={ "msg": "", "entry_id": dup_entry.id, "entry_name": dup_entry.name }, status=400, ) entry.set_status(Entry.STATUS_CREATING) # Create a new job to restore deleted entry and run it job = Job.new_restore(request.user, entry) job.run() return HttpResponse("Success to queue a request to restore an entry")
def do_restore(request, entry_id, recv_data): user = User.objects.get(id=request.user.id) entry, error = get_object_with_check_permission(user, Entry, entry_id, ACLType.Full) if error: return error if entry.is_active: return JsonResponse( data={'msg': 'Failed to get entry from specified parameter'}, status=400) # checks that a same name entry corresponding to the entity is existed, or not. dup_entry = Entry.objects.filter( schema=entry.schema.id, name=re.sub(r'_deleted_[0-9_]*$', '', entry.name), is_active=True).first() if dup_entry: return JsonResponse( data={'msg': '', 'entry_id': dup_entry.id, 'entry_name': dup_entry.name}, status=400) entry.set_status(Entry.STATUS_CREATING) # Create a new job to restore deleted entry and run it job = Job.new_restore(user, entry) job.run() return HttpResponse('Success to queue a request to restore an entry')