Skip to content

Commit

Permalink
added new views (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
paribaker committed Dec 19, 2022
1 parent f7c9b13 commit 4197058
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 103 deletions.
86 changes: 43 additions & 43 deletions {{cookiecutter.project_slug}}/app.json
@@ -1,49 +1,49 @@
{
"name": "{{ cookiecutter.project_name }}",
"env": {
"ALLOWED_HOSTS": {
"value": ".herokuapp.com"
},
"DEBUG": {
"value": "True"
},
"DISABLE_COLLECTSTATIC": {
"value": 1
},
"ENVIRONMENT": {
"value": "development"
},
"PROJECT_PATH": {
"value": "{{ cookiecutter.project_slug }}"
},
"NPM_CONFIG_PRODUCTION": {
"value": "false"
},
"SECRET_KEY": {
"generator": "secret"
}
"name": "{{ cookiecutter.project_name }}",
"env": {
"ALLOWED_HOSTS": {
"value": ".herokuapp.com"
},
"addons": [
"heroku-postgresql:standard-0",
"DEBUG": {
"value": "True"
},
"DISABLE_COLLECTSTATIC": {
"value": 1
},
"ENVIRONMENT": {
"value": "development"
},
"PROJECT_PATH": {
"value": "{{ cookiecutter.project_slug }}"
},
"NPM_CONFIG_PRODUCTION": {
"value": "false"
},
"SECRET_KEY": {
"generator": "secret"
}
},
"addons": [
"heroku-postgresql:standard-0",
"papertrail:Choklad"
],
"environments": {
"review": {
"addons": [
"heroku-postgresql:mini",
"papertrail:Choklad"
],
"environments": {
"review": {
"addons": [
"heroku-postgresql:mini",
"papertrail:Choklad"
]
}
]
}
},
"buildpacks": [
{
"url": "heroku/nodejs"
},
"buildpacks": [
{
"url": "heroku/nodejs"
},
{
"url": "heroku/python"
}
],
"scripts": {
"postdeploy": "./scripts/db_setup.sh"
{
"url": "heroku/python"
}
],
"scripts": {
"postdeploy": "./scripts/db_setup.sh"
}
}
@@ -0,0 +1,45 @@
from django.conf import settings
from django.conf.urls.static import static
from django.urls import include, path, re_path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions
from rest_framework_nested import routers

from {{ cookiecutter.project_slug }}.common import views as common_views
from {{ cookiecutter.project_slug }}.core import urls as core_urls

router = routers.SimpleRouter()
if settings.DEBUG:
router = routers.DefaultRouter()

# extend url patterns here
urlpatterns = [*core_urls.urlpatterns]

schema_view = get_schema_view(
openapi.Info(
title="njc API",
default_version="1.0",
description="njc Docs",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="support@njc.com"),
license=openapi.License(name="BSD License"),
),
public=False,
permission_classes=[permissions.IsAuthenticated],
)

urlpatterns = urlpatterns + [
re_path(r"^api/swagger(?P<format>\.json|\.yaml)$", schema_view.without_ui(cache_timeout=0), name="schema-json"),
path(r"api/docs/", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui"),
path(r"api/swagger/", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui"),
path(r"api/redoc/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
]
if settings.DEBUG: # pragma: no cover
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += [path("api-auth/", include("rest_framework.urls"))]

urlpatterns += [
re_path(r".*", common_views.index),
]
@@ -0,0 +1,28 @@
{% if cookiecutter.client_app == "Vue3" -%}
from django.shortcuts import render
from django.template.exceptions import TemplateDoesNotExist
{% endif %}
{% if cookiecutter.use_graphql == 'y' -%}
from django.template.response import TemplateResponse
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import ensure_csrf_cookie
{% endif -%}


{% if cookiecutter.use_graphql == 'y' %}

# Serve React frontend
@ensure_csrf_cookie
@never_cache
def index(request):
return TemplateResponse(request, ["index.html", "core/index-placeholder.html"])
{% elif cookiecutter.client_app.lower() == 'None' -%}
def index(request):
return redirect(to="/docs/swagger/")
{% else %}
def index(request):
try:
return render(request, "index.html")
except TemplateDoesNotExist:
return render(request, "core/index-placeholder.html")
{% endif -%}
@@ -1,10 +1,6 @@
from dj_rest_auth import views as rest_auth_views
from django.conf import settings
from django.conf.urls.static import static
from django.urls import include, path, re_path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions
from django.urls import include, path
from rest_framework_nested import routers

from {{ cookiecutter.project_slug }}.core import views as core_views
Expand All @@ -28,31 +24,3 @@
path(r"api/password/reset/", core_views.request_reset_link),
path(r"api/password/change/", rest_auth_views.PasswordChangeView.as_view()),
]

schema_view = get_schema_view(
openapi.Info(
title="{{ cookiecutter.project_name }} API",
default_version="1.0",
description="{{ cookiecutter.project_name }} Docs",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="support@{{ cookiecutter.project_slug }}.com"),
license=openapi.License(name="BSD License"),
),
public=False,
permission_classes=[permissions.IsAuthenticated],
)

urlpatterns = urlpatterns + [
re_path(r"^api/swagger(?P<format>\.json|\.yaml)$", schema_view.without_ui(cache_timeout=0), name="schema-json"),
path(r"api/docs/", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui"),
path(r"api/swagger/", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui"),
path(r"api/redoc/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
]
if settings.DEBUG: # pragma: no cover
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += [path("api-auth/", include("rest_framework.urls"))]

urlpatterns += [
re_path(r".*", core_views.index),
]
Expand Up @@ -2,16 +2,7 @@
from django.contrib.auth import authenticate
from django.contrib.auth.tokens import default_token_generator
from django.db import transaction
{% if cookiecutter.client_app == "Vue3" -%}
from django.shortcuts import render
from django.template.exceptions import TemplateDoesNotExist
{% endif -%}
from django.template.loader import render_to_string
{% if cookiecutter.use_graphql == 'y' -%}
from django.template.response import TemplateResponse
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import ensure_csrf_cookie
{% endif -%}
from rest_framework import generics, mixins, permissions, status, viewsets
from rest_framework.decorators import api_view, permission_classes
from rest_framework.exceptions import ValidationError
Expand All @@ -23,22 +14,6 @@
from .permissions import CreateOnlyPermissions
from .serializers import UserLoginSerializer, UserRegistrationSerializer, UserSerializer

{% if cookiecutter.use_graphql == 'y' %}
# Serve React frontend
@ensure_csrf_cookie
@never_cache
def index(request):
return TemplateResponse(request, ["index.html", "core/index-placeholder.html"])
{% elif cookiecutter.client_app.lower() == 'None' %}
def index(request):
return redirect(to="/docs/swagger/")
{% else %}
def index(request):
try:
return render(request, "index.html")
except TemplateDoesNotExist:
return render(request, "core/index-placeholder.html")
{% endif %}

class UserLoginView(generics.GenericAPIView):
serializer_class = UserLoginSerializer
Expand Down
Expand Up @@ -12,6 +12,6 @@
path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=settings.DEBUG))),
{% endif -%}
path(r"staff/", admin.site.urls),
path(r"", include("{{ cookiecutter.project_slug }}.core.favicon_urls")),
path(r"", include("{{ cookiecutter.project_slug }}.core.urls")),
path(r"", include("{{ cookiecutter.project_slug }}.common.favicon_urls")),
path(r"", include("{{ cookiecutter.project_slug }}.common.urls")),
]

0 comments on commit 4197058

Please sign in to comment.