Esempio n. 1
0
 def location(self, val):
     if not isinstance(val, tuple):
         raise dataobj.DataSchemaException("location must be a tuple")
     if len(val) != 2:
         raise dataobj.DataSchemaException(
             "location object must be a tuple of lat/lon only")
     self._set_single("loc.lat", val[0], coerce=self._float())
     self._set_single("loc.lon", val[1], coerce=self._float())
Esempio n. 2
0
 def self_archiving_publisher(self, val):
     if not isinstance(val, tuple):
         raise dataobj.DataSchemaException(
             "self_archiving_publisher must be a tuple of policy and number of months"
         )
     self._set_single("dc:source.self_archiving.publisher.policy",
                      val[0],
                      coerce=self._utf8_unicode())
     self._set_single("dc:source.self_archiving.publisher.embargo",
                      val[1],
                      coerce=self._int())
Esempio n. 3
0
    def set_reset_token(self, token, timeout=None, expires=None):
        if expires is None and timeout is None:
            raise dataobj.DataSchemaException(
                "You must provide a timeout or an expiry date for the reset token"
            )
        if expires is None:
            expires = datetime.utcnow() + timedelta(0, timeout)
        if not isinstance(expires, basestring):
            expires = expires.strftime("%Y-%m-%dT%H:%M:%SZ")

        self._set_single("reset_token", token, coerce=self._utf8_unicode())
        self._set_single("reset_expires", expires, coerce=self._date_str())
    def license(self, obj):
        # validate the object structure quickly
        allowed = ["title", "type", "url", "version"]
        for k in obj.keys():
            if k not in allowed:
                raise dataobj.DataSchemaException("License object must only contain the following keys: {x}".format(x=", ".join(allowed)))

        # coerce the values of the keys
        uc = dataobj.to_unicode()
        for k in allowed:
            if k in obj:
                obj[k] = self._coerce(obj[k], uc)

        # finally write it
        self._set_single("metadata.license_ref", obj)
    def projects(self, objlist):
        # validate the object structure quickly
        allowed = ["name", "grant_number", "identifier"]
        for obj in objlist:
            for k in obj.keys():
                if k not in allowed:
                    raise dataobj.DataSchemaException("Project object must only contain the following keys: {x}".format(x=", ".join(allowed)))

            # coerce the values of some of the keys
            uc = dataobj.to_unicode()
            for k in ["name", "grant_number"]:
                if k in obj:
                    obj[k] = self._coerce(obj[k], uc)

        # finally write it
        self._set_list("metadata.project", objlist)