Ejemplo n.º 1
0
def create_section(request):
    parent_id = request.POST.get('parent_id', None)
    is_unit = request.POST.get('is_unit', None)
    title = request.POST.get('title', None)
    section_type = request.POST.get('section_type', None)
    position = request.POST.get('position', None)

    settings = {
        'type': section_type
    }

    try:
        if is_unit:
            parent = Unit.objects.get(pk=parent_id)
        else:
            parent = StandardCategory.objects.get(pk=parent_id)
    except:
        return APIUtilities._api_not_found()

    new_section = Section(position=position, title=title, settings=settings)
    new_section.save()

    parent.sections.add(new_section)

    context = {
        'id': new_section.id
    }
    
    return APIUtilities.success(context)
Ejemplo n.º 2
0
    def add_sections_to(parent, sections):
        for section in sections:
            new_section = Section(
                position=section.position,
                title=section.title,
                settings=section.settings
            )
            new_section.save()
            parent.sections.add(new_section)

            # IF SYNC IS TURNED ON.
            CurriculumSyncLink(
                link_type=section_content_type, from_curriculum=curriculum, to_curriculum=new_curriculum,
                source_id=section.id, target_id=new_section.id
            ).save()

            for item in section.items.all():
                new_item = SectionItem(
                    content_type=item.content_type,
                    content_id=item.content_id,
                    description=item.description,
                    meta=item.meta,
                    position=item.position
                )
                new_item.save()
                new_section.items.add(new_item)

                # IF SYNC IS TURNED ON.
                CurriculumSyncLink(
                    link_type=sectionitem_content_type, from_curriculum=curriculum, to_curriculum=new_curriculum,
                    source_id=item.id, target_id=new_item.id
                ).save()

                for resource_set in item.resource_sets.all():
                    new_item_resources = SectionItemResources(
                        title=resource_set.title,
                        position=resource_set.position
                    )
                    new_item_resources.save()
                    new_item.resource_sets.add(new_item_resources)

                    # IF SYNC IS TURNED ON.
                    CurriculumSyncLink(
                        link_type=sectionitemresources_content_type, from_curriculum=curriculum, to_curriculum=new_curriculum,
                        source_id=resource_set.id, target_id=new_item_resources.id
                    ).save()

                    for resource in resource_set.resources.all():
                        new_curriculum_resource = Resource(
                            resource=resource.resource,
                            notes=resource.notes
                        )
                        new_curriculum_resource.save()
                        new_item_resources.resources.add(new_curriculum_resource)

                        # IF SYNC IS TURNED ON.
                        CurriculumSyncLink(
                            link_type=resource_content_type, from_curriculum=curriculum, to_curriculum=new_curriculum,
                            source_id=resource.id, target_id=new_curriculum_resource.id
                        ).save()