def batchFilePost(request, index): if request.method == 'POST': image = request.FILES albumName = request.POST['batchFilename'] batchName = albumName + " Photo " form = addBatchPhotoForm(request.POST, request.FILES) users = [] if form.is_valid(): data = form.cleaned_data formPermissions = form.cleaned_data.get('permissions') for circles in formPermissions: circle = Circle.objects.get(id=circles.id) for user in circle.users.all(): print user.username users.append(user.id) formUsers = None if form.cleaned_data.get('users'): formUsers = form.cleaned_data.get('users') if formUsers is not None: for user in formUsers: print user.username users.append(user.id) #users = [] photoList = [] for counter,file in enumerate(request.FILES): file = request.FILES['file['+`counter`+']'] newCounter = counter +1; imageName = request.POST["imageFilename["+`newCounter`+"]"] newPhoto = Photo(owner=request.user, name=imageName, photo=file) newPhoto.save() newPhoto.permissions.add(*users) newPhoto.save() photoList.append(newPhoto) newAlbum = PhotoAlbum(owner=request.user, name=albumName) newAlbum.save() newAlbum.photos.add(*photoList) newAlbum.save() #newPhoto = form.save(commit=False) #newPhoto.owner = request.user #form.save_m2m() return redirect('index')
def filePost(request): if request.method == 'POST': data = request.FILES users = [] newPhoto = Photo(owner=request.user, name=data['file'].name, photo=data['file']) newPhoto.save() newPhoto.permissions.add(*users) newPhoto.save() #newPhoto = form.save(commit=False) #newPhoto.owner = request.user #form.save_m2m() return redirect('index')
def addPhoto(request): if request.method == 'POST': form = addPhotoForm(request.POST, request.FILES) users = [] if form.is_valid(): data = form.cleaned_data formPermissions = form.cleaned_data.get('permissions') for circles in formPermissions: circle = Circle.objects.get(id=circles.id) for user in circle.users.all(): print user.username users.append(user.id) formUsers = None if form.cleaned_data.get('users'): formUsers = form.cleaned_data.get('users') if formUsers is not None: for user in formUsers: print user.username users.append(user.id) newPhoto = Photo(owner=request.user, name=data['name'], photo=data['photo']) newPhoto.save() newPhoto.permissions.add(*users) newPhoto.save() #newPhoto = form.save(commit=False) #newPhoto.owner = request.user #form.save_m2m() return redirect('index')
def batchFilePost(request, index): if request.method == 'POST': image = request.FILES albumName = request.POST['batchFilename'] batchName = albumName + " Photo " form = addBatchPhotoForm(request.POST, request.FILES) users = [] if form.is_valid(): data = form.cleaned_data formPermissions = form.cleaned_data.get('permissions') for circles in formPermissions: circle = Circle.objects.get(id=circles.id) for user in circle.users.all(): print user.username users.append(user.id) formUsers = None if form.cleaned_data.get('users'): formUsers = form.cleaned_data.get('users') if formUsers is not None: for user in formUsers: print user.username users.append(user.id) #users = [] photoList = [] for counter, file in enumerate(request.FILES): file = request.FILES['file[' + ` counter ` + ']'] newCounter = counter + 1 imageName = request.POST["imageFilename[" + ` newCounter ` + "]"] newPhoto = Photo(owner=request.user, name=imageName, photo=file) newPhoto.save() newPhoto.permissions.add(*users) newPhoto.save() photoList.append(newPhoto) newAlbum = PhotoAlbum(owner=request.user, name=albumName) newAlbum.save() newAlbum.photos.add(*photoList) newAlbum.save() #newPhoto = form.save(commit=False) #newPhoto.owner = request.user #form.save_m2m() return redirect('index')