Example #1
0
    def cast(cls, value):
        if is_null(value):
            return

        if isinstance(value, datetime):
            return value

        return dateutil.parser.parse(value)
Example #2
0
    def cast(cls, value):
        if isinstance(value, PythonsUUID):
            return value

        if is_null(value):
            return

        try:
            return cls.__base_type__(value)
        except ValueError as e:
            raise ValueError(": ".join([str(e), repr(value)]))
Example #3
0
    def cast(cls, value):
        """this method uses a redis connection to retrieve the referenced item"""
        if is_null(value):
            return

        if type(value) in MODELS.values():
            # the value is already a valid model instance
            return value

        try:
            _, module_name, model_name, model_uuid = value.split(':')
        except ValueError:
            raise ValueError('the given value is not a valid repocket reference: {0}'.format(value))

        compound_name = '.'.join([module_name, model_name])
        Model = MODELS.get(compound_name, None)
        if not Model:
            raise ReferenceError('The model {0} is not available in repocket. Make sure that you imported it'.format(compound_name))

        result = Model.objects.get(**{Model.__primary_key__: model_uuid})
        return result
Example #4
0
    def determine_github_repo_from_git_uri(self, git_uri):
        found = not is_null(git_uri) and GITHUB_URI_REGEX.search(git_uri)
        if found:
            return found.groupdict()

        return {}