Skip to content

Commit

Permalink
merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Bredehöft committed May 24, 2016
2 parents b13d18d + ab20009 commit f36e4c2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
4 changes: 3 additions & 1 deletion drf_tools/auth/authentications.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.db.models import Q
from rest_framework.authentication import BasicAuthentication

User = get_user_model()


class QuietBasicAuthentication(BasicAuthentication):
"""
Expand Down
6 changes: 3 additions & 3 deletions drf_tools/auth/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def has_permission(self, request, view):

if request.method == 'POST':
permission_model_ids = permission_service.get_permission_model_ids_from_request(request, view)
if not self.__check_links(request):
if not self._check_links(request):
return False
for permission_model_id in permission_model_ids:
if permission_service.has_permission(user, permission_model_id, view.queryset.model, Operation.CREATE):
Expand All @@ -64,12 +64,12 @@ def has_object_permission(self, request, view, obj):
if permission_service.is_super_user(user) or (
permission_service.is_super_reader(user) and request.method in SAFE_METHODS):
return True
if request.method in ('PUT', 'PATCH') and not self.__check_links(request):
if request.method in ('PUT', 'PATCH') and not self._check_links(request):
return False
operation = self.__get_operation(request.method)
return permission_service.has_object_permission(user, obj, operation)

def __check_links(self, request):
def _check_links(self, request):
if LINKS_FIELD_NAME in request.data:
urlconf = settings.ROOT_URLCONF
urlresolvers.set_urlconf(urlconf)
Expand Down
4 changes: 2 additions & 2 deletions drf_tools/auth/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from rest_framework.fields import EmailField
from rest_framework.fields import BooleanField

Expand All @@ -11,7 +11,7 @@ class UserSerializer(HalNestedFieldsModelSerializer):
email = EmailField(required=True)

class Meta:
model = User
model = get_user_model()
fields = ('id', 'email', 'password', 'first_name', 'last_name', 'isSuperAdmin', 'isSuperReader')
extra_kwargs = {'password': {'write_only': True}}
read_only_fields = ('id',)
5 changes: 4 additions & 1 deletion drf_tools/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def create_error_response_by_exception(exc):
messages = exc.messages
else:
messages = [str(exc)]
return create_error_response(exc.__class__.__name__, messages)
code = 0
if hasattr(exc, 'code'):
code = exc.code
return create_error_response(exc.__class__.__name__, messages, code)


def create_error_response(error_type, messages, code=0):
Expand Down
8 changes: 5 additions & 3 deletions drf_tools/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ class AnyFileFromSystemRenderer(BaseFileRenderer):
render_style = 'binary'

def render(self, data, accepted_media_type=None, renderer_context=None):
if not isinstance(data, str) or renderer_context['response'].status_code != 200:
if renderer_context['response'].status_code != 200:
return data
self._add_filename_to_response(renderer_context)
with open(data, "rb") as file:
return file.read()
if isinstance(data, str):
with open(data, "rb") as file:
return file.read()
return data
2 changes: 1 addition & 1 deletion setup.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='drf-tools',
version="0.9.19",
version="0.9.24",
url='https://github.com/seebass/drf-tools',
license='MIT',
description='Multiple extensions and test utilities for Django REST Framework 3',
Expand Down

0 comments on commit f36e4c2

Please sign in to comment.