Beispiel #1
0
from tastypie.resources import ModelResource, ALL

from django.contrib.auth.models import User
from sapling.api import api


class UserResource(ModelResource):
    class Meta:
        queryset = User.objects.all()
        fields = ['username', 'first_name', 'last_name', 'date_joined']
        filtering = {
            'username': ALL,
            'first_name': ALL,
            'last_name': ALL,
            'date_joined': ALL,
        }
        ordering = ['username', 'first_name', 'last_name', 'date_joined']


api.register(UserResource())
Beispiel #2
0
from django.contrib.sites.models import Site
from django.conf import settings

from tastypie.resources import ModelResource

from sapling.api import api


class SiteResource(ModelResource):
    class Meta:
        # For now, let's just show the default site.
        queryset = Site.objects.filter(id=settings.SITE_ID)

    def dehydrate(self, bundle):
        bundle.data['license'] = settings.GLOBAL_LICENSE_NOTE
        bundle.data['signup_tos'] = settings.SIGNUP_TOS
        bundle.data['time_zone'] = settings.TIME_ZONE
        bundle.data['language_code'] = settings.LANGUAGE_CODE
        return bundle


api.register(SiteResource())
Beispiel #3
0
        return self.create_response(request, object_list)

    def dehydrate(self, bundle):
        if (not bundle.request.META['PATH_INFO'].startswith('/api/page') and
            not bundle.request.GET.get('full')):
            bundle = bundle.data['resource_uri']
        return bundle


# We don't use the PageURLMixin approach here because it becomes
# too complicated to generate pretty URLs with the historical version
# identifiers. TODO: Fix this. Maybe easier now with
# `detail_uri_name`
class PageHistoryResource(ModelHistoryResource):
    class Meta:
        resource_name = 'page_version'
        queryset = Page.versions.all()
        filtering = {
            'name': ALL,
            'slug': ALL,
            'history_date': ALL,
            'history_type': ALL,
        }
        ordering = ['history_date']


api.register(PageResource())
api.register(PageHistoryResource())
api.register(FileResource())
api.register(FileHistoryResource())
Beispiel #4
0
    class Meta:
        queryset = Redirect.objects.all()
        detail_uri_name = 'source'
        filtering = {
            'destination': ALL_WITH_RELATIONS,
            'source': ALL,
        }
        authentication = ApiKeyWriteAuthentication()
        authorization = DjangoAuthorization()


# We don't use the SlugifyMixin approach here because it becomes
# too complicated to generate pretty URLs with the historical version
# identifiers.
class RedirectHistoryResource(ModelHistoryResource):
    destination = fields.ForeignKey(PageHistoryResource, 'destination')

    class Meta:
        resource_name = 'redirect_version'
        queryset = Redirect.versions.all()
        filtering = {
            'destination': ALL,
            'source': ALL,
            'history_date': ALL,
            'history_type': ALL,
        }
        ordering = ['history_date']

api.register(RedirectResource())
api.register(RedirectHistoryResource())
Beispiel #5
0
class TagResource(ModelResource):
    class Meta:
        resource_name = 'tag'
        queryset = Tag.objects.all()
        detail_uri_name = 'slug'
        filtering = {
            'name': ALL,
            'slug': ALL,
        }
        list_allowed_methods = ['get', 'post']
        authentication = ApiKeyWriteAuthentication()
        authorization = ChangePageAuthorization()


api.register(TagResource())


class PageTagSetResource(PageURLMixin, ModelResource):
    page = fields.ToOneField('pages.api.PageResource', 'page')
    tags = fields.ToManyField(TagResource, 'tags')

    class Meta:
        resource_name = 'page_tags'
        queryset = PageTagSet.objects.all()
        detail_uri_name = 'page__name'
        filtering = {
            'page': ALL_WITH_RELATIONS,
            'tags': ALL_WITH_RELATIONS,
        }
        list_allowed_methods = ['get', 'post']
Beispiel #6
0

class TagResource(ModelResource):
    class Meta:
        resource_name = 'tag'
        queryset = Tag.objects.all()
        detail_uri_name = 'slug'
        filtering = {
            'name': ALL,
            'slug': ALL,
        }
        list_allowed_methods = ['get', 'post']
        authentication = ApiKeyWriteAuthentication()
        authorization = ChangePageAuthorization()

api.register(TagResource())


class PageTagSetResource(PageURLMixin, ModelResource):
    page = fields.ToOneField('pages.api.PageResource', 'page')
    tags = fields.ToManyField(TagResource, 'tags')

    class Meta:
        resource_name = 'page_tags'
        queryset = PageTagSet.objects.all()
        detail_uri_name = 'page__name'
        filtering = {
            'page': ALL_WITH_RELATIONS,
            'tags': ALL_WITH_RELATIONS,
        }
        list_allowed_methods = ['get', 'post']
Beispiel #7
0
        queryset = Redirect.objects.all()
        detail_uri_name = 'source'
        filtering = {
            'destination': ALL_WITH_RELATIONS,
            'source': ALL,
        }
        authentication = ApiKeyWriteAuthentication()
        authorization = DjangoAuthorization()


# We don't use the SlugifyMixin approach here because it becomes
# too complicated to generate pretty URLs with the historical version
# identifiers.
class RedirectHistoryResource(ModelHistoryResource):
    destination = fields.ForeignKey(PageHistoryResource, 'destination')

    class Meta:
        resource_name = 'redirect_version'
        queryset = Redirect.versions.all()
        filtering = {
            'destination': ALL,
            'source': ALL,
            'history_date': ALL,
            'history_type': ALL,
        }
        ordering = ['history_date']


api.register(RedirectResource())
api.register(RedirectHistoryResource())
Beispiel #8
0
            bundle = self.build_bundle(obj=result.object, request=request)
            bundle = self.full_dehydrate(bundle)
            objects.append(bundle)

        object_list = {'objects': objects}

        self.log_throttled_access(request)
        return self.create_response(request, object_list)


# We don't use the PageURLMixin approach here because it becomes
# too complicated to generate pretty URLs with the historical version
# identifiers. TODO: Fix this. Maybe easier now with
# `detail_uri_name`
class PageHistoryResource(ModelHistoryResource):
    class Meta:
        resource_name = 'page_version'
        queryset = Page.versions.all()
        filtering = {
            'name': ALL,
            'slug': ALL,
            'history_date': ALL,
        }
        ordering = ['history_date']


api.register(PageResource())
api.register(PageHistoryResource())
api.register(FileResource())
api.register(FileHistoryResource())