From ccc8b18581a9f00a6deb95cd5b721bec3ffae44d Mon Sep 17 00:00:00 2001 From: Gavin Vickery Date: Mon, 3 Jan 2022 14:49:55 -0800 Subject: [PATCH 01/13] - Removing legacy modules from user model - Fixing invalid fields on admin fixtures - Rebuilding requirements file - Updating README --- .python-version | 1 + Makefile | 2 +- README.md | 65 +++++++++------------------------------------ apps/user/base.py | 19 +++---------- fixtures/admin.json | 1 - requirements.txt | 57 ++++++++++++++++++++------------------- runtime.txt | 2 +- 7 files changed, 49 insertions(+), 98 deletions(-) create mode 100644 .python-version diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..89a1ad7 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.8.12 diff --git a/Makefile b/Makefile index eb23de0..530a432 100755 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ setup: - pip install -IUr requirements.txt + pip install -r requirements.txt python manage.py migrate python manage.py loaddata fixtures/admin.json python manage.py loaddata fixtures/mail.json diff --git a/README.md b/README.md index b1e7e61..760bddc 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,18 @@ # Django API Starter ## Versions -- Python 3.9.x -- Django 3.2.x +- Python 3.8.12 +- Django 4.0 ## Installation -Clone repo: -``` -git clone https://github.com/inputlogic/django-api-starter.git ___PROJNAME___ -cd ___PROJNAME___ -``` - Create and activate local python environment: ``` -python -m venv env +virtualenv env . ./env/bin/activate ``` -Install requirements: - -``` -pip install -r requirements.init.txt -pip freeze > requirements.txt -rm requirements.init.txt -``` - -A note on `requirements.init.txt` vs `requirements.txt`: - -> `requirements.init.txt` installs the latest versions of each package. -> -> If you have problems with the packages installed from `requirements.init.txt`, -> try installing django-api-starter's `requirements.txt` instead. It contains -> specific versions that are expected to work. - -Save local environment variables: - -``` -mv env.template .env -``` - Create database: ``` createdb ___PROJNAME___ @@ -58,29 +30,18 @@ DATABASES = { } ``` -Django setup: -``` -python manage.py migrate -python manage.py createsuperuser -python manage.py collectstatic -``` - -Create a fresh git repo for the new project: +Setup & run Django: ``` -rm -rf .git -git init -git commit -am '___PROJNAME___ initial commit from django-api-starter' +make setup +./manage.py createsuperuser +./manage.py runserver ``` -## Project Configuration - -(Note that areas requiring configuration have been marked with `___CHANGEME___`, -to make them easy to find.) +A note on `requirements.init.txt` vs `requirements.txt`: -Delete example apps: -``` -rm -rf apps/workerexample -rm -rf apps/proxyexample -``` +> `requirements.init.txt` installs the latest versions of each package. +> +> If you have problems with the packages installed from `requirements.init.txt`, +> try installing django-api-starter's `requirements.txt` instead. It contains +> specific versions that are expected to work. -Remove references to example apps from `project/settings.py` & `project/urls.py` diff --git a/apps/user/base.py b/apps/user/base.py index eed5424..3121e6f 100644 --- a/apps/user/base.py +++ b/apps/user/base.py @@ -1,7 +1,6 @@ from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin from django.db import models from django.utils import timezone -from django.utils.translation import ugettext_lazy as _ class UserManager(BaseUserManager): @@ -26,20 +25,10 @@ def normalize_email(self, email): class AbstractEmailUser(AbstractBaseUser, PermissionsMixin): - email = models.EmailField(_('email address'), max_length=255, unique=True) - - is_staff = models.BooleanField( - _('staff status'), - default=False, - help_text=_('Designates whether the user can log into this admin site.') - ) - is_active = models.BooleanField( - _('active'), - default=True, - help_text=_('Designates whether this user should be treated as ' - 'active. Unselect this instead of deleting accounts.') - ) - date_joined = models.DateTimeField(_('date joined'), default=timezone.now) + email = models.EmailField(max_length=255, unique=True) + is_staff = models.BooleanField(default=False) + is_active = models.BooleanField(default=True) + date_joined = models.DateTimeField(default=timezone.now) objects = UserManager() diff --git a/fixtures/admin.json b/fixtures/admin.json index ed68083..2648847 100644 --- a/fixtures/admin.json +++ b/fixtures/admin.json @@ -37,7 +37,6 @@ "css_delete_button_background_color": "#D95D5D", "css_delete_button_background_hover_color": "#C94747", "css_delete_button_text_color": "#FFFFFF", - "css": "", "related_modal_active": true, "related_modal_background_color": "#EAEAEA", "related_modal_background_opacity": "0.2", diff --git a/requirements.txt b/requirements.txt index f2599dc..957373d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,44 +1,45 @@ -arrow==1.1.1 +arrow==1.2.1 asgiref==3.4.1 -boto3==1.18.3 -botocore==1.21.3 -certifi==2021.5.30 -charset-normalizer==2.0.3 +backports.zoneinfo==0.2.1 +boto3==1.20.27 +botocore==1.23.27 +certifi==2021.10.8 +charset-normalizer==2.0.9 dj-database-url==0.5.0 -Django==3.2.5 -django-admin-interface==0.16.3 -django-colorfield==0.4.2 +Django==4.0 +django-admin-interface==0.18.3 +django-colorfield==0.6.3 django-dotenv==1.4.2 -django-extensions==3.1.3 -django-filter==2.4.0 +django-extensions==3.1.5 +django-filter==21.1 django-flat-responsive==2.0 django-flat-theme==1.1.4 django-heroku==0.3.1 -django-storages==1.11.1 -djangorestframework==3.12.4 -djangorestframework-camel-case==1.2.0 +django-storages==1.12.3 +djangorestframework==3.13.1 +djangorestframework-camel-case==1.3.0 drf-api-tracking==1.8.0 -factory-boy==3.2.0 -Faker==8.10.1 -flake8==3.9.2 +factory-boy==3.2.1 +Faker==11.1.0 +flake8==4.0.1 gunicorn==20.1.0 -idna==3.2 +idna==3.3 jmespath==0.10.0 mccabe==0.6.1 -Pillow==8.3.1 -psycopg2 -psycopg2-binary -pycodestyle==2.7.0 -pyflakes==2.3.1 -Pygments==2.9.0 +Pillow==9.0.0 +psycopg2==2.9.3 +psycopg2-binary==2.9.3 +pycodestyle==2.8.0 +pyflakes==2.4.0 +Pygments==2.11.1 python-dateutil==2.8.2 -pytz==2021.1 +pytz==2021.3 raven==6.10.0 -requests==2.26.0 +requests==2.27.0 s3transfer==0.5.0 six==1.16.0 -sqlparse==0.4.1 +sqlparse==0.4.2 text-unidecode==1.3 -urllib3==1.26.6 -Werkzeug==2.0.1 +urllib3==1.26.7 +Werkzeug==2.0.2 whitenoise==5.3.0 diff --git a/runtime.txt b/runtime.txt index 9bff0e0..d9a16ae 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-3.9.6 +python-3.8.12 From 81cf25a4707666470946b21905ee168c4d290a96 Mon Sep 17 00:00:00 2001 From: Gavin Vickery Date: Mon, 3 Jan 2022 14:52:33 -0800 Subject: [PATCH 02/13] Fixing lint issues. --- apps/mail/tasks.py | 7 +++---- project/settings.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/mail/tasks.py b/apps/mail/tasks.py index e6d2186..48d737d 100644 --- a/apps/mail/tasks.py +++ b/apps/mail/tasks.py @@ -1,11 +1,9 @@ import logging -import json -import requests from smtplib import SMTPException from django.conf import settings from django.core.mail import send_mail as dj_send_mail -from apps.workers import task +# from apps.workers import task log = logging.getLogger(__name__) @@ -38,9 +36,10 @@ def _smtp_send(mail): return sent + # Should send emails inline by default. # ONLY enable workers if we're sending many emails and want to avoid server load -# +# # @task() def send_email(mail_id): """ diff --git a/project/settings.py b/project/settings.py index dedacdc..1cfd7d0 100644 --- a/project/settings.py +++ b/project/settings.py @@ -40,7 +40,7 @@ def get(variable, default=''): AUTH_USER_MODEL = 'user.User' INSTALLED_APPS = [ - # Custom Admin settings (must be before django.contrib.admin) + # Custom Admin settings (must be before django.contrib.admin) 'admin_interface', 'colorfield', From c9f6b9d672c802483f1966bc66852d7360530fed Mon Sep 17 00:00:00 2001 From: Gavin Vickery Date: Mon, 3 Jan 2022 14:55:43 -0800 Subject: [PATCH 03/13] Quick README fix. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 760bddc..2bc6bc1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Create and activate local python environment: ``` virtualenv env -. ./env/bin/activate +. env/bin/activate ``` Create database: From 61de38ff773a3ff2e6d562d923a3e9e59d5e5c4d Mon Sep 17 00:00:00 2001 From: mjreffel Date: Tue, 4 Jan 2022 10:17:20 -0800 Subject: [PATCH 04/13] Added install wheel before installing requirements to resolve dependency lookups and workflow failures --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c79d35d..ca9af42 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -53,6 +53,7 @@ jobs: export DATABASE_URL=postgres://postgres:@postgres:5432/django apt-get update -qy apt-get install -y python3-dev python3-pip + pip3 install wheel pip3 install -r requirements.txt pip3 install flake8 python3 manage.py test apps From 645561404acdb2db95e3b9afaa20410234aa174c Mon Sep 17 00:00:00 2001 From: mjreffel Date: Tue, 4 Jan 2022 10:23:49 -0800 Subject: [PATCH 05/13] Added in upgrade pip command to allow for django 4.0 to be found --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ca9af42..a22a968 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -53,6 +53,7 @@ jobs: export DATABASE_URL=postgres://postgres:@postgres:5432/django apt-get update -qy apt-get install -y python3-dev python3-pip + pip install --upgrade pip pip3 install wheel pip3 install -r requirements.txt pip3 install flake8 From 68b2f1d3bd73796621c0aa113e7651e7ec65d6a6 Mon Sep 17 00:00:00 2001 From: mjreffel Date: Tue, 4 Jan 2022 10:27:36 -0800 Subject: [PATCH 06/13] Changed to pip3 upgrade --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a22a968..963f73d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -53,7 +53,7 @@ jobs: export DATABASE_URL=postgres://postgres:@postgres:5432/django apt-get update -qy apt-get install -y python3-dev python3-pip - pip install --upgrade pip + pip3 install --upgrade pip pip3 install wheel pip3 install -r requirements.txt pip3 install flake8 From ffecc572226fd1caae89bcfc22c7943887d7cf39 Mon Sep 17 00:00:00 2001 From: Hawley Jean Date: Tue, 4 Jan 2022 19:08:06 -0400 Subject: [PATCH 07/13] adding to test.yml --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 963f73d..e30e5a8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -18,7 +18,7 @@ jobs: image: postgres:10.8 options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s container: - image: python:3.6 + image: python:3.8.12 env: POSTGRES_DB: django POSTGRES_USER: postgres @@ -60,7 +60,7 @@ jobs: python3 manage.py test apps - name: Run linters - uses: samuelmeuli/lint-action@v1 + uses: samuelmeuli/lint-action@v1 with: github_token: ${{ secrets.github_token }} flake8: true From 0434633f7fc5aa1dd7164048d252f33c00b93541 Mon Sep 17 00:00:00 2001 From: Hawley Jean Date: Tue, 4 Jan 2022 19:15:04 -0400 Subject: [PATCH 08/13] changing SSL mode --- project/settings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/project/settings.py b/project/settings.py index 1cfd7d0..bf95bfe 100644 --- a/project/settings.py +++ b/project/settings.py @@ -103,7 +103,10 @@ def get(variable, default=''): 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'django', # ___CHANGEME___ 'USER': 'postgres', - 'PASSWORD': 'postgres' + 'PASSWORD': 'postgres', + 'OPTIONS': { + 'sslmode': os.environ.get('DB_SSL', 'disable'), + } }, } From 706df8a7d3da58c00a44cdb5cdceb7eb3b426fa8 Mon Sep 17 00:00:00 2001 From: Hawley Jean Date: Tue, 4 Jan 2022 19:22:48 -0400 Subject: [PATCH 09/13] adding settings to project --- .github/workflows/test.yaml | 8 +++++--- project/settings.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e30e5a8..687efef 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -20,9 +20,11 @@ jobs: container: image: python:3.8.12 env: - POSTGRES_DB: django - POSTGRES_USER: postgres - POSTGRES_PASSWORD: "" + DB_HOST: postgres + DB_NAME: django + DB_USER: postgres + DB_PASSWORD: "" + DB_PORT: 5432 DJANGO_ENV: staging SECRET_KEY: test ALLOWED_HOSTS: "*" diff --git a/project/settings.py b/project/settings.py index bf95bfe..dcb90a4 100644 --- a/project/settings.py +++ b/project/settings.py @@ -101,9 +101,11 @@ def get(variable, default=''): DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'django', # ___CHANGEME___ - 'USER': 'postgres', - 'PASSWORD': 'postgres', + 'HOST': os.environ.get('DB_HOST', 'localhost'), + 'NAME': os.environ.get('DB_NAME', 'django'), # ___CHANGEME___ + 'USER': os.environ.get('DB_USER', 'postgres'), + 'PASSWORD': os.environ.get('DB_PASSWORD', 'postgres'), + 'PORT': os.environ.get('DB_PORT', 5432), 'OPTIONS': { 'sslmode': os.environ.get('DB_SSL', 'disable'), } From e1d9f39a4725b796876200c05e8457334f86928f Mon Sep 17 00:00:00 2001 From: Hawley Jean Date: Tue, 4 Jan 2022 19:30:00 -0400 Subject: [PATCH 10/13] adding ssl mode to allow --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 687efef..294251c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -25,6 +25,7 @@ jobs: DB_USER: postgres DB_PASSWORD: "" DB_PORT: 5432 + DB_SSL: "allow" DJANGO_ENV: staging SECRET_KEY: test ALLOWED_HOSTS: "*" From f6571b13374c56daf76aba2ba10acba529b4df45 Mon Sep 17 00:00:00 2001 From: Hawley Jean Date: Tue, 4 Jan 2022 19:36:23 -0400 Subject: [PATCH 11/13] removing ssl mode from heroku --- project/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project/settings.py b/project/settings.py index dcb90a4..681cfbc 100644 --- a/project/settings.py +++ b/project/settings.py @@ -261,3 +261,5 @@ def get(variable, default=''): SEND_MAIL = True if EMAIL_HOST_USER and EMAIL_HOST_PASSWORD else False django_heroku.settings(locals(), staticfiles=False) + +del DATABASES['default']['OPTIONS']['sslmode'] From e03fbd19397572b43ddb73360be6ea5e9d23a14e Mon Sep 17 00:00:00 2001 From: Hawley Jean Date: Tue, 4 Jan 2022 19:41:32 -0400 Subject: [PATCH 12/13] adding settings --- project/settings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/project/settings.py b/project/settings.py index 681cfbc..145a4a9 100644 --- a/project/settings.py +++ b/project/settings.py @@ -232,7 +232,9 @@ def get(variable, default=''): AWS_DEFAULT_ACL = 'public-read' AWS_QUERYSTRING_AUTH = False -if ENV in [STAGING, PRODUCTION]: +LOCAL_FILE_UPLOADS = os.environ.get('LOCAL_FILE_UPLOADS', 'True') == 'True' + +if ENV in [STAGING, PRODUCTION] or not LOCAL_FILE_UPLOADS: DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' From 3b137b6fe87fdeae6205c497150a92f941ee5e90 Mon Sep 17 00:00:00 2001 From: Hawley Jean Date: Tue, 4 Jan 2022 19:45:07 -0400 Subject: [PATCH 13/13] test environment changing --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 294251c..8317991 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,7 +26,7 @@ jobs: DB_PASSWORD: "" DB_PORT: 5432 DB_SSL: "allow" - DJANGO_ENV: staging + DJANGO_ENV: test SECRET_KEY: test ALLOWED_HOSTS: "*" WEB_URL: "http://localhost:3000"