def add_image(request): """ Add existing image(s) in the library to another facet.""" if request.method == "POST": add_image_form = AddImageForm(request.POST, request=request) if add_image_form.is_valid(): images = request.POST.getlist('images') # retrieve the facet the images should be associated with facet_type = request.POST.get('type') if facet_type == "webfacet": facet_id = request.POST.get('webfacet') facet = get_object_or_404(WebFacet, id=facet_id) elif facet_type == "printfacet": facet_id = request.POST.get('printfacet') facet = get_object_or_404(PrintFacet, id=facet_id) elif facet_type == "audiofacet": facet_id = request.POST.get('audiofacet') facet = get_object_or_404(AudioFacet, id=facet_id) elif facet_type == "videofacet": facet_id = request.POST.get('videofacet') facet = get_object_or_404(VideoFacet, id=facet_id) # connect image to facet for image in images: img_ins = get_object_or_404(ImageAsset, id=image) facet.image_assets.add(img_ins) facet.save() # record action for activity stream action.send(request.user, verb="added image", action_object=images[0], target=facet) return redirect('story_detail', pk=facet.story.id)
def add_videofacet_image(request): """ Add existing image(s) in the library to another videofacet.""" if request.method == "POST": add_image_form = AddImageForm(request.POST, request=request) if add_image_form.is_valid(): videofacet_id = request.POST.get('videofacet') print "videoFACETid: ", videofacet_id videofacet = get_object_or_404(VideoFacet, id=videofacet_id) images = request.POST.getlist('images') print "IMAGES: ", images for image in images: img_ins = get_object_or_404(ImageAsset, id=image) print "IMGins: ", img_ins videofacet.image_assets.add(img_ins) videofacet.save() return redirect('story_detail', pk=videofacet.story.id)