예제 #1
0
def changealbumname(request):
    form = AlbumForm(request.POST)
    requestOrigin = request.META['HTTP_REFERER']
    if form.is_valid():
        try:
            album = Album.objects.get(pk=request.POST['albumTitleChangeID'],
                                      owner=request.user)
            currentAlbumTitle = album.title
            album.title = request.POST['title']
            source = get_directory(request.user, None, currentAlbumTitle,
                                   False)
            destination = get_directory(request.user, None, album.title, False)
            change_directory(source, destination)
            photos = Photo.objects.filter(album=album, owner=request.user)
            for photo in photos:
                filename = photo.filename()
                photo.photo = 'photographs/' + photo.owner.username + '/' + album.title + '/' + filename
                photo.save()
            album.save()
            return HttpResponseRedirect(requestOrigin)
        except Exception as e:
            messages.error(request, '%s' % e.message)
            return HttpResponseRedirect(requestOrigin)
    else:
        messages.error(request, 'Please input a proper title')
        return HttpResponseRedirect(requestOrigin)
예제 #2
0
def deletealbum(request):
    requestOrigin = request.META['HTTP_REFERER']
    album = Album.objects.get(pk = request.POST['delete'], owner = request.user)
    photos = Photo.objects.filter(album = album, owner = request.user)
    for photo in photos:
        filename = photo.filename()
        source = photo.photo.path
        destination = get_directory(request.user, filename,)
        photo.photo = 'photographs/' + photo.owner.username + '/' + filename
        photo.save()
        shutil.move(source, destination)
    currentLocation = get_directory(request.user, None, album.title)
    try:
        shutil.rmtree(currentLocation)
    except Exception as e:
        messages.error(request, '%s (%s)' % (e.message, type(e)))
    album.delete()
    return HttpResponseRedirect(requestOrigin)
예제 #3
0
def deletealbum(request):
    requestOrigin = request.META['HTTP_REFERER']
    album = Album.objects.get(pk=request.POST['delete'], owner=request.user)
    photos = Photo.objects.filter(album=album, owner=request.user)
    for photo in photos:
        filename = photo.filename()
        source = photo.photo.path
        destination = get_directory(
            request.user,
            filename,
        )
        photo.photo = 'photographs/' + photo.owner.username + '/' + filename
        photo.save()
        shutil.move(source, destination)
    currentLocation = get_directory(request.user, None, album.title)
    try:
        shutil.rmtree(currentLocation)
    except Exception as e:
        messages.error(request, '%s (%s)' % (e.message, type(e)))
    album.delete()
    return HttpResponseRedirect(requestOrigin)
예제 #4
0
def assignphototoalbum(request):
    albumSelected = Album.objects.get(pk = request.POST['albumid'], owner = request.user)
    photo = Photo.objects.get(pk = request.POST['addToAlbum'], owner = request.user)
    filename = photo.filename()
    source = photo.photo.path
    destination = get_directory(request.user, filename, albumSelected)
    shutil.move(source, destination)
    photo.album = albumSelected
    photo.photo = 'photographs/' + photo.owner.username + '/' + albumSelected.title + '/' + filename
    photo.save()
    requestOrigin = request.META['HTTP_REFERER']
    return HttpResponseRedirect(requestOrigin)
예제 #5
0
def assignphototoalbum(request):
    albumSelected = Album.objects.get(pk=request.POST['albumid'],
                                      owner=request.user)
    photo = Photo.objects.get(pk=request.POST['addToAlbum'],
                              owner=request.user)
    filename = photo.filename()
    source = photo.photo.path
    destination = get_directory(request.user, filename, albumSelected)
    shutil.move(source, destination)
    photo.album = albumSelected
    photo.photo = 'photographs/' + photo.owner.username + '/' + albumSelected.title + '/' + filename
    photo.save()
    requestOrigin = request.META['HTTP_REFERER']
    return HttpResponseRedirect(requestOrigin)
예제 #6
0
def changealbumname(request):
    form = AlbumForm(request.POST)
    requestOrigin = request.META['HTTP_REFERER']
    if form.is_valid():
        try:
            album = Album.objects.get(pk = request.POST['albumTitleChangeID'], owner=request.user)
            currentAlbumTitle = album.title
            album.title = request.POST['title']
            source = get_directory(request.user, None, currentAlbumTitle, False)
            destination = get_directory(request.user, None, album.title, False)
            change_directory(source,destination)
            photos = Photo.objects.filter(album = album, owner = request.user)
            for photo in photos:
                filename = photo.filename()
                photo.photo = 'photographs/' + photo.owner.username + '/' + album.title + '/' + filename
                photo.save()
            album.save()
            return HttpResponseRedirect(requestOrigin)
        except Exception as e:
            messages.error(request, '%s' % e.message)
            return HttpResponseRedirect(requestOrigin)
    else:
        messages.error(request, 'Please input a proper title')
        return HttpResponseRedirect(requestOrigin)