Exemplo n.º 1
0
def create_product(name, attributes, catalog, category_path):

    product = None

    category = catalog.get_category(category_path)
    if not category.is_leaf():
        raise Exception("Category path %s does not point to leaf!" % (category_path,))

    category_attributes = category.get_attributes()

    product = _get_product(name)

    if product is None:
        
        products_root = _get_products_root()

        product = db.node(name=name)
        product.PRODUCT_CATEGORY(category.get_node())
        products_root.PRODUCT(product)

        for ca in category_attributes:
            #attribute_type = ca[0]
            relation = ca[1]
            # TODO validate type
            # validate required
            attribute_value = attributes[relation['Name']]
            product[relation['Name']] = attribute_value
            attribute_type = ca[0]
            if attribute_type['type'] == "category_relationship":
                rel_category = catalog.get_category(attribute_value)
                product.relationships.create(relation['Name'], rel_category.get_node()) 

    return product
Exemplo n.º 2
0
def childnode(parent, node_name, rel_name, **kwargs):

    n = None
    for r in parent.relationships.outgoing:
        if r.type.name() == rel_name and node_name == r.end['name']:
            n = r.end
            break

    if n is None:
        n = db.node(name=node_name, **kwargs)
        parent.relationships.create(rel_name, n)

    return n
Exemplo n.º 3
0
def subreference(subrel_name, subnode_name):

    node = None

    r = db.reference_node.relationships.outgoing
    for ri in r:
        if ri.type.name() == subrel_name and ri.end['name'] == subnode_name:
            node =  ri.end
            break

    if node is None:
        node = db.node(name=subnode_name)
        db.reference_node.relationships.create(subrel_name, node)

    return node