Exemplo n.º 1
0
def create_scope(authority, name, description, url):
	"""Instantiates, initialises & returns a term scope.

	"""
	# Validate inputs.
	v.validate(authority)
	v.validate_scope_name(name)
	v.validate_scope_description(description)
	v.validate_scope_url(url)

	# Format inputs.
	name = unicode(name).strip()
	description = unicode(description).strip()
	url = unicode(url).strip()

	# Instantiate.
	i = Scope()
	i.authority = authority
	i.description = description
	i.label = name
	i.name = name.lower()
	i.uid = uuid.uuid4()
	i.url = url

	# Append to parent & set idx.
	authority.scopes.append(i)
	i.idx = len(authority.scopes)

	# Raise validation exception (if appropriate).
	if not i.is_valid:
		raise ValidationError(i.errors)

	return i
Exemplo n.º 2
0
def _decode_scope(obj):
    """Decodes a termset from a dictionary.

    """
    instance = Scope()
    instance.collections = [_decode_collection(i) if isinstance(i, dict) else i
                            for i in obj['collections']]
    instance.description = obj['description']
    instance.idx = obj['idx']
    instance.label = obj['label']
    instance.name = obj['name']
    instance.uid = uuid.UUID(unicode(obj['uid']))
    instance.url = obj['url']

    # Wire hierarchy.
    for collection in instance:
        if isinstance(collection, Collection):
            collection.scope = instance

    return instance