Ejemplo n.º 1
0
def editphotoset(request, id):
    photo_form = PhotoUploadForm()
    photoset = get_object_or_404(PhotoSet, id = id)
    photoset_form = PhotoSetForm (instance = photoset)

    if request.method == 'POST':
        if request.POST['action'] == 'addphoto':
            photo_form = PhotoUploadForm(request.user, request.POST, request.FILES)
            if photo_form.is_valid():
                photo = photo_form.save()
                photo.member = request.user
                photo.photoset.add(photoset)
                photo.save()

        elif request.POST['action'] == 'editphotoset':
            photoset_form = PhotoSetForm(request.user, request.POST, instance = photoset)
            if photoset_form.is_valid():
                photoset = photoset_form.save(commit = False)
                
                photoset.save()
                
                redirect_to = "/photos/photoset/%i" % photoset.pk
                return HttpResponseRedirect(redirect_to)



    return render_to_response('photos/editphotoset.html', {'photo_form': photo_form,
                                                            'photoset_form': photoset_form,
                                                            
                                                            'photoset': photoset},
                                                            context_instance = RequestContext(request))
Ejemplo n.º 2
0
def newphotoset(request):
    if request.method == 'POST':
        photoset_form = PhotoSetForm(request.user, request.POST)
        if photoset_form.is_valid():
            photoset = photoset_form.save(commit = False)
            photoset.user = request.user
            photoset.save()
            redirect_to = "/photos/edit/photoset/%i" % photoset.pk
            return HttpResponseRedirect(redirect_to)
    else:
        photoset_form = PhotoSetForm()
    return render_to_response('photos/newphotoset.html', {'photoset_form': photoset_form}, context_instance = RequestContext(request))