Merge branch 'master' into production

pull/91/head
eric 2017-06-29 13:56:32 -04:00
commit 350a2a0ba2
2 changed files with 18 additions and 0 deletions

View File

@ -21,6 +21,7 @@ logger = logging.getLogger(__name__)
class EditionResource(ModelResource):
work = fields.ForeignKey('regluit.api.resources.WorkResource', 'work')
identifiers = fields.ToManyField('regluit.api.resources.IdentifierResource', 'identifiers')
ebooks = fields.ToManyField('regluit.api.resources.EbookResource', 'ebooks')
class Meta:
authentication = ApiKeyAuthentication()
queryset = models.Edition.objects.all()
@ -123,6 +124,21 @@ class SubjectResource(ModelResource):
queryset = models.Subject.objects.all()
resource_name = 'subject'
class EbookResource(ModelResource):
edition = fields.ToOneField(EditionResource, 'edition')
class Meta:
authentication = ApiKeyAuthentication()
queryset = models.Ebook.objects.all()
resource_name = 'ebook'
excludes = ['url']
class PublisherResource(ModelResource):
ebooks = fields.ToManyField(EbookResource, attribute=lambda bundle: models.Ebook.objects.filter(edition__publisher_name=bundle.obj.name))
class Meta:
authentication = ApiKeyAuthentication()
queryset = models.Publisher.objects.all()
resource_name = 'publisher'
class FreeResource(ModelResource):
def alter_list_data_to_serialize(self, request, data):
del data["meta"]["limit"]

View File

@ -25,6 +25,8 @@ v1_api.register(resources.CampaignResource())
v1_api.register(resources.AuthorResource())
v1_api.register(resources.SubjectResource())
v1_api.register(resources.FreeResource())
v1_api.register(resources.PublisherResource())
v1_api.register(resources.EbookResource())
urlpatterns = [
url(r'^help$', ApiHelpView.as_view(), name="api_help"),