예제 #1
0
파일: api.py 프로젝트: martindale/localwiki
class TagResource(ModelResource):
    class Meta:
        resource_name = 'tag'
        queryset = Tag.objects.all()
        detail_uri_name = 'slug'
        filtering = {
            'name': ALL,
            'slug': ALL,
        }
        ordering = ['name', 'slug']
        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,
        }
        ordering = ['page', 'tags']
예제 #2
0
파일: api.py 프로젝트: schlos/localwiki
        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())
예제 #3
0
파일: api.py 프로젝트: Web5design/localwiki
from tastypie.resources import ModelResource, ALL

from django.contrib.auth.models import User
from main.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())
예제 #4
0
        in_page_api = False
        for pattern in self.urls:
            if pattern.resolve(bundle.request.path.replace('/api/', '')):
                in_page_api = True
        if (not in_page_api 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())
예제 #5
0
파일: api.py 프로젝트: pvl/localwiki
        self.log_throttled_access(request)
        return self.create_response(request, object_list)

    def dehydrate(self, bundle):
        in_page_api = False
        for pattern in self.urls:
            if pattern.resolve(bundle.request.path.replace("/api/", "")):
                in_page_api = True
        if not in_page_api 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())
예제 #6
0
파일: api.py 프로젝트: Web5design/localwiki
    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())
예제 #7
0
파일: site.py 프로젝트: schlos/localwiki
from django.contrib.sites.models import Site
from django.conf import settings

from tastypie.resources import ModelResource

from main.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())