コード例 #1
0
def create_term(collection, name, data=None):
	"""Instantiates, initialises & returns a term.

	param: pyesdoc.cv.Collection collection: The collection to which the term belongs.
	param: str name: Name of term.
	param: dict data: Arbitrary data associated with term.

	"""
	# Validate inputs.
	v.validate(collection)
	v.validate_term_name(name)
	if data is not None:
		v.validate_term_data(data)

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

	# Instantiate.
	i = Term()
	i.collection = collection
	i.create_date = arrow.utcnow().datetime
	i.label = name
	i.name = name.lower()
	i.status = constants.GOVERNANCE_STATUS_PENDING
	i.uid = uuid.uuid4()
	i.data = data

	# Append to parent & set idx.
	collection.terms.append(i)
	i.idx = len(collection.terms)

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

	return i
コード例 #2
0
def _decode_term(obj):
    """Decodes a term from a dictionary.

    """
    instance = Term()
    instance.alternative_name = obj['alternative_name']
    instance.alternative_url = obj['alternative_url']
    instance.create_date = arrow.get(obj['create_date']).datetime
    instance.data = obj['data']
    instance.description = obj['description']
    instance.idx = obj['idx']
    instance.label = obj['label']
    instance.name = obj['name']
    instance.status = obj['status']
    instance.synonyms = obj['synonyms']
    instance.uid = uuid.UUID(unicode(obj['uid']))
    instance.url = obj['url']
    if instance.parent:
        instance.parent = uuid.UUID(unicode(obj['parent']))

    return instance