def edit(request, id): """ Description: Edit given video If edit is successful, return to page with videos with a success status message If edit isn't succesful, go to the video edit page. Arguments: - request: HttpRequest object - id: id of video of interest Return: None Author: Nnoduka Eruchalu """ video = get_object_or_404(Video, id=id) media = get_object_or_404(Media, video=video) if request.method == 'POST': form = YoutubeEditForm(request.POST, instance=video) form2 = MediaEditForm(request.POST, instance=media) # use & or all to avoid short-circuiting if form.is_valid() & form2.is_valid(): vid = form.save() vid.save() # because tags dont save till save_m2m is called media_new = form2.save() if media_new.gallery: redirect = reverse("mediaGalleryContent", kwargs={'id':media_new.gallery.id}) else: redirect = reverse("mediaLibrary") messages.add_message( request, messages.SUCCESS, "Video successfully edited") return HttpResponseRedirect(redirect) # if request.method != 'POST' else: form = YoutubeEditForm(instance=video) form2 = MediaEditForm(instance=media) return render_to_response("youtube/edit.html", {'form':form, 'form2':form2}, context_instance = RequestContext(request))
def edit(request, id): """ Description: Edit given photo If edit is successful, return to page with photos with a success status message If edit isn't succesful, go to the photo edit page. Arguments: - request: HttpRequest object - id: Photo object of interest Return: HttpResponse Author: Nnoduka Eruchalu """ photo = get_object_or_404(Photo, id=id) media = get_object_or_404(Media, photo=photo) if request.method == 'POST': form = PhotoEditForm(request.POST, instance=photo) form2 = MediaEditForm(request.POST, instance=media) # use & or all to avoid short-circuiting if form.is_valid() & form2.is_valid(): form.save() media_new = form2.save() if media_new.gallery: redirect = reverse("mediaGalleryContent", kwargs={'id':media_new.gallery.id}) else: redirect = reverse("mediaLibrary") messages.add_message( request, messages.SUCCESS, "Photo successfully edited") return HttpResponseRedirect(redirect) # if request.method != 'POST' else: form = PhotoEditForm(instance=photo) form2 = MediaEditForm(instance=media) return render_to_response("photo/edit.html", {'form':form, 'form2':form2}, context_instance = RequestContext(request))