Permalink
Browse files

First stab at porting to rf2.

Ported PageList and PageDetail.
  • Loading branch information...
1 parent e323894 commit ff15a406bf3a413d547031fe95cc96dbad3c6b45 @markotibold markotibold committed Nov 10, 2012
Showing with 33 additions and 22 deletions.
  1. +10 −0 fiber/rest_api/serializers.py
  2. +6 −21 fiber/rest_api/urls.py
  3. +16 −0 fiber/rest_api/views.py
  4. +1 −1 setup.py
@@ -0,0 +1,10 @@
+from rest_framework import serializers
+
+from fiber.models import Page
+
+
+class PageSerializer(serializers.HyperlinkedModelSerializer):
+ move_url = serializers.HyperlinkedIdentityField(view_name='page-resource-instance-move')
+ page_url = serializers.Field(source='get_absolute_url')
+ class Meta:
+ model = Page
View
@@ -10,7 +10,7 @@
from djangorestframework.resources import ModelResource
-from fiber.models import Page, PageContentItem, ContentItem, Image, File
+from fiber.models import PageContentItem, ContentItem, Image, File
from fiber.utils.date import friendly_datetime
from fiber.app_settings import PERMISSION_CLASS
from fiber.utils import class_loader
@@ -20,23 +20,7 @@
PERMISSIONS = class_loader.load_class(PERMISSION_CLASS)
-
-class PageResource(ModelResource):
- model = Page
- depth = 1
-
- def move_url(self, instance):
- """
- Provide a url on this resource that points to the
- `move_page` method on the Page model.
- """
- return reverse('page-resource-instance-move',
- kwargs={'pk': instance.id})
-
- def page_url(self, instance):
- return instance.get_absolute_url()
-
- include = ('move_url', 'url', 'page_url')
+from .views import PageList, PageDetail
class PageContentItemResource(ModelResource):
@@ -97,15 +81,16 @@ def can_edit(self, instance):
urlpatterns = patterns('',
(r'^$', ApiRoot.as_view()),
- url(r'^pages/$', ListView.as_view(resource=PageResource), name='page-resource-root'),
- url(r'^pages/(?P<pk>[^/]+)/$', InstanceView.as_view(resource=PageResource), name='page-resource-instance'),
+ url(r'^pages/$', PageList.as_view(), name='page-list'),
+ url(r'^pages/(?P<pk>[^/]+)/$', PageDetail.as_view(), name='page-detail'),
+# url(r'^pages/(?P<pk>[^/]+)/$', InstanceView.as_view(resource=PageResource), name='page-resource-instance'),
url(r'^pages/(?P<pk>[^/]+)/move_page/$', MovePageView.as_view(), name='page-resource-instance-move'),
url(r'^pagetree/$', TreeListView.as_view(), name='pagetree-resource'),
url(r'^page_content_items/$', ListView.as_view(resource=PageContentItemResource), name='page-content-item-resource-root'),
url(r'^page_content_items/(?P<pk>[^/]+)/$', InstanceView.as_view(resource=PageContentItemResource), name='page-content-item-resource-instance'),
url(r'^page_content_items/(?P<pk>[^/]+)/move/$', MovePageContentItemView.as_view(), name='page-content-item-resource-instance-move'),
url(r'^content_items/$', ListView.as_view(resource=ContentItemResource), name='content-item-resource-root'),
- url(r'^content_items/(?P<pk>[^/]+)/$', InstanceView.as_view(resource=ContentItemResource), name='content-item-resource-instance'),
+ url(r'^content_items/(?P<pk>[^/]+)/$', InstanceView.as_view(resource=ContentItemResource), name='contentitem-detail'),
url(r'^images/$', ImageListView.as_view(resource=ImageResource), name='image-resource-root'),
url(r'^images/(?P<pk>[^/]+)/$', InstanceView.as_view(resource=ImageResource), name='image-resource-instance'),
url(r'^files/$', FileListView.as_view(resource=FileResource), name='file-resource-root'),
View
@@ -26,6 +26,22 @@
'You may need to login or otherwise authenticate the request.'})
+from rest_framework import generics, renderers
+from .serializers import PageSerializer
+
+
+class PageList(generics.ListCreateAPIView):
+ model = Page
+ serializer_class = PageSerializer
+ renderer_classes = (renderers.JSONRenderer, )
+
+
+class PageDetail(generics.RetrieveUpdateDestroyAPIView):
+ model = Page
+ serializer_class = PageSerializer
+ renderer_classes = (renderers.JSONRenderer, )
+
+
class ApiRoot(View):
"""
The root view for the rest api.
View
@@ -20,7 +20,7 @@
'Pillow==1.7.7',
'django-mptt==0.5.1',
'django-compressor>=0.7.1',
- 'djangorestframework==0.3.3'
+ 'djangorestframework==2.1.2'
],
description='Django Fiber - a simple, user-friendly CMS for all your Django projects',

0 comments on commit ff15a40

Please sign in to comment.