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
class UnicodeJSONRenderer(BaseRenderer): | |
""" | |
Renderer which serializes to JSON | |
""" | |
media_type = 'application/json' | |
format = 'json' | |
def render(self, obj=None, media_type=None): | |
""" |
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
class DocumentingTemplateRenderer(BaseRenderer): | |
... | |
escape_binary = True | |
def _escape_binary(content): | |
if self.escape_binary and not all(char in string.printable for char in content): | |
return '[%d bytes of binary content]' % len(content) | |
return content | |
... |
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
class SeleniumTestCase(LiveServerTestCase): | |
_selenium_server_running = None | |
@property | |
def selenium_server_running(self): | |
""" | |
Determine if we can connect to the Selenium RC server. | |
Only evaluated once for performance reasons. | |
""" |
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
class SeleniumTestCase(LiveServerTestCase): | |
@property | |
def selenium_server_running(self): | |
""" | |
Determine if we can connect to the Selenium RC server. | |
""" | |
try: | |
conn = httplib.HTTPConnection(settings.SELENIUM_SERVER_HOST, | |
settings.SELENIUM_SERVER_PORT) |
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
# serializers.py | |
class CommentSerializer(serializers.Serializer): | |
email = serializers.EmailField() | |
content = serializers.CharField(max_length=200) | |
created = serializers.DateTimeField() | |
def restore_object(self, attrs, instance=None): | |
""" | |
Create or update a new comment instance. |
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
class GetAccessToken(APIView): | |
authentication_classes = [authentication.UserBasicAuthentication] | |
permission_classes = [permissions.UserIsAuthenticated] | |
model = djangorestframework.basictoken.models.BasicToken | |
def post(self, request, *args, **kwargs): | |
token = self.model.objects.get_or_create(user=request.user) | |
return Response({'key': token.key}) |
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
class TokenAuthentication(BaseAuthentication): | |
model = djangorestframework.tokenauth.models.Token | |
def authenticate(self, request): | |
key = request.META.get('HTTP_AUTHORIZATION', '').strip() | |
if not key: | |
return None | |
try: | |
token = self.model.objects.get(key=key) |
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
class MultipleObjectBaseView(MultipleObjectMixin, BaseView): | |
""" | |
Base class for generic views onto a queryset. | |
""" | |
pagination_serializer_class = api_settings.PAGINATION_SERIALIZER | |
paginate_by = api_settings.PAGINATE_BY | |
filter_class = None | |
filter_fields = None |
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
# Currently in initial() | |
if not self.has_permission(request): | |
self.permission_denied(request) | |
self.check_throttles(request) | |
# May be this... | |
if not self.has_permission(request): | |
if request._authenticated: | |
self.permission_denied(request) | |
else: |
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
class SnippetSerializer(serializers.Serializer): | |
title = serializers.CharField(required=False, | |
max_length=100) | |
code = serializers.CharField(widget=widgets.Textarea, | |
max_length=100000) | |
linenos = serializers.BooleanField(required=False) | |
lexer = serializers.ChoiceField(choices=models.LEXER_CHOICES, | |
default='python') | |
style = serializers.ChoiceField(choices=models.STYLE_CHOICES, | |
default='friendly') |
OlderNewer