Commit 101f3bf2aaeb25083ac9c9dab127859e9d41bc8e

Authored by fbormann
1 parent b0f214b3

fixed api which was broken when we removed core app from project, serializers fo…

…r log and users are now working
amadeus/settings.py
... ... @@ -75,6 +75,7 @@ INSTALLED_APPS = [
75 75 'mailsender',
76 76 'security',
77 77 'themes',
  78 + 'api',
78 79  
79 80 ]
80 81  
... ... @@ -289,6 +290,21 @@ S3DIRECT_DESTINATIONS = {
289 290  
290 291 }
291 292  
  293 +#API CONFIG STARTS
  294 +#TELL the rest framework to use a different backend
  295 +REST_FRAMEWORK = {
  296 + 'DEFAULT_AUTHENTICATION_CLASSES':(
  297 + 'oauth2_provider.ext.rest_framework.OAuth2Authentication',),
  298 + 'DEFAULT_PERMISSION_CLASSES':(
  299 + 'rest_framework.permissions.IsAuthenticated',),
  300 + 'PAGE_SIZE': 10, #pagination purposes
  301 +}
  302 +
  303 +OAUTH2_PROVIDER = {
  304 + 'SCOPES':{'read':'Read scope', 'write': 'Write scope'}
  305 +}
  306 +#API CONFIG ENDS
  307 +
292 308 # FILE UPLOAD
293 309 MAX_UPLOAD_SIZE = 10485760
294 310  
... ...
amadeus/urls.py
... ... @@ -25,6 +25,7 @@ urlpatterns = [
25 25 url(r'^users/', include('users.urls', namespace = 'users')),
26 26 url(r'^admin/', admin.site.urls),
27 27 url(r'^$', index, name = 'home'),
  28 + url(r'api/', include('api.urls', namespace = 'api')),
28 29 url(r'^categories/', include('categories.urls', namespace = 'categories')),
29 30 url(r'^subjects/', include('subjects.urls', namespace = 'subjects')),
30 31 url(r'^groups/', include('students_group.urls', namespace = 'groups')),
... ...
api/__init__.py 0 → 100644
api/admin.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +from django.contrib import admin
  2 +
  3 +# Register your models here.
... ...
api/apps.py 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +from django.apps import AppConfig
  2 +
  3 +
  4 +class ApiConfig(AppConfig):
  5 + name = 'api'
... ...
api/migrations/__init__.py 0 → 100644
api/models.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +from django.db import models
  2 +
  3 +# Create your models here.
... ...
api/tests.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +from django.test import TestCase
  2 +
  3 +# Create your tests here.
... ...
api/urls.py 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +from django.conf.urls import url, include
  2 +
  3 +# ========== API IMPORTS ============= #
  4 +
  5 +from rest_framework import routers
  6 +
  7 +from users.views import UserViewSet
  8 +from log.views import LogViewSet
  9 +
  10 +router = routers.DefaultRouter()
  11 +router.register(r'logs', LogViewSet)
  12 +router.register(r'usersapi', UserViewSet)
  13 +
  14 +urlpatterns = [
  15 + #API REST
  16 + url(r'^', include(router.urls)),
  17 +]
0 18 \ No newline at end of file
... ...
api/views.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +from django.shortcuts import render
  2 +
  3 +# Create your views here.
... ...
log/serializers.py 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +from rest_framework import serializers
  2 +from .models import Log
  3 +
  4 +class LogSerializer(serializers.ModelSerializer):
  5 + class Meta:
  6 + model = Log
  7 + fields = '__all__'
0 8 \ No newline at end of file
... ...
log/views.py
1 1 from django.shortcuts import render
2   -
  2 +#API IMPORTS
  3 +from rest_framework import viewsets
  4 +from .serializers import LogSerializer
  5 +from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnly
  6 +from .models import Log
3 7 # Create your views here.
  8 +
  9 +#REST API VIEWS
  10 +class LogViewSet(viewsets.ModelViewSet):
  11 + permission_classes = [IsAuthenticated]
  12 + queryset = Log.objects.all()
  13 + serializer_class = LogSerializer
4 14 \ No newline at end of file
... ...
users/serializers.py
... ... @@ -4,6 +4,5 @@ from .models import User
4 4 class UserSerializer(serializers.ModelSerializer):
5 5 class Meta:
6 6 model = User
7   - fields = ('username','email','name','city','state','gender','image','birth_date','phone',
8   - 'cpf','type_profile','titration','year_titration','institution','curriculum','date_created',
  7 + fields = ('username','email','image','last_update','date_created','last_name','social_name',
9 8 'is_staff','is_active')
... ...