This repository has been archived by the owner. It is now read-only.
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (45 sloc) 2.08 KB
from __future__ import absolute_import
from . import base
from .content import (ContentResource, ContentManager, Audio, Data, Photo,
Text, Video)
class Package(ContentResource):
_related_keys = ContentResource._related_keys + ['audio_items',
def audio_items(self):
return [Audio(, audio)
for audio in self._audio_items]
def data_items(self):
return [Data(, data)
for data in self._data_items]
def photo_items(self):
return [Photo(, photo)
for photo in self._photo_items]
def text_items(self):
return [Text(self.manager.api.text, text)
for text in self._text_items]
def video_items(self):
return [Video(, video)
for video in self._video_items]
class PackageManager(ContentManager):
resource_class = Package
urlbit = 'package'
def _flatten(self, resource):
# Extend flattening to handle all the *_items fields.
flattened = super(PackageManager, self)._flatten(resource)
for related_type in ['audio', 'data', 'photo', 'text', 'video']:
key = '%s_items' % related_type
flattened_related = []
for related in flattened.get(key, []):
if not isinstance(related, basestring):
related = '/content/%s/%s/' % (related_type, base.getid(related))
flattened[key] = flattened_related
return flattened