def wrap(context): obj = resolve_variable(obj_var, context) ctype = ContentType.objects.get_for_model(obj) form_class = get_form_class_for_object(obj) form = form_class(obj) comments = form.get_comment_model().objects.valid().filter(content_type = ctype, object_pk = str(obj.pk)) if reversed: comments = comments.order_by('-submit_date') context[varname] = comments return ''
def wrap(context): obj = resolve_variable(obj_var, context) ctype = ContentType.objects.get_for_model(obj) request = context.get('request', None) if request is None: raise TemplateSyntaxError("%s: Request not found in context." % tag) form = request.model_comment_form if hasattr(request, 'model_comment_form') else None if not form: form_class = get_form_class_for_object(obj) if request.method == "POST": form = form_class(obj, data = request.POST.copy()) else: form = form_class(obj) form.set_request(request) context[context_var] = form return u''
model = models.get_model(*ctype.split(".", 1)) target = model._default_manager.using(using).get(pk=object_pk) except TypeError: return CommentPostBadRequest("Invalid content_type value: %r" % escape(ctype)) except AttributeError: return CommentPostBadRequest("The given content-type %r does not resolve to a valid model." % escape(ctype)) except ObjectDoesNotExist: return CommentPostBadRequest("No object matching content-type %r and object PK %r exists." % (escape(ctype), escape(object_pk))) except (ValueError, ValidationError), e: return CommentPostBadRequest("Attempting go get content-type %r and object PK %r exists raised %s" % (escape(ctype), escape(object_pk), e.__class__.__name__)) # <Twig> Changed this part # Construct the comment form #form = comments.get_form()(target, data=data) form_class = get_form_class_for_object(target) form = form_class(target, data = data) # </Twig> # print "form.security_errors" # Check security information # if form.security_errors(): # return CommentPostBadRequest("The comment form failed security verification: %s" % str(form.security_errors()) ) # <Twig> Added this to allow custom validation # If there are errors or if we requested a preview show the comment # if form.errors or preview: