-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Initial Commit
- Loading branch information
0 parents
commit 9fc8445
Showing
40 changed files
with
928 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[behave] | ||
paths = organization/tests/acceptance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
.pyc | ||
dev.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM python:3.9-alpine | ||
|
||
WORKDIR /app | ||
|
||
# set environment variables | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
# install psycopg2 dependencies | ||
RUN apk update \ | ||
&& apk add postgresql-dev gcc python3-dev musl-dev | ||
|
||
# install dependencies | ||
COPY requirements.txt /app/requirements.txt | ||
RUN pip install --upgrade pip | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
|
||
# copy project | ||
COPY . . |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for SampleDemo project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SampleDemo.settings') | ||
|
||
application = get_asgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
""" | ||
Django settings for SampleDemo project. | ||
Generated by 'django-admin startproject' using Django 3.1.7. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.1/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/3.1/ref/settings/ | ||
""" | ||
from datetime import timedelta | ||
from pathlib import Path | ||
import os | ||
import sentry_sdk | ||
from sentry_sdk.integrations.django import DjangoIntegration | ||
|
||
# Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = os.getenv('SECRET_KEY') | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = int(os.getenv('DEBUG')) | ||
|
||
ALLOWED_HOSTS = ['*'] | ||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'organization', | ||
'rest_framework', | ||
'behave_django' | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'SampleDemo.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [BASE_DIR / 'templates'] | ||
, | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'SampleDemo.wsgi.application' | ||
|
||
# Database | ||
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.postgresql', | ||
'NAME': os.getenv('DB_NAME'), | ||
'USER': os.getenv('DB_USERNAME'), | ||
'PASSWORD': os.getenv('DB_PASSWORD'), | ||
'HOST': os.getenv('DB_HOST'), | ||
'PORT': os.getenv('DB_PORT') | ||
} | ||
} | ||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/3.1/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/3.1/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/3.1/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
STATIC_ROOT = os.path.join(BASE_DIR, "static") | ||
|
||
REST_FRAMEWORK = { | ||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', | ||
'PAGE_SIZE': 5, | ||
'DEFAULT_PERMISSION_CLASSES': ( | ||
'rest_framework.permissions.IsAuthenticated', | ||
'rest_framework.permissions.AllowAny', | ||
|
||
), | ||
'DEFAULT_RENDERER_CLASSES': ( | ||
'rest_framework.renderers.JSONRenderer', | ||
), | ||
'DEFAULT_PARSER_CLASSES': ( | ||
'rest_framework.parsers.JSONParser', | ||
'rest_framework.parsers.MultiPartParser', | ||
'rest_framework.parsers.FileUploadParser', | ||
'rest_framework.parsers.FormParser', | ||
), | ||
'DEFAULT_AUTHENTICATION_CLASSES': ( | ||
'rest_framework_simplejwt.authentication.JWTAuthentication', | ||
'rest_framework.authentication.SessionAuthentication', | ||
'rest_framework.authentication.BasicAuthentication', | ||
), | ||
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',), | ||
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.NamespaceVersioning', | ||
} | ||
|
||
SIMPLE_JWT = { | ||
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5), | ||
'REFRESH_TOKEN_LIFETIME': timedelta(days=1), | ||
'ROTATE_REFRESH_TOKENS': False, | ||
'BLACKLIST_AFTER_ROTATION': True, | ||
'UPDATE_LAST_LOGIN': False, | ||
|
||
'ALGORITHM': 'HS256', | ||
'SIGNING_KEY': SECRET_KEY, | ||
'VERIFYING_KEY': None, | ||
'AUDIENCE': None, | ||
'ISSUER': None, | ||
|
||
'AUTH_HEADER_TYPES': ('Bearer',), | ||
'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION', | ||
'USER_ID_FIELD': 'id', | ||
'USER_ID_CLAIM': 'user_id', | ||
|
||
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',), | ||
'TOKEN_TYPE_CLAIM': 'token_type', | ||
|
||
'JTI_CLAIM': 'jti', | ||
|
||
'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp', | ||
'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5), | ||
'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1), | ||
} | ||
|
||
|
||
sentry_sdk.init( | ||
dsn="https://[email protected]/5683366", | ||
integrations=[DjangoIntegration()], | ||
|
||
# Set traces_sample_rate to 1.0 to capture 100% | ||
# of transactions for performance monitoring. | ||
# We recommend adjusting this value in production. | ||
traces_sample_rate=1.0, | ||
|
||
# If you wish to associate users to errors (assuming you are using | ||
# django.contrib.auth) you may enable sending PII data. | ||
send_default_pii=True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""SampleDemo URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/3.1/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.urls import include, path | ||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
""" | ||
from django.contrib import admin | ||
from django.urls import path, include | ||
|
||
urlpatterns = [ | ||
path('admin/', admin.site.urls), | ||
path('api/', include('api.urls')), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for SampleDemo project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SampleDemo.settings') | ||
|
||
application = get_wsgi_application() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.urls import path, include | ||
|
||
urlpatterns = [ | ||
path('v1/', include('api.v1.urls')), | ||
] |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from rest_framework import serializers | ||
from organization.models import Organization | ||
|
||
|
||
class OrganizationSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Organization | ||
fields = "__all__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path | ||
from . import views | ||
|
||
urlpatterns = [ | ||
path('', views.OrganizationAPI.as_view()), | ||
path('<int:pk>', views.OrganizationRetrieveUpdateDestroyAPI.as_view()), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from rest_framework import status | ||
from rest_framework.generics import (ListCreateAPIView, RetrieveUpdateDestroyAPIView) | ||
from rest_framework.response import Response | ||
|
||
from organization.models import Organization | ||
from . import serializer | ||
|
||
|
||
class OrganizationAPI(ListCreateAPIView): | ||
queryset = Organization.objects.all() | ||
serializer_class = serializer.OrganizationSerializer | ||
|
||
def create(self, request, *args, **kwargs): | ||
serializer = self.get_serializer(data=request.data) | ||
serializer.is_valid(raise_exception=True) | ||
self.perform_create(serializer) | ||
headers = self.get_success_headers(serializer.data) | ||
return Response({"status": True, | ||
"message": "Organization Added !", | ||
"data": serializer.data}, | ||
status=status.HTTP_201_CREATED, headers=headers) | ||
|
||
|
||
class OrganizationRetrieveUpdateDestroyAPI(RetrieveUpdateDestroyAPIView): | ||
serializer_class = serializer.OrganizationSerializer | ||
|
||
def get_queryset(self): | ||
return Organization.objects.filter(id=self.kwargs.get('pk', None)) | ||
|
||
def update(self, request, *args, **kwargs): | ||
partial = kwargs.pop('partial', False) | ||
instance = self.get_object() | ||
serializer = self.get_serializer(instance, data=request.data, partial=partial) | ||
serializer.is_valid(raise_exception=True) | ||
self.perform_update(serializer) | ||
|
||
if getattr(instance, '_prefetched_objects_cache', None): | ||
# If 'prefetch_related' has been applied to a queryset, we need to | ||
# forcibly invalidate the prefetch cache on the instance. | ||
instance._prefetched_objects_cache = {} | ||
|
||
return Response({"status": True, "message": "Organization Updated !", "data": serializer.data}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path, include | ||
|
||
urlpatterns = [ | ||
path('user/', include('api.v1.user.urls')), | ||
path('organization/', include('api.v1.organization.urls')), | ||
|
||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.urls import path | ||
from rest_framework_simplejwt.views import ( | ||
TokenObtainPairView, | ||
TokenRefreshView, | ||
TokenVerifyView | ||
) | ||
|
||
urlpatterns = [ | ||
path('login/', TokenObtainPairView.as_view(), name='token_obtain_pair'), | ||
path('refresh-token/', TokenRefreshView.as_view(), name='token_refresh'), | ||
path('token-verify/', TokenVerifyView.as_view(), name='token_verify'), | ||
|
||
] |
Oops, something went wrong.