Example #1
0
def albumUpload(request):
    thisUser = None
    if request.user.is_authenticated():
        thisUser = request.user

        myCircles = Circle.objects.filter(owner=thisUser)

        myAlbums = PhotoAlbum.objects.filter(owner=thisUser)

        myPhotos = Photo.objects.filter(owner=thisUser)

        users = User.objects.all().order_by('name')

        circleForm = addCircleForm(request.POST)

        albumForm = addAlbumForm(request.POST)
        albumForm.fields['photos'].queryset = Photo.objects.filter(
            owner=thisUser)

        circleQuery = Circle.objects.filter(owner=thisUser)

        photoForm = addPhotoForm(request.POST)
        photoForm.fields['permissions'].queryset = circleQuery

        batchPhotoForm = addBatchPhotoForm(request.POST)
        batchPhotoForm.fields['permissions'].queryset = circleQuery

    else:
        myCircles = None
        myAlbums = None
        myPhotos = None

        users = User.objects.all().order_by('name')
        circleForm = addCircleForm()
        albumForm = addAlbumForm()
        photoForm = addPhotoForm()
        batchPhotoForm = addBatchPhotoForm()

    context = {
        'myCircles': myCircles,
        'myAlbums': myAlbums,
        'myPhotos': myPhotos,
        'users': users,
        'circleForm': circleForm,
        'albumForm': albumForm,
        'photoForm': photoForm,
        'requestPost': request.POST,
        'batchPhotoForm': batchPhotoForm,
    }

    return render(request, 'familypix/albumUpload.html', context)
Example #2
0
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')
Example #3
0
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')
Example #4
0
def albumUpload(request):
    thisUser = None
    if request.user.is_authenticated():
        thisUser = request.user
    
        myCircles = Circle.objects.filter(owner=thisUser)

        myAlbums = PhotoAlbum.objects.filter(owner = thisUser)

        myPhotos = Photo.objects.filter(owner=thisUser)
    
        users = User.objects.all().order_by('name')
    
        circleForm = addCircleForm(request.POST)
    
        albumForm = addAlbumForm(request.POST)
        albumForm.fields['photos'].queryset = Photo.objects.filter(owner=thisUser)
        
        circleQuery = Circle.objects.filter(owner=thisUser)
        
        photoForm = addPhotoForm(request.POST)
        photoForm.fields['permissions'].queryset = circleQuery
        
        batchPhotoForm = addBatchPhotoForm(request.POST)
        batchPhotoForm.fields['permissions'].queryset = circleQuery
        
    else:
        myCircles = None
        myAlbums = None
        myPhotos = None
        
        
        users = User.objects.all().order_by('name')
        circleForm = addCircleForm()
        albumForm = addAlbumForm()    
        photoForm = addPhotoForm()
        batchPhotoForm = addBatchPhotoForm()
    
    context = {'myCircles' : myCircles, 'myAlbums' : myAlbums, 'myPhotos' : myPhotos, 'users': users, 'circleForm' : circleForm, 'albumForm': albumForm, 'photoForm' : photoForm, 'requestPost' : request.POST, 'batchPhotoForm' : batchPhotoForm,}
    
    return render(request, 'familypix/albumUpload.html', context)