From fbbaa76153e9b9ddebec509c0055c5076f986538 Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Sun, 13 Aug 2017 09:44:48 -0400 Subject: [PATCH] Establish basic REST Framework API structure. --- api/__init__.py | 0 api/admin.py | 3 +++ api/apps.py | 5 +++++ api/migrations/__init__.py | 0 api/models.py | 3 +++ api/serializers.py | 11 +++++++++++ api/tests.py | 3 +++ api/urls.py | 16 ++++++++++++++++ api/views.py | 12 ++++++++++++ babyblotter/settings.py | 31 +++++++++++-------------------- babyblotter/urls.py | 3 ++- db.sqlite3 | Bin 3072 -> 37888 bytes 12 files changed, 66 insertions(+), 21 deletions(-) create mode 100644 api/__init__.py create mode 100644 api/admin.py create mode 100644 api/apps.py create mode 100644 api/migrations/__init__.py create mode 100644 api/models.py create mode 100644 api/serializers.py create mode 100644 api/tests.py create mode 100644 api/urls.py create mode 100644 api/views.py diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/api/admin.py b/api/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/api/apps.py b/api/apps.py new file mode 100644 index 00000000..d87006dd --- /dev/null +++ b/api/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + name = 'api' diff --git a/api/migrations/__init__.py b/api/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/api/models.py b/api/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/api/serializers.py b/api/serializers.py new file mode 100644 index 00000000..b3c619c4 --- /dev/null +++ b/api/serializers.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib.auth.models import User +from rest_framework import serializers + + +class UserSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = User + fields = ('url', 'username', 'email', 'is_staff') \ No newline at end of file diff --git a/api/tests.py b/api/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 00000000..5c1e290e --- /dev/null +++ b/api/urls.py @@ -0,0 +1,16 @@ +from django.conf.urls import url, include +from rest_framework import routers + +from .views import UserViewSet + +# Routers provide an easy way of automatically determining the URL conf. +router = routers.DefaultRouter() +router.register(r'users', UserViewSet) + +# Wire up our API using automatic URL routing. +# Additionally, we include login URLs for the browsable API. +urlpatterns = [ + url(r'^api/', include(router.urls)), + url(r'^api-auth/', include('rest_framework.urls', + namespace='rest_framework')) +] diff --git a/api/views.py b/api/views.py new file mode 100644 index 00000000..72964d58 --- /dev/null +++ b/api/views.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib.auth.models import User +from rest_framework import viewsets + +from .serializers import (UserSerializer) + + +class UserViewSet(viewsets.ModelViewSet): + queryset = User.objects.all() + serializer_class = UserSerializer diff --git a/babyblotter/settings.py b/babyblotter/settings.py index d920aa17..fe127e34 100644 --- a/babyblotter/settings.py +++ b/babyblotter/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'rest_framework' ] MIDDLEWARE = [ @@ -81,31 +82,12 @@ DATABASES = { } -# Password validation -# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - # Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/ LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'UTC' +TIME_ZONE = 'America/New_York' USE_I18N = True @@ -118,3 +100,12 @@ USE_TZ = True # https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/' + + +# Django Rest Framework +# http://www.django-rest-framework.org/# +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' + ] +} diff --git a/babyblotter/urls.py b/babyblotter/urls.py index 1555beba..0d6db60e 100644 --- a/babyblotter/urls.py +++ b/babyblotter/urls.py @@ -13,9 +13,10 @@ Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ -from django.conf.urls import url +from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), + url(r'', include('api.urls')), ] diff --git a/db.sqlite3 b/db.sqlite3 index fb674899ca3c7407e7f882890f08a0e16ed4d35b..ce34a691667ad8e15b2d679719622bb82e8926f8 100644 GIT binary patch literal 37888 zcmeHQU2GgnR_^NRneil<#IfV;WgU}_W8a&RV|%81dVUf??!=iSPU7*6-H%`B?-k z52TPw=Ps@9}@*|HOZ@7aNb~ z2yg^m83KWR5Oqq1;Orm-z9SHv8H3;pN(jP`@H+zjL;O`-#An675Pwm;A^OpC^fO2m z{t=QsdzTjS2_xg_x>c{+)k-}Qi9`*%VmEBFq(-8N$w+cCswq+Jq8hoVCZ-aq8dD?J zj`@V4yJ>T)u?7rD!z?wdnz2=Pf{IzTjI#N}C|Q-&##%2qx*F4y+O4A?=Ob56!jbdH zEZIe~QLWVtvsg5&TCG|$%1}Ua)vEUrrm1l?7D*ogVY9BVxKXnnZrL@@n8af<0gy1~O3+vdR@t;m`$8L^itAc5rr+>`kR?}$>Im7iYGs?& zwDH19iciI~SUeWF;qwXO*V8PF1VzBNTz%Ar*C6;(p}XOYPpPp)B9cf;K0yX(ie?#rO15|N~u zK%nnCfH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