688 |
688 |
689 def __init__(self, content, projects): |
689 def __init__(self, content, projects): |
690 self.content = content |
690 self.content = content |
691 self.projects = projects |
691 self.projects = projects |
692 |
692 |
693 def get_merged_project(self, shot_by_shot=True): |
693 def get_merged_project(self, shot_by_shot=True, only_visible=True): |
694 # New project |
694 # New project |
695 contents = [ self.content, ] |
695 contents = [ self.content, ] |
696 |
696 |
697 # Get user |
697 # Get user |
698 user = User.objects.get(username="admin") |
698 user = User.objects.get(username="admin") |
716 ctt_disp_node.remove(dec_node) |
716 ctt_disp_node.remove(dec_node) |
717 |
717 |
718 # Parse all projects |
718 # Parse all projects |
719 for p in self.projects: |
719 for p in self.projects: |
720 p_xml = lxml.etree.fromstring(p.ldt_encoded) |
720 p_xml = lxml.etree.fromstring(p.ldt_encoded) |
|
721 # We only keep the decoupages (cuttings) visible in the default view, which means the first display. |
|
722 first_display = p_xml.xpath('/iri/displays/display')[0] |
|
723 current_disp_node = first_display.xpath('content[@id="' + self.content.iri_id + '"]')[0] |
721 # First version of ensemble |
724 # First version of ensemble |
722 ens = p_xml.xpath('/iri/annotations/content[@id="' + self.content.iri_id + '"]/ensemble') |
725 ens = p_xml.xpath('/iri/annotations/content[@id="' + self.content.iri_id + '"]/ensemble') |
723 for e in ens: |
726 for e in ens: |
724 content_node.append(e) |
727 content_node.append(e) |
725 # Update display |
728 # Update display |
726 for c in e.xpath('decoupage'): |
729 for c in e.xpath('decoupage'): |
727 c_node = lxml.etree.SubElement(ctt_disp_node, 'decoupage') |
730 if not only_visible or (only_visible and len(current_disp_node.xpath('decoupage[@id="' + c.get('id') + '"]'))>0 ) : |
728 c_node.set(u'idens', e.get('id')) |
731 c_node = lxml.etree.SubElement(ctt_disp_node, 'decoupage') |
729 c_node.set(u'id', c.get('id')) |
732 c_node.set(u'idens', e.get('id')) |
|
733 c_node.set(u'id', c.get('id')) |
730 # Second version of ensemble |
734 # Second version of ensemble |
731 ens = p_xml.xpath('/iri/annotations/content[@id="' + self.content.iri_id + '"]/ensembles/ensemble') |
735 ens = p_xml.xpath('/iri/annotations/content[@id="' + self.content.iri_id + '"]/ensembles/ensemble') |
732 for e in ens: |
736 for e in ens: |
733 content_node.append(e) |
737 content_node.append(e) |
734 # Update display |
738 # Update display |
735 for c in e.xpath('decoupage'): |
739 for c in e.xpath('decoupage'): |
736 c_node = lxml.etree.SubElement(ctt_disp_node, 'decoupage') |
740 if not only_visible or (only_visible and len(current_disp_node.xpath('decoupage[@id="' + c.get('id') + '"]'))>0 ) : |
737 c_node.set(u'idens', e.get('id')) |
741 c_node = lxml.etree.SubElement(ctt_disp_node, 'decoupage') |
738 c_node.set(u'id', c.get('id')) |
742 c_node.set(u'idens', e.get('id')) |
739 |
743 c_node.set(u'id', c.get('id')) |
740 |
744 |
741 proj.ldt = lxml.etree.tostring(doc, pretty_print=True) |
745 proj.ldt = lxml.etree.tostring(doc, pretty_print=True) |
742 |
746 |
743 return proj |
747 return proj |
744 |
748 |