Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit 26dadaa

Browse files
committed
set up project template
0 parents  commit 26dadaa

File tree

12 files changed

+398
-0
lines changed

12 files changed

+398
-0
lines changed

.gitignore

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
data/
2+
environment/
3+
whoosh/
4+
activate*.sh
5+
activate*.bat
6+
7+
run.bat
8+
node_modules/
9+
frontend/package-lock.json
10+
*.elasticbeanstalk/
11+
env/
12+
.env.local
13+
.env.development.local
14+
.env.test.local
15+
.env.production.local
16+
*.sqlite3
17+
*.sqlite3-journal
18+
secrets/
19+
.vscode/
20+
.DS_Store
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+
26+
/.pnp
27+
.pnp.js
28+
29+
# Byte-compiled / optimized / DLL files
30+
__pycache__/
31+
*.py[cod]
32+
*$py.class
33+
34+
# C extensions
35+
*.so
36+
37+
# Distribution / packaging
38+
.Python
39+
build/
40+
package/
41+
develop-eggs/
42+
dist/
43+
downloads/
44+
eggs/
45+
.eggs/
46+
lib/
47+
lib64/
48+
parts/
49+
sdist/
50+
var/
51+
wheels/
52+
*.egg-info/
53+
.installed.cfg
54+
*.egg
55+
MANIFEST
56+
57+
# PyInstaller
58+
# Usually these files are written by a python script from a template
59+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
60+
*.manifest
61+
*.spec
62+
63+
# Installer logs
64+
pip-log.txt
65+
pip-delete-this-directory.txt
66+
67+
# Unit test / coverage reports
68+
htmlcov/
69+
.tox/
70+
.coverage
71+
.coverage.*
72+
.cache
73+
nosetests.xml
74+
coverage.xml
75+
*.cover
76+
.hypothesis/
77+
.pytest_cache/
78+
/coverage
79+
80+
# Translations
81+
*.mo
82+
*.pot
83+
84+
# Django stuff:
85+
*.log
86+
local_settings.py
87+
db.sqlite3
88+
89+
# Flask stuff:
90+
instance/
91+
.webassets-cache
92+
93+
# Scrapy stuff:
94+
.scrapy
95+
96+
# production
97+
/build
98+
99+
# Sphinx documentation
100+
docs/_build/
101+
102+
# PyBuilder
103+
target/
104+
105+
# Jupyter Notebook
106+
.ipynb_checkpoints
107+
108+
# pyenv
109+
.python-version
110+
111+
# celery beat schedule file
112+
celerybeat-schedule
113+
114+
# SageMath parsed files
115+
*.sage.py
116+
117+
# Environments
118+
.env
119+
.venv
120+
env/
121+
venv/
122+
ENV/
123+
env.bak/
124+
venv.bak/
125+
126+
# Spyder project settings
127+
.spyderproject
128+
.spyproject
129+
130+
# Rope project settings
131+
.ropeproject
132+
133+
# mkdocs documentation
134+
/site
135+
136+
# mypy
137+
.mypy_cache/
138+
139+
# VS Code workspace
140+
*.code-workspace
141+
# Elastic Beanstalk Files
142+
.elasticbeanstalk/*
143+
!.elasticbeanstalk/*.cfg.yml
144+
!.elasticbeanstalk/*.global.yml
145+
146+
# csv files exported
147+
NOTE*.csv
148+
149+
.idea
150+
.pylintrc

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# django-rest-microservice
2+
3+
This is a place holder for work currently in progress and not yet published.

env_setup.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
#!/bin/bash
3+
4+
echo "Removing existing environment/ directory..."
5+
rm -r environment
6+
7+
echo "Creating new environment at environment/ ..."
8+
python3 -m venv environment/
9+
10+
if [[ "$OSTYPE" == "msys"* ]]
11+
then
12+
ENVPATH="environment/Scripts/activate"
13+
elif [[ "$OSTYPE" == "cygwin"* ]]
14+
then
15+
ENVPATH="environment/Scripts/activate"
16+
COMMENT_SYNTAX="rem"
17+
elif [[ "$OSTYPE" == "win32"* ]]
18+
then
19+
ENVPATH="environment/Scripts/activate"
20+
else
21+
ENVPATH="environment/bin/activate"
22+
fi
23+
24+
echo "Installing python packages to environment at $ENVPATH ..."
25+
source $ENVPATH
26+
python3 -m pip install --upgrade pip
27+
python3 -m pip install -r requirements.txt
28+
deactivate
29+
30+
echo "Creating activate.sh..."
31+
touch activate.sh
32+
echo > activate.sh
33+
echo "# Created by env_setup.sh, modify the environment variables below if needed.">>activate.sh
34+
echo "source $ENVPATH">> activate.sh
35+
echo >> activate.sh
36+
37+
echo 'Finished setting up environment.'
38+
echo 'To activate environment, run `source activate.sh`.'
39+
40+
41+

make_package_migrations.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!environment/bin/python
2+
3+
"""
4+
Use this script to create migrations for this standalone package.Remember to update references to model outside this
5+
package (such as auth user model) manually by editing the generated migrations files. See printout instruction below.
6+
"""
7+
8+
import django
9+
from django.conf import settings
10+
from django.core.management import call_command
11+
12+
settings.configure(
13+
DEBUG=True,
14+
INSTALLED_APPS=(
15+
'django.contrib.contenttypes',
16+
'django.contrib.auth',
17+
'django_microservice',
18+
),
19+
)
20+
21+
django.setup()
22+
call_command('makemigrations', )
23+
24+
print('''
25+
Finished generating migrations.
26+
Check the migration file, update any reference to existing user model. Ie:
27+
28+
(1) Instead of
29+
```
30+
dependencies = [
31+
('auth', '0012_alter_user_first_name_max_length'),
32+
]
33+
```
34+
Change it to:
35+
```
36+
dependencies = [
37+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
38+
]
39+
```
40+
41+
(2) In fields, instead of referring to user model as
42+
```
43+
'auth.user'
44+
```
45+
change it to
46+
```
47+
settings.AUTH_USER_MODEL
48+
```
49+
''')

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
django>=2.2
2+
djangorestframework>=3.10
3+
djangorestframework-simplejwt>=5.0
4+
tox>=3.24
5+
wheel>=0.37

rest_framework_microservice/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class RestFrameworkMicroserviceConfig(AppConfig):
5+
name = 'rest_framework_microservice'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from django.conf import settings
2+
from django.test.signals import setting_changed
3+
4+
USER_SETTINGS = getattr(settings, "REST_FRAMEWORK_MICROSERVICE", None)
5+
6+
DEFAULTS = {
7+
"TOKEN_CUSTOM_USER_CLAIMS": [],
8+
9+
}
10+
11+
12+
class RestFrameworkMicroserviceSettings:
13+
def __init__(self, user_settings=None, defaults=None):
14+
self._user_settings = user_settings or {}
15+
self.defaults = defaults or DEFAULTS
16+
self._cached_attrs = set()
17+
18+
@property
19+
def user_settings(self):
20+
if not hasattr(self, "_user_settings"):
21+
self._user_settings = getattr(settings, "REST_FRAMEWORK_MICROSERVICE", {})
22+
return self._user_settings
23+
24+
def __getattr__(self, attr):
25+
26+
# check the setting is accepted
27+
if attr not in self.defaults:
28+
raise AttributeError(f"Invalid REST_FRAMEWORK_MICROSERVICE setting: {attr}")
29+
30+
# get from user settings or default value
31+
try:
32+
val = self.user_settings[attr]
33+
except KeyError:
34+
val = self.defaults[attr]
35+
36+
self._cached_attrs.add(attr)
37+
setattr(self, attr, val)
38+
return val
39+
40+
def reload(self):
41+
for attr in self._cached_attrs:
42+
delattr(self, attr)
43+
self._cached_attrs.clear()
44+
if hasattr(self, "_user_settings"):
45+
delattr(self, "_user_settings")
46+
47+
48+
drf_stripe_settings = DrfStripeSettings(USER_SETTINGS, DEFAULTS)
49+
50+
51+
def reload_rest_framework_microservice_settings(*args, **kwargs):
52+
print("Reloading rest_framework_microservice settings")
53+
setting = kwargs["setting"]
54+
if setting == "REST_FRAMEWORK_MICROSERVICE":
55+
drf_stripe_settings.reload()
56+
57+
58+
setting_changed.connect(reload_rest_framework_microservice_settings)

setup.cfg

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[metadata]
2+
name = django-rest-microservice
3+
version = 0
4+
description = Facilitating microservice architecture in Django REST framework
5+
long_description = file: README.md
6+
url = https://github.com/oscarychen/django-rest-microservice
7+
author = Oscar Chen
8+
author_email = quacky@duck.com
9+
license = MIT
10+
classifiers =
11+
Environment :: Web Environment
12+
Framework :: Django
13+
Framework :: Django :: 3.0
14+
Framework :: Django :: 3.1
15+
Framework :: Django :: 3.2
16+
Framework :: Django :: 4.0
17+
Intended Audience :: Developers
18+
License :: OSI Approved :: BSD License
19+
Operating System :: OS Independent
20+
Programming Language :: Python
21+
Programming Language :: Python :: 3
22+
Programming Language :: Python :: 3 :: Only
23+
Programming Language :: Python :: 3.6
24+
Programming Language :: Python :: 3.7
25+
Programming Language :: Python :: 3.8
26+
Programming Language :: Python :: 3.9
27+
Topic :: Internet :: WWW/HTTP
28+
Topic :: Internet :: WWW/HTTP :: Dynamic Content
29+
30+
[options]
31+
include_package_data = true
32+
packages = find:
33+
python_requires = >=3.6
34+
install_requires =
35+
Django >= 2.2
36+
djangorestframework >= 3.0

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
long_description_content_type='text/markdown',
5+
packages=find_packages(exclude=("tests",)),
6+
)

0 commit comments

Comments
 (0)