# Path: indicomobile/db/schema.py
# class Presenter(Document):
# class Resource(Document):
# class Material(Document):
# class Chair(Document):
# class Event(Document):
# class Contribution(Document):
# class SessionSlot(Document):
# class Contribution(Document):
# class Day(Document):
# class FavoritesContribution(Document):
# class FavoritesSessionSlot(Document):
# class FavoritesEvent(Document):
# class HistoryEvent(Document):
# class CachedLatestEvent(Document):
#     def cleanup(self, event_id):
#     def cleanup(self, user_id, event_id):


from indicomobile.db.schema import db

def store_material(block):
    materials = []
    for material_dict in block.get('material', []):
        resources = []

        for resource_dict in material_dict.get('resources', []):
            resource_dict.pop('_type')
            resource_dict['conferenceId'] = block.get('conferenceId')
            resource = db.Resource()
            resource.update(resource_dict)
            resources.append(resource)
            resource.save()

        material_dict['resources'] = resources
        material_dict.pop('_type')
        material_dict['conferenceId'] = block.get('conferenceId')

# Path: indicomobile/db/schema.py
# class Presenter(Document):
# class Resource(Document):
# class Material(Document):
# class Chair(Document):
# class Event(Document):
# class Contribution(Document):
# class SessionSlot(Document):
# class Contribution(Document):
# class Day(Document):
# class FavoritesContribution(Document):
# class FavoritesSessionSlot(Document):
# class FavoritesEvent(Document):
# class HistoryEvent(Document):
# class CachedLatestEvent(Document):
#     def cleanup(self, event_id):
#     def cleanup(self, user_id, event_id):


# Path: indicomobile/db/common.py
from indicomobile.db.schema import db


def store_material(block):
    materials = []
    for material_dict in block.get('material', []):
        resources = []

        for resource_dict in material_dict.get('resources', []):
            resource_dict.pop('_type')
            resource_dict['conferenceId'] = block.get('conferenceId')
            resource = db.Resource()
            resource.update(resource_dict)
            resources.append(resource)
            resource.save()

        material_dict['resources'] = resources
        material_dict.pop('_type')
        material_dict['conferenceId'] = block.get('conferenceId')

        material = db.Material()