def admin_reg_fs_by_file(request):
    profile = request.user.get_profile()
    if (not profile.is_net_admin):
        return HttpResponseRedirect("/dashboard")
 
    # the first admin doesn't need to request fs. he/she already owns everything
    if profile.supervisor == profile.user:
        return HttpResponseRedirect("/dashboard")
 
    error_msg = []    
    sup_fs = AdminFlowSpace.objects.filter(user=profile.supervisor)
    if (request.method == "POST"):
        uform = UploadFileForm(request.POST, request.FILES)
        if uform.is_valid():
            
            # parse the file and find the list of flowspaces to be requested
            result = read_fs(request.FILES['file'])
            
            # check if an error happened while parsing the file, 
            if len(result["error"])==0:
                if not multifs_is_subset_of(result['flowspace'],sup_fs):
                    error_msg.append("You can't request for this flowspace. Your flowspace request should be a subset of your supervisor flowspace")
                else:
            
            
                
                    # check if the requested flowspace is a subset of previous flowspace request,
                    # and if so, show an error message:
                    prev_reqs = RequestedAdminFlowSpace.objects.filter(user=request.user)
                    prev_fs = AdminFlowSpace.objects.filter(user=request.user)
                    
                    

                    if multifs_is_subset_of(result['flowspace'],prev_reqs):
                        error_msg.append("You already requested for this flowspace or a superset of it. You can delete the previous request, and then try again")
                    elif multifs_is_subset_of(result['flowspace'],prev_fs):
                        error_msg.append("You already own this flowspace or a superset of it. You can delete the flowspace that you own, and then try again")
                    else:
                        # if there is a pending flowpsace request which is a subset of this one, delete that,
                        # and replace it with this new request:
                        for preq in prev_reqs:
                            if singlefs_is_subset_of(preq,result['flowspace']):
                                preq.delete()
                        # if there is a flowpsace owned by this admin which is a subset of this one, delete that,
                        # and replace it with this new request:
                        for preq in prev_fs:
                            if singlefs_is_subset_of(preq,result['flowspace']):
                                preq.delete()
                      
                        for fs in result['flowspace']:
                            requested_fs = RequestedAdminFlowSpace()
                            copy_fs(fs,requested_fs)
                            requested_fs.user = request.user
                            requested_fs.admin = profile.supervisor
                            requested_fs.req_priority = profile.max_priority_level
                            requested_fs.save()
                            
                        return simple.direct_to_template(request, 
                        template ="openflow/optin_manager/admin_manager/admin_request_successful.html",
                            extra_context = {
                                'user':request.user,
                            },
                        )
            # if there is error while parsing the file
            else:
                error_msg = result["error"]

    else:
        uform = UploadFileForm()
        
    form = AdminOptInForm()
    return simple.direct_to_template(request, 
        template = "openflow/optin_manager/admin_manager/admin_req_fs.html",
        extra_context = {
            'sup_fs':sup_fs,
            'form': form,
            'upload_form':uform,
            'user':request.user,
            'error_msg':error_msg,
        },
    )
The view function for requesting fs for admin
dataset/ETHPy150Open fp7-ofelia/ocf/optin_manager/src/python/openflow/optin_manager/admin_manager/views.py/admin_reg_fs_by_file