Ejemplo n.º 1
0
    def run(self):
        ip = self.get_information_package()
        rootdir = os.path.dirname(ip.object_path) if os.path.isfile(
            ip.object_path) else ip.object_path
        xml = ip.package_mets_path
        parsed = parse_submit_description(xml, rootdir)

        ip.label = parsed.get('label')
        ip.entry_date = parsed.get('entry_date')
        ip.start_date = parsed.get('start_date')
        ip.end_date = parsed.get('end_date')

        if ip.policy is None:
            parsed_policy = parsed.get('altrecordids', {}).get('POLICYID')[0]
            ip.policy = ArchivePolicy.objects.get(policy_id=parsed_policy)

        ip.information_class = parsed.get(
            'information_class') or ip.policy.information_class
        if ip.information_class != ip.policy.information_class:
            raise ValueError(
                'Information class in submit description ({}) and policy ({}) does not match'
                .format(ip.information_class, ip.policy.information_class))

        for agent_el in get_agents(etree.parse(xml)):
            agent = Agent.objects.from_mets_element(agent_el)
            ip.agents.add(agent)

        ip.save()
Ejemplo n.º 2
0
def add_agents_from_xml(ip, xml):
    for agent_el in get_agents(etree.parse(xml)):
        agent = Agent.objects.from_mets_element(agent_el)
        ip.agents.add(agent)