示例#1
0
 def prepare_value(self, value):
     # test if the value is already signed. if yes, we do not resign it
     try:
         signing.loads(value)
         return value
     except signing.BadSignature:
         return signing.dumps(value)
示例#2
0
    def to_python(self, value):
        """ a broken/manipulated value will raise an exception of
        type signing.BadSignature. We do not catch it, it should raise """

        original = signing.loads(value)
        return original
示例#3
0
        return ReviewPostBadRequest(
            "The given content-type %r does not resolve to a valid model." % \
                escape(ctype))
    except ObjectDoesNotExist:
        return ReviewPostBadRequest(
            "No object matching content-type %r and object PK %r exists." % \
                (escape(ctype), escape(object_pk)))
    except (ValueError, ValidationError), e:
        return ReviewPostBadRequest(
            "Attempting go get content-type %r and object PK %r exists raised %s" % \
                (escape(ctype), escape(object_pk), e.__class__.__name__))

    # Do we want to preview the review?
    preview = "preview" in data

    category = signing.loads(data['category'])

    # Construct the review form
    form = reviews.get_form()(target, data=data, category=category)

    # Check security information
    if form.security_errors():
        return ReviewPostBadRequest(
            "The review form failed security verification: %s" % \
                escape(str(form.security_errors())))

    # If there are errors or if we requested a preview show the review
    if form.errors or not form.formset.is_valid() or preview:
        template_list = [
            # Now the usual directory based template heirarchy.
            "reviews/%s/%s/preview.html" % (model._meta.app_label, model._meta.module_name),