Commit 4a5ba549dcdfe2d86cfb69f82bbc41776c2cdfff

Authored by fbormann
1 parent 8d39cac8

set configuration fully working for oauth2 provider and core log methods

amadeus/settings.py
@@ -43,6 +43,7 @@ INSTALLED_APPS = [ @@ -43,6 +43,7 @@ INSTALLED_APPS = [
43 43
44 'widget_tweaks', 44 'widget_tweaks',
45 'rolepermissions', 45 'rolepermissions',
  46 + 'oauth2_provider',
46 'rest_framework', 47 'rest_framework',
47 'django_bootstrap_breadcrumbs', 48 'django_bootstrap_breadcrumbs',
48 's3direct', 49 's3direct',
@@ -208,6 +209,21 @@ EMAIL_HOST_PASSWORD = 'amadeusteste' @@ -208,6 +209,21 @@ EMAIL_HOST_PASSWORD = 'amadeusteste'
208 # SMTP CONFIG 209 # SMTP CONFIG
209 # EMAIL_BACKEND = 'core.smtp.AmadeusEmailBackend' 210 # EMAIL_BACKEND = 'core.smtp.AmadeusEmailBackend'
210 211
  212 +#API CONFIG STARTS
  213 +#TELL the rest framework to use a different backend
  214 +REST_FRAMEWORK = {
  215 + 'DEFAULT_AUTHENTICATION_CLASSES':(
  216 + 'oauth2_provider.ext.rest_framework.OAuth2Authentication',),
  217 + 'DEFAULT_PERMISSION_CLASSES':(
  218 + 'rest_framework.permissions.IsAuthenticated',)
  219 +}
  220 +
  221 +OAUTH2_PROVIDER = {
  222 + 'SCOPES':{'read':'Read scope', 'write': 'Write scope'}
  223 +}
  224 +#API CONFIG ENDS
  225 +
  226 +
211 #s3direct 227 #s3direct
212 228
213 # AWS keys 229 # AWS keys
amadeus/urls.py
@@ -25,7 +25,8 @@ urlpatterns = [ @@ -25,7 +25,8 @@ urlpatterns = [
25 url(r'^users/', include('users.urls', namespace = 'users')), 25 url(r'^users/', include('users.urls', namespace = 'users')),
26 url(r'^admin/', admin.site.urls), 26 url(r'^admin/', admin.site.urls),
27 url(r'^', include('core.urls', namespace = 'core')), 27 url(r'^', include('core.urls', namespace = 'core')),
28 - 28 + #API
  29 + url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
29 #S3Direct 30 #S3Direct
30 url(r'^s3direct/', include('s3direct.urls')), 31 url(r'^s3direct/', include('s3direct.urls')),
31 url(r'^summernote/', include('django_summernote.urls')), 32 url(r'^summernote/', include('django_summernote.urls')),
core/serializers.py
@@ -4,4 +4,5 @@ from .models import Log @@ -4,4 +4,5 @@ from .models import Log
4 class LogSerializer(serializers.ModelSerializer): 4 class LogSerializer(serializers.ModelSerializer):
5 class Meta: 5 class Meta:
6 model = Log 6 model = Log
  7 + fields = '__all__'
7 8
8 \ No newline at end of file 9 \ No newline at end of file
@@ -2,8 +2,11 @@ from django.conf.urls import url, include @@ -2,8 +2,11 @@ from django.conf.urls import url, include
2 from django.contrib.auth import views as auth_views 2 from django.contrib.auth import views as auth_views
3 from django.contrib.auth.views import password_reset, password_reset_done,password_reset_confirm, password_reset_complete 3 from django.contrib.auth.views import password_reset, password_reset_done,password_reset_confirm, password_reset_complete
4 from . import views 4 from . import views
  5 +from rest_framework import routers
5 6
6 7
  8 +router = routers.DefaultRouter()
  9 +router.register(r'logs', views.LogViewSet)
7 urlpatterns = [ 10 urlpatterns = [
8 url(r'^$', views.login, name='home'), 11 url(r'^$', views.login, name='home'),
9 url(r'^register/$', views.RegisterUser.as_view(), name='register'), 12 url(r'^register/$', views.RegisterUser.as_view(), name='register'),
@@ -14,7 +17,8 @@ urlpatterns = [ @@ -14,7 +17,8 @@ urlpatterns = [
14 url(r'^guest/$', views.GuestView.as_view(), name='guest'), 17 url(r'^guest/$', views.GuestView.as_view(), name='guest'),
15 18
16 #API REST 19 #API REST
17 - url(r'^logs/$', views.get_log), 20 + url(r'^', include(router.urls)),
  21 + #url(r'^logs/$', views.get_log),
18 22
19 #Reset Password 23 #Reset Password
20 24
@@ -30,3 +34,5 @@ urlpatterns = [ @@ -30,3 +34,5 @@ urlpatterns = [
30 url(r'^done/$', password_reset_complete,{'template_name':'registration/passwor_reset_complete.html'}), 34 url(r'^done/$', password_reset_complete,{'template_name':'registration/passwor_reset_complete.html'}),
31 35
32 ] 36 ]
  37 +
  38 +
@@ -16,8 +16,10 @@ from rolepermissions.shortcuts import assign_role @@ -16,8 +16,10 @@ from rolepermissions.shortcuts import assign_role
16 from django.contrib.auth.decorators import login_required 16 from django.contrib.auth.decorators import login_required
17 #API REST IMPORTS 17 #API REST IMPORTS
18 from .serializers import LogSerializer 18 from .serializers import LogSerializer
19 -from rest_framework.renderers import JSONRenderer  
20 -from rest_framework.parsers import JSONParser 19 +from rest_framework import status, serializers, permissions, viewsets
  20 +from rest_framework.response import Response
  21 +from rest_framework.decorators import api_view
  22 +
21 23
22 from .forms import RegisterUserForm 24 from .forms import RegisterUserForm
23 from .decorators import log_decorator, notification_decorator 25 from .decorators import log_decorator, notification_decorator
@@ -135,19 +137,19 @@ class GuestView (ListView): @@ -135,19 +137,19 @@ class GuestView (ListView):
135 context['categorys_courses'] = CourseCategory.objects.all() 137 context['categorys_courses'] = CourseCategory.objects.all()
136 return context 138 return context
137 139
138 -class JSONResponse(HttpResponse):  
139 - """  
140 - An HttpResponse that renders its content into JSON.  
141 - """  
142 - def __init__(self, data, **kwargs):  
143 - content = JSONRenderer().render(data)  
144 - kwargs['content_type'] = 'application/json'  
145 - super(JSONResponse, self).__init__(content, **kwargs) 140 +
146 141
147 #REST API VIEWS 142 #REST API VIEWS
148 @login_required 143 @login_required
  144 +@api_view(['GET'])
149 def get_log(request): 145 def get_log(request):
150 if request.method == 'GET': 146 if request.method == 'GET':
151 logs = Log.objects.all() 147 logs = Log.objects.all()
152 serializer = LogSerializer(logs, many=True) 148 serializer = LogSerializer(logs, many=True)
153 - return JSONResponse(serializer.data) 149 + return Response(serializer.data)
  150 +
  151 +
  152 +class LogViewSet(viewsets.ModelViewSet):
  153 + permission_classes = [permissions.IsAuthenticated]
  154 + queryset = Log.objects.all()
  155 + serializer_class = LogSerializer