Beispiel #1
0
def modify_post(request, **kwargs):
    """
        This view allows you to modify a post. You may delete the post from this page.
        
        You can also view or delete comments from this post.
    """
    pk = kwargs["pk"]
    if request.method == "GET":
        my_post = PostModel.objects.get(id=pk)
        post_form = ModifyForm(instance=my_post)
        return render_to_response(
            "posts/modify.html", {"form": post_form, "pk": pk}, context_instance=RequestContext(request)
        )
    else:
        my_post = PostModel.objects.get(id=pk)
        post_form = ModifyForm(request.POST, instance=my_post)
        if post_form.is_valid():
            delete_post = post_form.cleaned_data["delete_post"]
            if delete_post:
                my_post.delete()
                return HttpResponseRedirect("/posts/")
            else:
                post_form.save()
                return HttpResponseRedirect("/posts/%(pk)s/" % locals())
        else:
            return render_to_response(
                "posts/modify.html",
                {"form": post_form, "pk": pk, "errors": post_form.errors},
                context_instance=RequestContext(request),
            )
Beispiel #2
0
def modify_artwork(request, **kwargs):
    """
        This view allows you to modify the attributes associated with a piece of artwork.
        You may delete a piece of artwork from this page.

        You can also view/delete comments associated with this image.

    """
    pk = kwargs["pk"]
    my_art = ArtworkModel.objects.get(id=pk)
    # pk is the primary key of the art model we want to change
    if request.method == 'GET':
        # If this is a GET request, we should prepopulate a form with the artwork information.
        modify_form = ModifyForm(instance=my_art)
        # modify_form = populate_modify_form(my_art)
        return render_to_response("artwork/modify.html",
                                 {"form":modify_form,
                                  "pk": pk},
                                 context_instance=RequestContext(request))
    else:
        # If this is a POST request, we should take the form data handed to us
        #with the changed form information and resave it. 
        modify_form = ModifyForm(request.POST, request.FILES, instance=my_art)
        if modify_form.is_valid():
            # If the delete checkbox is selected, delete it
            # Hopefully this deletes the comments associated with the image as well.
            if modify_form.cleaned_data['delete_art']:
                my_art.delete()
                return HttpResponseRedirect("http://www.deathweasel.net/artwork/")
            else:
                modify_form.save()
                return HttpResponseRedirect("http://www.deathweasel.net/artwork/%s/" % (pk,))
        else:
            # Recycle the form.
            return render_to_response("artwork/modify.html",
                                     {"form":modify_form,
                                      "pk": pk},
                                     context_instance=RequestContext(request))