This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v1_api = Api(api_name='v1') | |
v1_api.register(BookResource()) | |
# Intentionally left out PageResource |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.handlers.base import BaseHandler | |
from django.test.client import RequestFactory | |
class RequestMock(RequestFactory): | |
def request(self, **request): | |
"Construct a generic request object." | |
request = RequestFactory.request(self, **request) | |
handler = BaseHandler() | |
handler.load_middleware() | |
for middleware_method in handler._request_middleware: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# This field is used on the user model to transparently add stuff from the | |
# user profile object into the user resource. | |
# | |
# Copyright (c) 2012 Colin Sullivan <colinsul [at] gmail.com> | |
# Licensed under the MIT License. | |
### | |
class UserProfileManyToManyField(fields.ManyToManyField): | |
### | |
# We will override the dehydrate method so when we're trying to dehydrate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from oauth2 import Error | |
from django.utils.translation import ugettext as _ | |
from tastypie.authentication import Authentication | |
from oauth_provider.utils import initialize_server_request, send_oauth_error, get_oauth_request | |
from oauth_provider.consts import OAUTH_PARAMETERS_NAMES | |
from oauth_provider.store import store, InvalidTokenError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tastypie.authentication import Authentication | |
class DjangoAuthentication(Authentication): | |
"""Authenticate based upon Django session""" | |
def is_authenticated(self, request, **kwargs): | |
return request.user.is_authenticated() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import os | |
from tastypie.fields import FileField | |
from django.core.files.uploadedfile import SimpleUploadedFile | |
class Base64FileField(FileField): | |
""" | |
A django-tastypie field for handling file-uploads through raw post data. | |
It uses base64 for en-/decoding the contents of the file. | |
Usage: |
NewerOlder