from contentrelations import BaseResource, resource_list from downloads.models import DownloadableFile class DownloadableFileResource(BaseResource): def get_title(self): return self.instance.file_name def get_description(self): return self.instance.notes def get_key_image(self): return self.instance.preview_image def get_url(self): return self.instance.downloadablefile.url resource_list.register(DownloadableFile, DownloadableFileResource)
from contentrelations import BaseResource, resource_list from articleapp.models import Article class ArticleResource(BaseResource): def get_title(self): return self.instance.headline def get_description(self): return self.instance.summary def get_key_image(self): return self.instance.primary_image def get_resource_name(self): return u'%s Article' % self.instance.primary_category resource_list.register(Article, ArticleResource)
import json from contentrelations import BaseResource, resource_list from contentrelations.serializer import Serializer from .models import Food, Beverage, Person class ExampleResource(BaseResource): def get_title(self): return self.instance.name def get_short_desc(self): return self.instance.description[:10] resource_list.register((Food, Beverage, Person), ExampleResource) class SimpleJSONSerializer(Serializer): """ This will serialize resources with name and description attributes """ def start_serialization(self): self.stream.write("[") def end_serialization(self): self.stream.write("]") def serialize_object(self, obj): out = {'name': obj.name, 'description': obj.description}
from contentrelations import BaseResource, resource_list from imageapp.models import Image class ImageResource(BaseResource): def get_title(self): return self.instance.name def get_description(self): return self.instance.caption def get_key_image(self): return self.instance.image resource_list.register(Image, ImageResource)
from contentrelations import BaseResource, resource_list from contentrelations.serializer import Serializer from .models import Food, Beverage, Person class ExampleResource(BaseResource): def get_title(self): return self.instance.name def get_short_desc(self): return self.instance.description[:10] resource_list.register((Food, Beverage, Person), ExampleResource) class SimpleJSONSerializer(Serializer): """ This will serialize resources with name and description attributes """ def start_serialization(self): self.stream.write("[") def end_serialization(self): self.stream.write("]") def serialize_object(self, obj): out = {'name': obj.name, 'description': obj.description} if not self.first:
from contentrelations import resource_list from curricula.models import Activity resource_list.register(Activity)