Does all fontend routes based on react
12 files changed, +71 -23
+4-2dev
| @@ -35,9 +35,11 @@ if [ "$1" = "back" ]; then | ||
| 35 | 35 | # compose up the dev compose file |
| 36 | 36 | docker compose -f dev-compose.yml up -d |
| 37 | 37 | |
| 38 | - # create secret key | |
| 38 | + # create secret key if .env doesn't exist | |
| 39 | 39 | cd rango/backend |
| 40 | - python manage.py createsecret | |
| 40 | + if [ ! -f ".env" ]; then | |
| 41 | + python manage.py createsecret | |
| 42 | + fi | |
| 41 | 43 | |
| 42 | 44 | # migrate database |
| 43 | 45 | python manage.py migrate |
+0-1rango/.dockerignore
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | **/venv |
| 2 | 2 | **/__pycache__ |
| 3 | 3 | **/node_modules |
| 4 | -**/.env | |
| 5 | 4 | **/dist |
| 6 | 5 | **/db.sqlite3 |
+9-0rango/backend/api/urls.py
| @@ -0,0 +1,9 @@ | ||
| 1 | +from django.urls import include, re_path | |
| 2 | +from .views import ApiRoot | |
| 3 | +from api.users.urls import router as user_router | |
| 4 | + | |
| 5 | + | |
| 6 | +urlpatterns = [ | |
| 7 | + re_path('$', ApiRoot.as_view(), name='api-root'), | |
| 8 | + re_path('', include(user_router.urls)), | |
| 9 | +] |
+9-0rango/backend/api/users/serializers.py
| @@ -0,0 +1,9 @@ | ||
| 1 | +from rest_framework import serializers | |
| 2 | +from django.contrib.auth.models import User | |
| 3 | + | |
| 4 | + | |
| 5 | +class UserSerializer(serializers.HyperlinkedModelSerializer): | |
| 6 | + class Meta: | |
| 7 | + model = User | |
| 8 | + fields = ['url', 'id', 'username', 'first_name', 'last_name', 'email', 'password'] | |
| 9 | + extra_kwargs = {'password': {'write_only': True}} |
+7-0rango/backend/api/users/urls.py
| @@ -0,0 +1,7 @@ | ||
| 1 | +from django.urls import path, include | |
| 2 | +from api.users.views import UserViewSet | |
| 3 | +from rest_framework.routers import SimpleRouter | |
| 4 | + | |
| 5 | +router = SimpleRouter() | |
| 6 | +router.register(r'users', UserViewSet) | |
| 7 | + |
+13-0rango/backend/api/users/views.py
| @@ -0,0 +1,13 @@ | ||
| 1 | +from rest_framework import viewsets | |
| 2 | +from rest_framework.permissions import IsAuthenticated, AllowAny | |
| 3 | +from django.contrib.auth.models import User | |
| 4 | +from api.users.serializers import UserSerializer | |
| 5 | + | |
| 6 | + | |
| 7 | +class UserViewSet(viewsets.ModelViewSet): | |
| 8 | + """ | |
| 9 | + API endpoint that allows users to be viewed or edited. | |
| 10 | + """ | |
| 11 | + queryset = User.objects.all().order_by('-date_joined') | |
| 12 | + serializer_class = UserSerializer | |
| 13 | + permission_classes = [AllowAny] |
+9-1rango/backend/api/views.py
| @@ -1,3 +1,11 @@ | ||
| 1 | -from django.shortcuts import render | |
| 1 | +from rest_framework.response import Response | |
| 2 | +from rest_framework.routers import APIRootView | |
| 3 | +from rest_framework.reverse import reverse | |
| 2 | 4 | |
| 3 | 5 | # Create your views here. |
| 6 | +class ApiRoot(APIRootView): | |
| 7 | + | |
| 8 | + def get(self, request, *args, **kwargs): | |
| 9 | + return Response({ | |
| 10 | + 'users': reverse('user-list', request=request), | |
| 11 | + }) |
+3-1rango/backend/backend/settings.py
| @@ -48,7 +48,9 @@ INSTALLED_APPS = [ | ||
| 48 | 48 | 'django.contrib.sessions', |
| 49 | 49 | 'django.contrib.messages', |
| 50 | 50 | 'django.contrib.staticfiles', |
| 51 | - 'backend' | |
| 51 | + 'backend', | |
| 52 | + 'api', | |
| 53 | + 'rest_framework', | |
| 52 | 54 | ] |
| 53 | 55 | |
| 54 | 56 | MIDDLEWARE = [ |
+8-6rango/backend/backend/urls.py
| @@ -14,15 +14,17 @@ Including another URLconf | ||
| 14 | 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) |
| 15 | 15 | """ |
| 16 | 16 | from django.contrib import admin |
| 17 | -from django.urls import path | |
| 18 | -from backend import views | |
| 17 | +from django.urls import include, re_path | |
| 18 | +from utils.views import RangoView | |
| 19 | 19 | |
| 20 | 20 | urlpatterns = [ |
| 21 | - path('admin/', admin.site.urls), | |
| 22 | - path('', views.IndexView.as_view(), name='index'), | |
| 21 | + re_path(r'^api/', include('api.urls')), | |
| 22 | + re_path(r'^admin/', admin.site.urls), | |
| 23 | + re_path(r'(?!api?/).*', RangoView.as_view()), | |
| 23 | 24 | ] |
| 24 | 25 | |
| 25 | -# include media files | |
| 26 | +# include media files in development | |
| 26 | 27 | from django.conf import settings |
| 27 | 28 | from django.conf.urls.static import static |
| 28 | -urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) | |
| 29 | +if settings.DEBUG: | |
| 30 | + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
+0-10rango/backend/backend/views.py
| @@ -1,10 +0,0 @@ | ||
| 1 | -from django.views.generic import TemplateView | |
| 2 | - | |
| 3 | - | |
| 4 | -class IndexView(TemplateView): | |
| 5 | - template_name = 'index.html' | |
| 6 | - | |
| 7 | - def get_context_data(self, **kwargs): | |
| 8 | - context = super().get_context_data(**kwargs) | |
| 9 | - context['title'] = 'backend' | |
| 10 | - return context |
+4-2rango/backend/entrypoint.sh
| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | #!/bin/bash |
| 2 | 2 | # For production only |
| 3 | 3 | |
| 4 | -# create secret key | |
| 5 | -python manage.py createsecret | |
| 4 | +# create secret key if .env doesn't exist | |
| 5 | +if [ ! -f ".env" ]; then | |
| 6 | + python manage.py createsecret | |
| 7 | +fi | |
| 6 | 8 | |
| 7 | 9 | # migrate database |
| 8 | 10 | python manage.py migrate |
+5-0rango/backend/utils/views.py
| @@ -0,0 +1,5 @@ | ||
| 1 | +from django.views.generic import TemplateView | |
| 2 | + | |
| 3 | + | |
| 4 | +class RangoView(TemplateView): | |
| 5 | + template_name = 'index.html' |