Skip to content
Browse files

Added resources for REST-ful API

  • Loading branch information...
1 parent d752153 commit de4e0d66f176f3c8f98b04d94999af975441500b Esten Hurtle committed
Showing with 160 additions and 0 deletions.
  1. +20 −0 api_urls.py
  2. +19 −0 articles/api.py
  3. +24 −0 blogs/api.py
  4. +12 −0 design/api.py
  5. +9 −0 events/api.py
  6. +23 −0 multimedia/api.py
  7. +13 −0 photography/api.py
  8. +18 −0 podcasts/api.py
  9. +14 −0 publishing/api.py
  10. +8 −0 tagging/api.py
View
20 api_urls.py
@@ -0,0 +1,20 @@
+from tastypie.api import Api
+from brubeck.articles.api import ArticleResource
+from brubeck.blogs.api import EntryResource
+from brubeck.events.api import EventResource
+from brubeck.podcasts.api import PodcastResource
+from brubeck.multimedia.api import AudioResource,VideoResource,SlideshowResource
+
+v1_api = Api(api_name='v1')
+v1_api.register(ArticleResource())
+v1_api.register(EntryResource())
+v1_api.register(EventResource())
+v1_api.register(PodcastResource())
+v1_api.register(AudioResource())
+v1_api.register(VideoResource())
+v1_api.register(SlideshowResource())
+
+
+urlpatterns = patterns('',
+ (r'^api/', include(v1_api.urls)),
+)
View
19 articles/api.py
@@ -0,0 +1,19 @@
+from tastypie.resources import ModelResource
+from tastypie import fields
+from brubeck.articles.models import Article
+from brubeck.publishing.api import SectionResource,IssueResource
+
+class ArticleResource(ModelResource):
+ issue = fields.ForeignKey(IssueResource, 'issue')
+ section = fields.ForeignKey(SectionResource, 'section')
+ tag = fields.ToManyField('brubeck.tagging.api.TagResource', 'tag')
+ photos = fields.ToManyField('brubeck.photography.api.PhotoResource', 'photos')
+ videos = fields.ToManyField('brubeck.multimedia.api.VideoResource', 'videos')
+ audio_clips = fields.ToManyField('brubeck.multimedia.api.AudioResource', 'audio_clips')
+ slideshows = fields.ToManyField('brubeck.multimedia.api.SlideshowResource', 'slideshows')
+ podcast_episodes = fields.ToManyField('brubeck.podcasts.api.PodcastResource', 'podcast_episodes')
+ photos = fields.ToManyField('brubeck.design.api.GraphicResource', 'graphics')
+ class Meta:
+ queryset = Article.objects.all()
+ resource_name = 'article'
+ allowed_methods = ['get']
View
24 blogs/api.py
@@ -0,0 +1,24 @@
+from tastypie.resources import ModelResource
+from brubeck.blogs.models import Entry
+from tastypie import fields
+from brubeck.publishing.api import SectionResource
+
+class BlogResource(ModelResource):
+ section = fields.ForeignKey(SectionResource, 'blog')
+ class Meta:
+ queryset = Blog.objects.all()
+ resource_name = 'blog'
+ allowed_methods = ['get']
+
+class EntryResource(ModelResource):
+ blog = fields.ForeignKey(BlogResource, 'blog')
+ tag = fields.ToManyField('brubeck.tagging.api.TagResource', 'tag')
+ photos = fields.ToManyField('brubeck.photography.api.PhotoResource', 'photos')
+ videos = fields.ToManyField('brubeck.multimedia.api.VideoResource', 'videos')
+ audio_clips = fields.ToManyField('brubeck.multimedia.api.AudioResource', 'audio_clips')
+ slideshows = fields.ToManyField('brubeck.multimedia.api.SlideshowResource', 'slideshows')
+ podcast_episodes = fields.ToManyField('brubeck.podcasts.api.PodcastResource', 'podcast_episodes')
+ class Meta:
+ queryset = Entry.objects.all()
+ resource_name = 'entry'
+ allowed_methods = ['get']
View
12 design/api.py
@@ -0,0 +1,12 @@
+from tastypie.resources import ModelResource
+from brubeck.design.models import Graphic
+from brubeck.publishing.api import IssueResource,SectionResource
+
+class GraphicResource(ModelResource):
+ issue = fields.ForeignKey(IssueResource, 'issue')
+ section = fields.ForeignKey(SectionResource, 'section')
+ class Meta:
+ queryset = Graphic.objects.all()
+ resource_name = 'graphic'
+ allowed_methods = ['get']
+
View
9 events/api.py
@@ -0,0 +1,9 @@
+from tastypie.resources import ModelResource
+from brubeck.events.models import Event
+
+class EventResource(ModelResource):
+ class Meta:
+ queryset = Event.objects.all()
+ resource_name = 'event'
+ allowed_methods = ['get']
+
View
23 multimedia/api.py
@@ -0,0 +1,23 @@
+from tastypie.resources import ModelResource
+from brubeck.multimedia.models import AudioClip,Slideshow,Video
+
+class AudioResource(ModelResource):
+ tag = fields.ToManyField('brubeck.tagging.api.TagResource', 'tag')
+ class Meta:
+ queryset = AudioClip.objects.all()
+ resource_name = 'audioclip'
+ allowed_methods = ['get']
+
+class SlideshowResource(ModelResource):
+ tag = fields.ToManyField('brubeck.tagging.api.TagResource', 'tag')
+ class Meta:
+ queryset = Slideshow.objects.all()
+ resource_name = 'slideshow'
+ allowed_methods = ['get']
+
+class VideoResource(ModelResource):
+ tag = fields.ToManyField('brubeck.tagging.api.TagResource', 'tag')
+ class Meta:
+ queryset = Video.objects.all()
+ resource_name = 'video'
+ allowed_methods = ['get']
View
13 photography/api.py
@@ -0,0 +1,13 @@
+from tastypie.resources import ModelResource
+from brubeck.photography.models import Photo
+from brubeck.publishing.api import IssueResource,SectionResource
+
+class PhotoResource(ModelResource):
+ issue = fields.ForeignKey(IssueResource, 'issue')
+ section = fields.ForeignKey(SectionResource, 'section')
+ tag = fields.ToManyField('brubeck.tagging.api.TagResource', 'tag')
+ class Meta:
+ queryset = Photo.objects.all()
+ resource_name = 'photo'
+ allowed_methods = ['get']
+
View
18 podcasts/api.py
@@ -0,0 +1,18 @@
+from tastypie.resources import ModelResource
+from brubeck.podcasts.models import Episode,Channel
+
+class ChannelResource(ModelResource):
+ class Meta:
+ queryset = Channel.objects.all()
+ resource_name = 'channel'
+ allowed_methods = ['get']
+
+
+
+class PodcastResource(ModelResource):
+ channel = fields.ForeignKey(ChannelResource, 'channel')
+ class Meta:
+ queryset = Episode.objects.all()
+ resource_name = 'podcast'
+ allowed_methods = ['get']
+
View
14 publishing/api.py
@@ -0,0 +1,14 @@
+from tastypie.resources import ModelResource
+from brubeck.publishing.models import Section,Issue
+
+class SectionResource(ModelResource):
+ class Meta:
+ queryset = Section.objects.all()
+ resource_name = 'section'
+ allowed_methods = ['get']
+
+class IssueResource(ModelResource):
+ class Meta:
+ queryset = Issue.objects.all()
+ resource_name = 'issue'
+ allowed_methods = ['get']
View
8 tagging/api.py
@@ -0,0 +1,8 @@
+from brubeck.tagging.models import Tag
+from tastypie.resources import ModelResource
+
+class TagResource(ModelResource):
+ class Meta:
+ queryset = Tag.objects.all()
+ resource_name = 'tag'
+ allowed_methods = ['get']

0 comments on commit de4e0d6

Please sign in to comment.
Something went wrong with that request. Please try again.