Esempio n. 1
0
def update_assignment(request):
   if request.method == 'POST':
  
        post=request.POST
        files=request.FILES
        user = AuthService.get_current_user(request)
        token = token_service.get_access_token(constant.Resources.MSGraph, user.o365_user_id)
        education_service = EducationService(user.tenant_id, token)  
        assignment = education_service.get_assignment(post["classId"],post["assignmentId"])  

        if assignment.status=='draft' and post['assignmentStatus']=='assigned':
            education_service.publish_assignment(post['classId'], post['assignmentId'])
        
       
        files= request.FILES.getlist("newResource")

        if files !=None:
            resourceFolderURL = education_service.get_Assignment_Resource_Folder_URL(post["classId"],post["assignmentId"])["value"]
            ids = getIds(resourceFolderURL)
            for file in files:
               driveFile = uploadFileToOneDrive(resourceFolderURL,file,education_service)      
               resourceUrl = "https://graph.microsoft.com/v1.0/drives/" + ids[0] + "/items/" + driveFile["id"]
               education_service.add_assignment_resources(post["classId"],post["assignmentId"],driveFile["name"],resourceUrl)
    
        referer = request.META.get('HTTP_REFERER') 
        if referer.find("?")==-1:
            referer +="?tab=assignments"
        return HttpResponseRedirect(referer)
Esempio n. 2
0
def new_assignment(request):
    if request.method == 'POST':        
        post=request.POST        
        user = AuthService.get_current_user(request)
        token = token_service.get_access_token(constant.Resources.MSGraph, user.o365_user_id)
        education_service = EducationService(user.tenant_id, token)
        dueDate = post["duedate"] + "T" + post["duetime"] + "Z"       
        dueDateUTC=datetime.strptime(dueDate,"%m/%d/%YT%H:%M %pZ").strftime("%Y-%m-%dT%H:%M:%SZ")
        result = education_service.add_assignment(post["classId"],post["name"],dueDateUTC)        
        jsonContent = result.content.decode('utf8')
        assignment = json.loads(jsonContent)
        if post['status']=="assigned":
           education_service.publish_assignment(post["classId"],assignment["id"])


        files= request.FILES.getlist("fileUpload")
        if files !=None:
            resourceFolderURL = education_service.get_Assignment_Resource_Folder_URL(post["classId"],assignment["id"])["value"]
            ids = getIds(resourceFolderURL)
            
            for file in files:
               driveFile = uploadFileToOneDrive(resourceFolderURL,file,education_service)      
               resourceUrl = "https://graph.microsoft.com/v1.0/drives/" + ids[0] + "/items/" + driveFile["id"]
               education_service.add_assignment_resources(post["classId"],assignment["id"],driveFile["name"],resourceUrl)
    
        
        referer = request.META.get('HTTP_REFERER') 
        if referer.find("?")==-1:
            referer +="?tab=assignments"
        return HttpResponseRedirect(referer)