Esempio n. 1
0
def retrieve_xml(docID):
    """ Get the xml assiociated to the id

    :param request:
    :return:
    """
    xml_data = XMLdata.getXMLdata(docID)
    xml_dta = json.dumps(xml_data.items()[3][1],sort_keys=False)
    xml_d = json.loads(xml_dta, object_pairs_hook=OrderedDict) # Convert the ordered dict in dict
    xsdDocData = XMLdata.unparse(xml_d)
    xsdEncoded = xsdDocData.encode('utf-8')

    return xsdEncoded
Esempio n. 2
0
def get_navigation_node_for_document(node_id, document_id):
    navigation_node = Navigation.objects.get(pk=node_id)
    original_node = Navigation.objects.get(pk=node_id)

    if "projection" in navigation_node.options and navigation_node.options[
            'projection'] is not None:
        # **************
        # FIXME duplicate of parser code
        # Get projection

        filters = []
        while True:
            # add filter to the list of filters
            if 'filter' in navigation_node.options and navigation_node.options[
                    'filter'] is not None:
                filters.append(navigation_node.options['filter'])

            # if no parent, stops the filter lookup
            if navigation_node.parent is None:
                break
            else:  # if parent, continue the filter lookup at the parent level
                navigation_node = navigation_get(navigation_node.parent)

        # get the documents matching the query
        doc = XMLdata.getXMLdata(document_id)
        #.getXMLdata_schema
        template_id = ''
        for k, v in doc.items():
            if k == "schema":
                template_id = v

        documents_id = [
            str(get_projection(document)) for document in query.execute_query(
                template_id, filters, '{"_id": 1}')
        ]
        #  End fixme
        # **************

        # If the document is one of the document we return the navigation node, else return None
        if document_id in documents_id:
            return original_node
        else:
            return None
    else:
        navigation_children = navigation_node.children

        if len(navigation_children) == 0:
            return None
        else:
            navigation_nodes = [
                get_navigation_node_for_document(child_id, document_id)
                for child_id in navigation_children
            ]
            navigation_nodes = [
                nav_node for nav_node in navigation_nodes
                if nav_node is not None
            ]

            if len(navigation_nodes) != 1:
                return None
            else:
                return navigation_nodes[0]