How to use the rdmo.conditions.models.Condition.objects.get function in rdmo

To help you get started, we’ve selected a few rdmo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rdmorganiser / rdmo / rdmo / conditions / utils.py View on Github external
def import_conditions(conditions_node):

    nsmap = conditions_node.nsmap

    for condition_node in conditions_node.iterchildren():
        condition_uri = condition_node[get_ns_tag('dc:uri', nsmap)].text

        try:
            condition = Condition.objects.get(uri=condition_uri)
        except Condition.DoesNotExist:
            condition = Condition()

        condition.uri_prefix = condition_uri.split('/conditions/')[0]
        condition.key = condition_uri.split('/')[-1]
        condition.comment = condition_node[get_ns_tag('dc:comment', nsmap)]
        condition.relation = condition_node['relation']

        try:
            source_uri = condition_node['source'].get(get_ns_tag('dc:uri', nsmap))
            condition.source = Attribute.objects.get(uri=source_uri)
        except (AttributeError, Attribute.DoesNotExist):
            condition.source = None

        try:
            condition.target_text = condition_node['target_text']