Exemplo n.º 1
0
    def validate(self):
        from ductus.resource import get_resource_database
        from ductus.resource.ductmodels import DuctModelMismatchError
        resource_database = get_resource_database()

        for r in self._re_objects:
            match = r.match(self.uri)
            if match is not None:
                hash_type, digest = match.group(1), match.group(2)
                urn = "urn:%s:%s" % (hash_type, digest)
                if urn not in resource_database:
                    raise forms.ValidationError(
                        _(u"This urn cannot be found on the server you are currently accessing."
                          ))
                try:
                    Picture.load(urn)
                except DuctModelMismatchError:
                    raise forms.ValidationError(
                        _(u"This urn represents content that is not a picture."
                          ))
                # fixme: handle exception raised by get_resource_object if it's
                # actually a blob
                self.urn = urn
                return

        # this should never be reached
        assert self.handles(self.uri)
Exemplo n.º 2
0
    def validate(self):
        from ductus.resource import get_resource_database
        from ductus.resource.ductmodels import DuctModelMismatchError
        resource_database = get_resource_database()

        for r in self._re_objects:
            match = r.match(self.uri)
            if match is not None:
                hash_type, digest = match.group(1), match.group(2)
                urn = "urn:%s:%s" % (hash_type, digest)
                if urn not in resource_database:
                    raise forms.ValidationError(_(u"This urn cannot be found on the server you are currently accessing."))
                try:
                    Picture.load(urn)
                except DuctModelMismatchError:
                    raise forms.ValidationError(_(u"This urn represents content that is not a picture."))
                # fixme: handle exception raised by get_resource_object if it's
                # actually a blob
                self.urn = urn
                return

        # this should never be reached
        assert self.handles(self.uri)