예제 #1
0
def save_category(data, parent, nsmap, status):
    collection_id = get_identifier(data, nsmap)
    if not collection_id:
        return
    category = get_category(data, parent, nsmap)
    if not category:
        category = Category()
        category.uid = collection_id
        category.parent = parent

    category.status = status
    collection_title = data.xpath('./ns:did/ns:unittitle', namespaces=nsmap)
    collection_descr = data.xpath('./ns:scopecontent/ns:p', namespaces=nsmap)
    collection_order_id = data.xpath('./ns:did/ns:unitid', namespaces=nsmap)

    if len(collection_title) and collection_title[0].text:
        category.title = collection_title[0].text
    if len(collection_order_id) and collection_order_id[0].text:
        category.order_id = collection_order_id[0].text
    if len(collection_descr) and collection_descr[0].text:
        category.description = collection_descr[0].text.replace('<lb/>',
                                                                ' ').strip()

    category.save()
    logger.info('dataimport.eadddb.category',
                'category %s saved' % category.id)
    return category
def save_category(parent, title):
    category = get_category(parent, title)
    if not category:
        category = Category()
        category.uid = title
        category.parent = parent
    category.title = title
    category.save()
    logger.info('dataimport.eadddb.category',
                'category %s saved' % category.id)
    return category