def post_annotation(request): if request.method != "POST": return HttpResponseNotAllowed(["POST"]) if request.user.is_anonymous(): return HttpResponseForbidden(_("Sorry, only logged users can annotate.")) form = NewAnnotationForm(request.POST) if form.is_valid(): new_annotation = Annotation(content_type=form.cleaned_data["content_type"], object_id=form.cleaned_data["object_id"], user=request.user, selection_start=form.cleaned_data["selection_start"], selection_end=form.cleaned_data["selection_end"], comment=form.cleaned_data["comment"], flags=form.cleaned_data["flags"], color=form.cleaned_data["color"]) new_annotation.save() return HttpResponseRedirect(new_annotation.get_absolute_url()) else: return HttpResponseBadRequest()