def drive(request): assert isinstance(request, HttpRequest) drive = GoogleDrive() file_list = drive.getFiles() return render( request, 'app/drive.html', { 'title': 'Drive', 'file_list': file_list, 'folderId': '1a_ZOqi75h6nTvsUEPDi8NGUrb9Tk-dkh', })
def driveFolder(request, folder, groupId): assert isinstance(request, HttpRequest) drive = GoogleDrive() file_list = drive.getFilesInFolder(folder) group = Group.objects.get(id=groupId) membersList = [] for m in Membership.objects.filter(group=group): membersList.append(m.user_id) return render( request, 'app/drive.html', { 'title': group.name, 'file_list': file_list, 'folderId': folder, 'groupId': groupId, 'membersList': membersList, 'errorMessage': 'app/errors/403.html' })
def createGroup(request, username): assert isinstance(request, HttpRequest) # If the method is a POST request, check if it is a valid Create Group form if request.method == 'POST': form = CreateGroupForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] # If the group already exists, do nothing if Group.objects.filter(name=name).exists(): return render( request, 'app/createGroup.html', { 'title': username, 'form': CreateGroupForm(), 'error': 'Group already exists' }) # If the group does not exists, make a new group else: user = User.objects.get_by_natural_key(username) gDrive = GoogleDrive() # Create a folder in the drive and get its id folderId = gDrive.createGroup(name) # Create a group in the db, setting the owner to be the user who created the group, # and the gdriveid to be the id of the newly created folder group = Group() group.name = name group.owner = user group.gdriveid = folderId # Create a random 16 byte key that will be used for encryption/decryption group.key = get_random_bytes(16) group.save() # Create a membership relationship between the new group and the user who created it membership = Membership() membership.group = group membership.user = user membership.save() # Redirect back to the user page return redirect('/userpage/' + username) else: # If there was no POST request, just render the userpage as normal return render(request, 'app/createGroup.html', { 'title': username, 'form': CreateGroupForm() })
def driveDelete(request, fileId, folder, groupId): assert isinstance(request, HttpRequest) gDrive = GoogleDrive() gDrive.deleteFile(fileId) return driveFolder(request, folder, groupId)
def driveDownload(request, id, title, folder, groupId): assert isinstance(request, HttpRequest) gDrive = GoogleDrive() gDrive.downloadFile(id, title, groupId) return driveFolder(request, folder, groupId)
def driveUpload(request, folder, groupId): assert isinstance(request, HttpRequest) gDrive = GoogleDrive() gDrive.uploadFile(folder, groupId) return driveFolder(request, folder, groupId)
def deleteGroup(request, groupId): gdriveId = Group.objects.get(id=groupId).gdriveid gDrive = GoogleDrive() gDrive.deleteFile(gdriveId) Group.objects.filter(id=groupId).delete() return redirect('userpage', username=request.user)