예제 #1
0
def create_bare_contentnode(ccnode):
    logging.debug("Creating a Kolibri node for instance id {}".format(
        ccnode.node_id))

    kolibri_license = None
    if ccnode.license is not None:
        kolibri_license = create_kolibri_license_object(ccnode)[0]

    kolibrinode, is_new = kolibrimodels.ContentNode.objects.update_or_create(
        pk=ccnode.node_id,
        defaults={'kind': ccnode.kind.kind,
            'title': ccnode.title,
            'content_id': ccnode.content_id,
            'author' : ccnode.author or "",
            'description': ccnode.description,
            'sort_order': ccnode.sort_order,
            'license_owner': ccnode.copyright_holder or "",
            'license': kolibri_license,
            'available': True,  # TODO: Set this to False, once we have availability stamping implemented in Kolibri
            'stemmed_metaphone': ' '.join(fuzz(ccnode.title + ' ' + ccnode.description)),
        }
    )

    if ccnode.parent:
        logging.debug("Associating {child} with parent {parent}".format(
            child=kolibrinode.pk,
            parent=ccnode.parent.node_id
        ))
        kolibrinode.parent = kolibrimodels.ContentNode.objects.get(pk=ccnode.parent.node_id)

    kolibrinode.save()
    logging.debug("Created Kolibri ContentNode with node id {}".format(ccnode.node_id))
    logging.debug("Kolibri node count: {}".format(kolibrimodels.ContentNode.objects.all().count()))

    return kolibrinode
예제 #2
0
def create_bare_contentnode(ccnode, default_language):
    logging.debug("Creating a Kolibri node for instance id {}".format(
        ccnode.node_id))

    kolibri_license = None
    if ccnode.license is not None:
        kolibri_license = create_kolibri_license_object(ccnode)[0]

    language = None
    if ccnode.language or default_language:
        language, _new = get_or_create_language(ccnode.language
                                                or default_language)

    kolibrinode, is_new = kolibrimodels.ContentNode.objects.update_or_create(
        pk=ccnode.node_id,
        defaults={
            'kind':
            ccnode.kind.kind,
            'title':
            ccnode.title,
            'content_id':
            ccnode.content_id,
            'author':
            ccnode.author or "",
            'description':
            ccnode.description,
            'sort_order':
            ccnode.sort_order,
            'license_owner':
            ccnode.copyright_holder or "",
            'license':
            kolibri_license,
            'available':
            ccnode.get_descendants(include_self=True).exclude(
                kind_id=content_kinds.TOPIC).exists(),  # Hide empty topics
            'stemmed_metaphone':
            ' '.join(fuzz(ccnode.title + ' ' + ccnode.description)),
            'lang':
            language
        })

    if ccnode.parent:
        logging.debug("Associating {child} with parent {parent}".format(
            child=kolibrinode.pk, parent=ccnode.parent.node_id))
        kolibrinode.parent = kolibrimodels.ContentNode.objects.get(
            pk=ccnode.parent.node_id)

    kolibrinode.save()
    logging.debug("Created Kolibri ContentNode with node id {}".format(
        ccnode.node_id))
    logging.debug("Kolibri node count: {}".format(
        kolibrimodels.ContentNode.objects.all().count()))

    return kolibrinode
def create_bare_contentnode(ccnode, default_language, channel_id, channel_name):
    logging.debug("Creating a Kolibri contentnode for instance id {}".format(
        ccnode.node_id))

    kolibri_license = None
    if ccnode.license is not None:
        kolibri_license = create_kolibri_license_object(ccnode)[0]

    language = None
    if ccnode.language or default_language:
        language, _new = get_or_create_language(ccnode.language or default_language)

    kolibrinode, is_new = kolibrimodels.ContentNode.objects.update_or_create(
        pk=ccnode.node_id,
        defaults={
            'kind': ccnode.kind.kind,
            'title': ccnode.title if ccnode.parent else channel_name,
            'content_id': ccnode.content_id,
            'channel_id': channel_id,
            'author': ccnode.author or "",
            'description': ccnode.description,
            'sort_order': ccnode.sort_order,
            'license_owner': ccnode.copyright_holder or "",
            'license': kolibri_license,
            'available': ccnode.get_descendants(include_self=True).exclude(kind_id=content_kinds.TOPIC).exists(),  # Hide empty topics
            'stemmed_metaphone': ' '.join(fuzz(ccnode.title + ' ' + ccnode.description)),
            'lang': language,
            'license_name': kolibri_license.license_name if kolibri_license is not None else None,
            'license_description': kolibri_license.license_description if kolibri_license is not None else None,
            'coach_content': ccnode.role_visibility == roles.COACH,
        }
    )

    if ccnode.parent:
        logging.debug("Associating {child} with parent {parent}".format(
            child=kolibrinode.pk,
            parent=ccnode.parent.node_id
        ))
        kolibrinode.parent = kolibrimodels.ContentNode.objects.get(pk=ccnode.parent.node_id)

    kolibrinode.save()
    logging.debug("Created Kolibri ContentNode with node id {}".format(ccnode.node_id))
    logging.debug("Kolibri node count: {}".format(kolibrimodels.ContentNode.objects.all().count()))

    return kolibrinode