Beispiel #1
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()
Beispiel #2
0
def create_item_resources(request):
    section_item_id = request.POST.get('id', None)
    title = request.POST.get('title', None)
    position = request.POST.get('position', None)

    try:
        section_item = SectionItem.objects.get(pk=section_item_id)
    except:
        return APIUtilities._api_not_found()

    new_section_item_resources = SectionItemResources(
        title=title, position=int(position))
    new_section_item_resources.save()

    section_item.resource_sets.add(new_section_item_resources)

    return APIUtilities.success({'id': new_section_item_resources.id})
Beispiel #3
0
def create_resource_set(request, section_item_resources_id):
    if request.user:
        if section_item_resources_id == 'null':
            section_item_id = request.POST.get('section_item_id', None)

            if section_item_id:
                section_item = SectionItem.objects.get(pk=section_item_id)

                section_item_resources = SectionItemResources(title='Resources')
                section_item_resources.save()

                section_item.resource_sets.add(section_item_resources)
            
            else:
                return None

        else:
            return None

    else:
        return None