Minor fixes.
parent
ef7c15ec1d
commit
31c86c8f8d
11
README.rst
11
README.rst
|
@ -11,3 +11,14 @@ Setup development environment.
|
||||||
python manage.py syncdb --migrate --noinput
|
python manage.py syncdb --migrate --noinput
|
||||||
python manage.py loaddata initial_user
|
python manage.py loaddata initial_user
|
||||||
python manage.py sample_data
|
python manage.py sample_data
|
||||||
|
|
||||||
|
|
||||||
|
Auth: admin/123123
|
||||||
|
|
||||||
|
|
||||||
|
Polyfill's
|
||||||
|
----------
|
||||||
|
|
||||||
|
Django-Rest Framework by default returns 403 for not authenticated requests and permission denied
|
||||||
|
requests. On ``base.__init__`` has a monky patch for this bug. On its solved on django rest framework,
|
||||||
|
this patch must be removed.
|
||||||
|
|
|
@ -64,3 +64,9 @@ class Role(models.Model):
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return unicode(self.name)
|
return unicode(self.name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Patch api view for correctly return 401 responses on
|
||||||
|
# request is authenticated instead of 403
|
||||||
|
from .monkey import patch_api_view; patch_api_view()
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from rest_framework import views
|
||||||
|
from rest_framework import status, exceptions
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
def patch_api_view():
|
||||||
|
from django.views.generic import View
|
||||||
|
|
||||||
|
if hasattr(views, "_patched"):
|
||||||
|
return
|
||||||
|
|
||||||
|
views._APIView = views.APIView
|
||||||
|
views._patched = True
|
||||||
|
|
||||||
|
class APIView(views.APIView):
|
||||||
|
def handle_exception(self, exc):
|
||||||
|
if isinstance(exc, exceptions.NotAuthenticated):
|
||||||
|
return Response({'detail': 'Not authenticated'},
|
||||||
|
status=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
exception=True)
|
||||||
|
return super(APIView, self).handle_exception(exc)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def as_view(cls, **initkwargs):
|
||||||
|
view = super(views._APIView, cls).as_view(**initkwargs)
|
||||||
|
view.cls_instance = cls(**initkwargs)
|
||||||
|
return view
|
||||||
|
|
||||||
|
print "Patching APIView"
|
||||||
|
views.APIView = APIView
|
|
@ -3,6 +3,7 @@ from rest_framework.urlpatterns import format_suffix_patterns
|
||||||
|
|
||||||
from greenmine.base.api import Login, Logout, ApiRoot
|
from greenmine.base.api import Login, Logout, ApiRoot
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = format_suffix_patterns(patterns('',
|
urlpatterns = format_suffix_patterns(patterns('',
|
||||||
url(r'^auth/login/$', Login.as_view(), name='login'),
|
url(r'^auth/login/$', Login.as_view(), name='login'),
|
||||||
url(r'^auth/logout/$', Logout.as_view(), name='logout'),
|
url(r'^auth/logout/$', Logout.as_view(), name='logout'),
|
||||||
|
|
|
@ -174,6 +174,7 @@ class IssueDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
|
||||||
def post_save(self, obj, created=False):
|
def post_save(self, obj, created=False):
|
||||||
with reversion.create_revision():
|
with reversion.create_revision():
|
||||||
|
if "comment" in self.request.DATA:
|
||||||
# Update the comment in the last version
|
# Update the comment in the last version
|
||||||
reversion.set_comment(self.request.DATA['comment'])
|
reversion.set_comment(self.request.DATA['comment'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue