From f5f47994f4adae371f9ab4b407e067285c2cb11d Mon Sep 17 00:00:00 2001 From: marshall Date: Sun, 2 Dec 2018 16:06:40 -0800 Subject: [PATCH 1/6] day 1 intro --- hw/.gitignore | 1 + hw/Pipfile | 13 +++ hw/Pipfile.lock | 43 ++++++++++ hw/djorg/__init__.py | 0 hw/djorg/settings.py | 123 ++++++++++++++++++++++++++++ hw/djorg/urls.py | 21 +++++ hw/djorg/wsgi.py | 16 ++++ hw/manage.py | 15 ++++ hw/notes/__init__.py | 0 hw/notes/admin.py | 3 + hw/notes/apps.py | 5 ++ hw/notes/migrations/0001_initial.py | 23 ++++++ hw/notes/migrations/__init__.py | 0 hw/notes/models.py | 7 ++ hw/notes/tests.py | 3 + hw/notes/views.py | 3 + 16 files changed, 276 insertions(+) create mode 100644 hw/.gitignore create mode 100644 hw/Pipfile create mode 100644 hw/Pipfile.lock create mode 100644 hw/djorg/__init__.py create mode 100644 hw/djorg/settings.py create mode 100644 hw/djorg/urls.py create mode 100644 hw/djorg/wsgi.py create mode 100755 hw/manage.py create mode 100644 hw/notes/__init__.py create mode 100644 hw/notes/admin.py create mode 100644 hw/notes/apps.py create mode 100644 hw/notes/migrations/0001_initial.py create mode 100644 hw/notes/migrations/__init__.py create mode 100644 hw/notes/models.py create mode 100644 hw/notes/tests.py create mode 100644 hw/notes/views.py diff --git a/hw/.gitignore b/hw/.gitignore new file mode 100644 index 000000000..2eea525d8 --- /dev/null +++ b/hw/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/hw/Pipfile b/hw/Pipfile new file mode 100644 index 000000000..172da92c2 --- /dev/null +++ b/hw/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +django = "*" +python-decouple = "*" + +[dev-packages] + +[requires] +python_version = "3.7" diff --git a/hw/Pipfile.lock b/hw/Pipfile.lock new file mode 100644 index 000000000..bbc0d0a13 --- /dev/null +++ b/hw/Pipfile.lock @@ -0,0 +1,43 @@ +{ + "_meta": { + "hash": { + "sha256": "0bb3b331760d823d01166b55e53cd9c02ded57f108f27a6e4dd739e3ed291a1f" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "django": { + "hashes": [ + "sha256:1ffab268ada3d5684c05ba7ce776eaeedef360712358d6a6b340ae9f16486916", + "sha256:dd46d87af4c1bf54f4c926c3cfa41dc2b5c15782f15e4329752ce65f5dad1c37" + ], + "index": "pypi", + "version": "==2.1.3" + }, + "python-decouple": { + "hashes": [ + "sha256:1317df14b43efee4337a4aa02914bf004f010cd56d6c4bd894e6474ec8c4fe2d" + ], + "index": "pypi", + "version": "==3.1" + }, + "pytz": { + "hashes": [ + "sha256:31cb35c89bd7d333cd32c5f278fca91b523b0834369e757f4c5641ea252236ca", + "sha256:8e0f8568c118d3077b46be7d654cc8167fa916092e28320cde048e54bfc9f1e6" + ], + "version": "==2018.7" + } + }, + "develop": {} +} diff --git a/hw/djorg/__init__.py b/hw/djorg/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/hw/djorg/settings.py b/hw/djorg/settings.py new file mode 100644 index 000000000..2a26aed28 --- /dev/null +++ b/hw/djorg/settings.py @@ -0,0 +1,123 @@ +""" +Django settings for djorg project. + +Generated by 'django-admin startproject' using Django 2.1.3. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/ref/settings/ +""" + +import os + +from decouple import config + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = config('SECRET_KEY') + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = config('DEBUG', cast=bool) + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'notes', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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 = 'djorg.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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 = 'djorg.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.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/2.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/2.1/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/hw/djorg/urls.py b/hw/djorg/urls.py new file mode 100644 index 000000000..f4f667215 --- /dev/null +++ b/hw/djorg/urls.py @@ -0,0 +1,21 @@ +"""djorg URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.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 + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/hw/djorg/wsgi.py b/hw/djorg/wsgi.py new file mode 100644 index 000000000..7bb827bb0 --- /dev/null +++ b/hw/djorg/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for djorg 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/2.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djorg.settings') + +application = get_wsgi_application() diff --git a/hw/manage.py b/hw/manage.py new file mode 100755 index 000000000..ae1e94bc6 --- /dev/null +++ b/hw/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djorg.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/hw/notes/__init__.py b/hw/notes/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/hw/notes/admin.py b/hw/notes/admin.py new file mode 100644 index 000000000..8c38f3f3d --- /dev/null +++ b/hw/notes/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/hw/notes/apps.py b/hw/notes/apps.py new file mode 100644 index 000000000..b6155aca3 --- /dev/null +++ b/hw/notes/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NotesConfig(AppConfig): + name = 'notes' diff --git a/hw/notes/migrations/0001_initial.py b/hw/notes/migrations/0001_initial.py new file mode 100644 index 000000000..fa88ceaf8 --- /dev/null +++ b/hw/notes/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.3 on 2018-12-02 21:43 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Note', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('title', models.CharField(max_length=200)), + ('content', models.TextField(blank=True)), + ], + ), + ] diff --git a/hw/notes/migrations/__init__.py b/hw/notes/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/hw/notes/models.py b/hw/notes/models.py new file mode 100644 index 000000000..9828a2808 --- /dev/null +++ b/hw/notes/models.py @@ -0,0 +1,7 @@ +from django.db import models +from uuid import uuid4 + +class Note(models.Model): + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) + title = models.CharField(max_length=200) + content = models.TextField(blank=True) diff --git a/hw/notes/tests.py b/hw/notes/tests.py new file mode 100644 index 000000000..7ce503c2d --- /dev/null +++ b/hw/notes/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/hw/notes/views.py b/hw/notes/views.py new file mode 100644 index 000000000..91ea44a21 --- /dev/null +++ b/hw/notes/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From ebe591c1c1aa0981c5d27a2c1f32774751ae56fc Mon Sep 17 00:00:00 2001 From: marshall Date: Sun, 2 Dec 2018 17:52:19 -0800 Subject: [PATCH 2/6] day 2 admin interface and sql --- hw/notes/admin.py | 8 ++++++ .../migrations/0002_auto_20181203_0047.py | 25 +++++++++++++++++++ hw/notes/migrations/0003_personalnote.py | 24 ++++++++++++++++++ hw/notes/models.py | 8 ++++++ 4 files changed, 65 insertions(+) create mode 100644 hw/notes/migrations/0002_auto_20181203_0047.py create mode 100644 hw/notes/migrations/0003_personalnote.py diff --git a/hw/notes/admin.py b/hw/notes/admin.py index 8c38f3f3d..1a375c586 100644 --- a/hw/notes/admin.py +++ b/hw/notes/admin.py @@ -1,3 +1,11 @@ from django.contrib import admin +from .models import Note, PersonalNote + +class NoteAdmin(admin.ModelAdmin): + readonly_fields=('created_at', 'last_modified') + + # Register your models here. +admin.site.register(Note, NoteAdmin) +admin.site.register(PersonalNote) diff --git a/hw/notes/migrations/0002_auto_20181203_0047.py b/hw/notes/migrations/0002_auto_20181203_0047.py new file mode 100644 index 000000000..61862cf38 --- /dev/null +++ b/hw/notes/migrations/0002_auto_20181203_0047.py @@ -0,0 +1,25 @@ +# Generated by Django 2.1.3 on 2018-12-03 00:47 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('notes', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='note', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='note', + name='last_modified', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/hw/notes/migrations/0003_personalnote.py b/hw/notes/migrations/0003_personalnote.py new file mode 100644 index 000000000..e3661a171 --- /dev/null +++ b/hw/notes/migrations/0003_personalnote.py @@ -0,0 +1,24 @@ +# Generated by Django 2.1.3 on 2018-12-03 01:28 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('notes', '0002_auto_20181203_0047'), + ] + + operations = [ + migrations.CreateModel( + name='PersonalNote', + fields=[ + ('note_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='notes.Note')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + bases=('notes.note',), + ), + ] diff --git a/hw/notes/models.py b/hw/notes/models.py index 9828a2808..72e936dd4 100644 --- a/hw/notes/models.py +++ b/hw/notes/models.py @@ -1,7 +1,15 @@ from django.db import models from uuid import uuid4 +from django.contrib.auth.models import User + class Note(models.Model): id = models.UUIDField(primary_key=True, default=uuid4, editable=False) title = models.CharField(max_length=200) content = models.TextField(blank=True) + + created_at = models.DateTimeField(auto_now_add=True) + last_modified = models.DateTimeField(auto_now=True) + +class PersonalNote(Note): + user = models.ForeignKey(User, on_delete=models.CASCADE) \ No newline at end of file From 18a3e993a0a5794931f39dc68440baff4f349a29 Mon Sep 17 00:00:00 2001 From: marshall Date: Mon, 3 Dec 2018 15:33:24 -0800 Subject: [PATCH 3/6] day 3 and 4 --- hw/Pipfile | 1 + hw/Pipfile.lock | 16 ++++++++++++---- hw/djorg/settings.py | 22 ++++++++++++++++++++++ hw/djorg/urls.py | 23 ++++++++++++++++++++++- hw/notes/api.py | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 hw/notes/api.py diff --git a/hw/Pipfile b/hw/Pipfile index 172da92c2..2d6b93ec0 100644 --- a/hw/Pipfile +++ b/hw/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [packages] django = "*" python-decouple = "*" +djangorestframework = "*" [dev-packages] diff --git a/hw/Pipfile.lock b/hw/Pipfile.lock index bbc0d0a13..74432aa3b 100644 --- a/hw/Pipfile.lock +++ b/hw/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "0bb3b331760d823d01166b55e53cd9c02ded57f108f27a6e4dd739e3ed291a1f" + "sha256": "f60c55d31de62ba3f850d6c16dc83ccc1a0d6fe44e337b58447a45133fdc5bb9" }, "pipfile-spec": 6, "requires": { @@ -18,11 +18,19 @@ "default": { "django": { "hashes": [ - "sha256:1ffab268ada3d5684c05ba7ce776eaeedef360712358d6a6b340ae9f16486916", - "sha256:dd46d87af4c1bf54f4c926c3cfa41dc2b5c15782f15e4329752ce65f5dad1c37" + "sha256:068d51054083d06ceb32ce02b7203f1854256047a0d58682677dd4f81bceabd7", + "sha256:55409a056b27e6d1246f19ede41c6c610e4cab549c005b62cbeefabc6433356b" ], "index": "pypi", - "version": "==2.1.3" + "version": "==2.1.4" + }, + "djangorestframework": { + "hashes": [ + "sha256:607865b0bb1598b153793892101d881466bd5a991de12bd6229abb18b1c86136", + "sha256:63f76cbe1e7d12b94c357d7e54401103b2e52aef0f7c1650d6c820ad708776e5" + ], + "index": "pypi", + "version": "==3.9.0" }, "python-decouple": { "hashes": [ diff --git a/hw/djorg/settings.py b/hw/djorg/settings.py index 2a26aed28..59b70c49b 100644 --- a/hw/djorg/settings.py +++ b/hw/djorg/settings.py @@ -34,6 +34,8 @@ INSTALLED_APPS = [ 'notes', + 'rest_framework', + 'rest_framework.authtoken', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -121,3 +123,23 @@ # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' + +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly', + ], + + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.TokenAuthentication' + ), +} + + + + + + + + diff --git a/hw/djorg/urls.py b/hw/djorg/urls.py index f4f667215..c8616f5bf 100644 --- a/hw/djorg/urls.py +++ b/hw/djorg/urls.py @@ -14,8 +14,29 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include + +from rest_framework import routers +from notes.api import PersonalNoteViewSet + +from rest_framework.authtoken import views + +router = routers.DefaultRouter() +router.register('notes', PersonalNoteViewSet) urlpatterns = [ path('admin/', admin.site.urls), + path('api/', include(router.urls)), + path('api-token-auth/', views.obtain_auth_token) ] + + + + + + + + + + + diff --git a/hw/notes/api.py b/hw/notes/api.py new file mode 100644 index 000000000..862d68996 --- /dev/null +++ b/hw/notes/api.py @@ -0,0 +1,37 @@ +from rest_framework import serializers, viewsets +from .models import PersonalNote + +class PersonalNoteSerializer(serializers.HyperlinkedModelSerializer): + + class Meta: + model = PersonalNote + fields = ('title', 'content') + + def create(self, validated_data): + # import pdb; pdb.set_trace() + user = self.context['request'].user + note = PersonalNote.objects.create(user=user, **validated_data) + return note + +class PersonalNoteViewSet(viewsets.ModelViewSet): + serializer_class = PersonalNoteSerializer + queryset = PersonalNote.objects.none() + + def get_queryset(self): + user = self.request.user + + if user.is_anonymous: + return PersonalNote.objects.none() + + else: + return PersonalNote.objects.filter(user=user) + + + + + + + + + + From 3f95575c6312d57d0b7497be7a9a810a429f5007 Mon Sep 17 00:00:00 2001 From: marshall Date: Tue, 4 Dec 2018 15:38:24 -0800 Subject: [PATCH 4/6] hw day 1-4 again as practice with a couple extra models --- .gitignore | 2 + hw/.gitignore | 3 +- practice/.gitignore | 1 + practice/Pipfile | 14 ++ practice/Pipfile.lock | 51 +++++++ practice/djorg2/__init__.py | 0 practice/djorg2/settings.py | 144 ++++++++++++++++++ practice/djorg2/urls.py | 31 ++++ practice/djorg2/wsgi.py | 16 ++ practice/manage.py | 15 ++ practice/notes2/__init__.py | 0 practice/notes2/admin.py | 18 +++ practice/notes2/api.py | 31 ++++ practice/notes2/apps.py | 5 + practice/notes2/migrations/0001_initial.py | 23 +++ practice/notes2/migrations/0002_articles.py | 22 +++ .../migrations/0003_auto_20181204_2148.py | 36 +++++ .../notes2/migrations/0004_personalnote.py | 24 +++ .../notes2/migrations/0005_personalarticle.py | 24 +++ practice/notes2/migrations/__init__.py | 0 practice/notes2/models.py | 44 ++++++ practice/notes2/tests.py | 3 + practice/notes2/views.py | 3 + 23 files changed, 509 insertions(+), 1 deletion(-) create mode 100644 practice/.gitignore create mode 100644 practice/Pipfile create mode 100644 practice/Pipfile.lock create mode 100644 practice/djorg2/__init__.py create mode 100644 practice/djorg2/settings.py create mode 100644 practice/djorg2/urls.py create mode 100644 practice/djorg2/wsgi.py create mode 100755 practice/manage.py create mode 100644 practice/notes2/__init__.py create mode 100644 practice/notes2/admin.py create mode 100644 practice/notes2/api.py create mode 100644 practice/notes2/apps.py create mode 100644 practice/notes2/migrations/0001_initial.py create mode 100644 practice/notes2/migrations/0002_articles.py create mode 100644 practice/notes2/migrations/0003_auto_20181204_2148.py create mode 100644 practice/notes2/migrations/0004_personalnote.py create mode 100644 practice/notes2/migrations/0005_personalarticle.py create mode 100644 practice/notes2/migrations/__init__.py create mode 100644 practice/notes2/models.py create mode 100644 practice/notes2/tests.py create mode 100644 practice/notes2/views.py diff --git a/.gitignore b/.gitignore index 894a44cc0..6a0812a4d 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,5 @@ venv.bak/ # mypy .mypy_cache/ + +.DS_Store diff --git a/hw/.gitignore b/hw/.gitignore index 2eea525d8..4c842e40a 100644 --- a/hw/.gitignore +++ b/hw/.gitignore @@ -1 +1,2 @@ -.env \ No newline at end of file +.env +.DS_Store \ No newline at end of file diff --git a/practice/.gitignore b/practice/.gitignore new file mode 100644 index 000000000..2eea525d8 --- /dev/null +++ b/practice/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/practice/Pipfile b/practice/Pipfile new file mode 100644 index 000000000..2d6b93ec0 --- /dev/null +++ b/practice/Pipfile @@ -0,0 +1,14 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +django = "*" +python-decouple = "*" +djangorestframework = "*" + +[dev-packages] + +[requires] +python_version = "3.7" diff --git a/practice/Pipfile.lock b/practice/Pipfile.lock new file mode 100644 index 000000000..74432aa3b --- /dev/null +++ b/practice/Pipfile.lock @@ -0,0 +1,51 @@ +{ + "_meta": { + "hash": { + "sha256": "f60c55d31de62ba3f850d6c16dc83ccc1a0d6fe44e337b58447a45133fdc5bb9" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "django": { + "hashes": [ + "sha256:068d51054083d06ceb32ce02b7203f1854256047a0d58682677dd4f81bceabd7", + "sha256:55409a056b27e6d1246f19ede41c6c610e4cab549c005b62cbeefabc6433356b" + ], + "index": "pypi", + "version": "==2.1.4" + }, + "djangorestframework": { + "hashes": [ + "sha256:607865b0bb1598b153793892101d881466bd5a991de12bd6229abb18b1c86136", + "sha256:63f76cbe1e7d12b94c357d7e54401103b2e52aef0f7c1650d6c820ad708776e5" + ], + "index": "pypi", + "version": "==3.9.0" + }, + "python-decouple": { + "hashes": [ + "sha256:1317df14b43efee4337a4aa02914bf004f010cd56d6c4bd894e6474ec8c4fe2d" + ], + "index": "pypi", + "version": "==3.1" + }, + "pytz": { + "hashes": [ + "sha256:31cb35c89bd7d333cd32c5f278fca91b523b0834369e757f4c5641ea252236ca", + "sha256:8e0f8568c118d3077b46be7d654cc8167fa916092e28320cde048e54bfc9f1e6" + ], + "version": "==2018.7" + } + }, + "develop": {} +} diff --git a/practice/djorg2/__init__.py b/practice/djorg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/practice/djorg2/settings.py b/practice/djorg2/settings.py new file mode 100644 index 000000000..13bf998ea --- /dev/null +++ b/practice/djorg2/settings.py @@ -0,0 +1,144 @@ +""" +Django settings for djorg2 project. + +Generated by 'django-admin startproject' using Django 2.1.4. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/ref/settings/ +""" + +import os + +from decouple import config + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = config('SECRET_KEY') + + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = config('DEBUG', cast=bool) + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'notes2', + 'rest_framework', + 'rest_framework.authtoken', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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 = 'djorg2.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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 = 'djorg2.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.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/2.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/2.1/howto/static-files/ + +STATIC_URL = '/static/' + +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly', + ], + + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.TokenAuthentication' + ), +} + + + + + + diff --git a/practice/djorg2/urls.py b/practice/djorg2/urls.py new file mode 100644 index 000000000..196b571ed --- /dev/null +++ b/practice/djorg2/urls.py @@ -0,0 +1,31 @@ +"""djorg2 URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.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 + +from rest_framework import routers +from notes2.api import PersonalNoteViewSet + +from rest_framework.authtoken import views + +router = routers.DefaultRouter() +router.register('notes', PersonalNoteViewSet) + +urlpatterns = [ + path('admin/', admin.site.urls), + path('api/', include(router.urls)), + path('api-token-auth/', views.obtain_auth_token), +] diff --git a/practice/djorg2/wsgi.py b/practice/djorg2/wsgi.py new file mode 100644 index 000000000..d6ccd558f --- /dev/null +++ b/practice/djorg2/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for djorg2 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/2.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djorg2.settings') + +application = get_wsgi_application() diff --git a/practice/manage.py b/practice/manage.py new file mode 100755 index 000000000..eb081018d --- /dev/null +++ b/practice/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djorg2.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/practice/notes2/__init__.py b/practice/notes2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/practice/notes2/admin.py b/practice/notes2/admin.py new file mode 100644 index 000000000..fa61d56b3 --- /dev/null +++ b/practice/notes2/admin.py @@ -0,0 +1,18 @@ +from django.contrib import admin + +from .models import Note, Articles, PersonalNote, PersonalArticle + + +class NoteAdmin(admin.ModelAdmin): + readonly_fields=('created_at', 'last_modified') + +class ArticleAdmin(admin.ModelAdmin): + readonly_fields=('created_at', 'last_modified') + + +# Register your models here. +admin.site.register(Note, NoteAdmin) +admin.site.register(PersonalNote) +admin.site.register(PersonalArticle) + +admin.site.register(Articles, ArticleAdmin) \ No newline at end of file diff --git a/practice/notes2/api.py b/practice/notes2/api.py new file mode 100644 index 000000000..8013fda0b --- /dev/null +++ b/practice/notes2/api.py @@ -0,0 +1,31 @@ +from rest_framework import serializers, viewsets +from .models import PersonalNote + +class PersonalNoteSerializer(serializers.HyperlinkedModelSerializer): + + class Meta: + model = PersonalNote + fields = ('title', 'content') + + def create(self, validated_data): + # import pdb; pdb.set_trace() + user = self.context['request'].user + note = PersonalNote.objects.create(user=user, **validated_data) + return note + +class PersonalNoteViewSet(viewsets.ModelViewSet): + serializer_class = PersonalNoteSerializer + queryset = PersonalNote.objects.all() + + def get_queryset(self): + user = self.request.user + + if user.is_anonymous: + return PersonalNote.objects.none() + + else: + return PersonalNote.objects.filter(user=user) + + + + diff --git a/practice/notes2/apps.py b/practice/notes2/apps.py new file mode 100644 index 000000000..e3d935b32 --- /dev/null +++ b/practice/notes2/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class Notes2Config(AppConfig): + name = 'notes2' diff --git a/practice/notes2/migrations/0001_initial.py b/practice/notes2/migrations/0001_initial.py new file mode 100644 index 000000000..2adec4d78 --- /dev/null +++ b/practice/notes2/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.4 on 2018-12-04 20:52 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Note', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('title', models.CharField(max_length=200)), + ('content', models.TextField(blank=True)), + ], + ), + ] diff --git a/practice/notes2/migrations/0002_articles.py b/practice/notes2/migrations/0002_articles.py new file mode 100644 index 000000000..a73ad8363 --- /dev/null +++ b/practice/notes2/migrations/0002_articles.py @@ -0,0 +1,22 @@ +# Generated by Django 2.1.4 on 2018-12-04 20:58 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('notes2', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Articles', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('title', models.CharField(max_length=200)), + ('content', models.TextField(blank=True)), + ], + ), + ] diff --git a/practice/notes2/migrations/0003_auto_20181204_2148.py b/practice/notes2/migrations/0003_auto_20181204_2148.py new file mode 100644 index 000000000..1cee29203 --- /dev/null +++ b/practice/notes2/migrations/0003_auto_20181204_2148.py @@ -0,0 +1,36 @@ +# Generated by Django 2.1.4 on 2018-12-04 21:48 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('notes2', '0002_articles'), + ] + + operations = [ + migrations.AddField( + model_name='articles', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='articles', + name='last_modified', + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name='note', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='note', + name='last_modified', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/practice/notes2/migrations/0004_personalnote.py b/practice/notes2/migrations/0004_personalnote.py new file mode 100644 index 000000000..ca067565d --- /dev/null +++ b/practice/notes2/migrations/0004_personalnote.py @@ -0,0 +1,24 @@ +# Generated by Django 2.1.4 on 2018-12-04 22:03 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('notes2', '0003_auto_20181204_2148'), + ] + + operations = [ + migrations.CreateModel( + name='PersonalNote', + fields=[ + ('note_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='notes2.Note')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + bases=('notes2.note',), + ), + ] diff --git a/practice/notes2/migrations/0005_personalarticle.py b/practice/notes2/migrations/0005_personalarticle.py new file mode 100644 index 000000000..8a4534e46 --- /dev/null +++ b/practice/notes2/migrations/0005_personalarticle.py @@ -0,0 +1,24 @@ +# Generated by Django 2.1.4 on 2018-12-04 22:07 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('notes2', '0004_personalnote'), + ] + + operations = [ + migrations.CreateModel( + name='PersonalArticle', + fields=[ + ('articles_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='notes2.Articles')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + bases=('notes2.articles',), + ), + ] diff --git a/practice/notes2/migrations/__init__.py b/practice/notes2/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/practice/notes2/models.py b/practice/notes2/models.py new file mode 100644 index 000000000..e6bf7309a --- /dev/null +++ b/practice/notes2/models.py @@ -0,0 +1,44 @@ +from django.db import models +from uuid import uuid4 + +from django.contrib.auth.models import User + +# Create your models here. +class Note(models.Model): + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) + title = models.CharField(max_length=200) + content = models.TextField(blank=True) + + created_at = models.DateTimeField(auto_now_add=True) + last_modified = models.DateTimeField(auto_now=True) + +class PersonalNote(Note): + user = models.ForeignKey(User, on_delete=models.CASCADE) + + + +class Articles(models.Model): + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) + title = models.CharField(max_length=200) + content = models.TextField(blank=True) + + created_at = models.DateTimeField(auto_now_add=True) + last_modified = models.DateTimeField(auto_now=True) + + +class PersonalArticle(Articles): + user = models.ForeignKey(User, on_delete=models.CASCADE) + + + + + + + + + + + + + + diff --git a/practice/notes2/tests.py b/practice/notes2/tests.py new file mode 100644 index 000000000..7ce503c2d --- /dev/null +++ b/practice/notes2/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/practice/notes2/views.py b/practice/notes2/views.py new file mode 100644 index 000000000..91ea44a21 --- /dev/null +++ b/practice/notes2/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From a4937d42588d7e894f06129e0749d91f673cec28 Mon Sep 17 00:00:00 2001 From: marshall Date: Wed, 5 Dec 2018 15:16:22 -0800 Subject: [PATCH 5/6] time for heroku --- practice/Pipfile | 4 +++ practice/Pipfile.lock | 62 ++++++++++++++++++++++++++++++++++++- practice/Procfile | 1 + practice/djorg2/settings.py | 19 +++++++++--- practice/requirements.txt | 8 +++++ 5 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 practice/Procfile create mode 100644 practice/requirements.txt diff --git a/practice/Pipfile b/practice/Pipfile index 2d6b93ec0..190afb452 100644 --- a/practice/Pipfile +++ b/practice/Pipfile @@ -7,6 +7,10 @@ name = "pypi" django = "*" python-decouple = "*" djangorestframework = "*" +gunicorn = "*" +"psycopg2-binary" = "*" +dj-database-url = "*" +whitenoise = "*" [dev-packages] diff --git a/practice/Pipfile.lock b/practice/Pipfile.lock index 74432aa3b..9389d5bec 100644 --- a/practice/Pipfile.lock +++ b/practice/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "f60c55d31de62ba3f850d6c16dc83ccc1a0d6fe44e337b58447a45133fdc5bb9" + "sha256": "8afcbb900798e3365aaa12966ff1c4a545134cbc204818e57f81d4504337595e" }, "pipfile-spec": 6, "requires": { @@ -16,6 +16,14 @@ ] }, "default": { + "dj-database-url": { + "hashes": [ + "sha256:4aeaeb1f573c74835b0686a2b46b85990571159ffc21aa57ecd4d1e1cb334163", + "sha256:851785365761ebe4994a921b433062309eb882fedd318e1b0fcecc607ed02da9" + ], + "index": "pypi", + "version": "==0.5.0" + }, "django": { "hashes": [ "sha256:068d51054083d06ceb32ce02b7203f1854256047a0d58682677dd4f81bceabd7", @@ -32,6 +40,50 @@ "index": "pypi", "version": "==3.9.0" }, + "gunicorn": { + "hashes": [ + "sha256:aa8e0b40b4157b36a5df5e599f45c9c76d6af43845ba3b3b0efe2c70473c2471", + "sha256:fa2662097c66f920f53f70621c6c58ca4a3c4d3434205e608e121b5b3b71f4f3" + ], + "index": "pypi", + "version": "==19.9.0" + }, + "psycopg2-binary": { + "hashes": [ + "sha256:036bcb198a7cc4ce0fe43344f8c2c9a8155aefa411633f426c8c6ed58a6c0426", + "sha256:1d770fcc02cdf628aebac7404d56b28a7e9ebec8cfc0e63260bd54d6edfa16d4", + "sha256:1fdc6f369dcf229de6c873522d54336af598b9470ccd5300e2f58ee506f5ca13", + "sha256:21f9ddc0ff6e07f7d7b6b484eb9da2c03bc9931dd13e36796b111d631f7135a3", + "sha256:247873cda726f7956f745a3e03158b00de79c4abea8776dc2f611d5ba368d72d", + "sha256:3aa31c42f29f1da6f4fd41433ad15052d5ff045f2214002e027a321f79d64e2c", + "sha256:475f694f87dbc619010b26de7d0fc575a4accf503f2200885cc21f526bffe2ad", + "sha256:4b5e332a24bf6e2fda1f51ca2a57ae1083352293a08eeea1fa1112dc7dd542d1", + "sha256:570d521660574aca40be7b4d532dfb6f156aad7b16b5ed62d1534f64f1ef72d8", + "sha256:59072de7def0690dd13112d2bdb453e20570a97297070f876fbbb7cbc1c26b05", + "sha256:5f0b658989e918ef187f8a08db0420528126f2c7da182a7b9f8bf7f85144d4e4", + "sha256:649199c84a966917d86cdc2046e03d536763576c0b2a756059ae0b3a9656bc20", + "sha256:6645fc9b4705ae8fbf1ef7674f416f89ae1559deec810f6dd15197dfa52893da", + "sha256:6872dd54d4e398d781efe8fe2e2d7eafe4450d61b5c4898aced7610109a6df75", + "sha256:6ce34fbc251fc0d691c8d131250ba6f42fd2b28ef28558d528ba8c558cb28804", + "sha256:73920d167a0a4d1006f5f3b9a3efce6f0e5e883a99599d38206d43f27697df00", + "sha256:8a671732b87ae423e34b51139628123bc0306c2cb85c226e71b28d3d57d7e42a", + "sha256:8d517e8fda2efebca27c2018e14c90ed7dc3f04d7098b3da2912e62a1a5585fe", + "sha256:9475a008eb7279e20d400c76471843c321b46acacc7ee3de0b47233a1e3fa2cf", + "sha256:96947b8cd7b3148fb0e6549fcb31258a736595d6f2a599f8cd450e9a80a14781", + "sha256:abf229f24daa93f67ac53e2e17c8798a71a01711eb9fcdd029abba8637164338", + "sha256:b1ab012f276df584beb74f81acb63905762c25803ece647016613c3d6ad4e432", + "sha256:b22b33f6f0071fe57cb4e9158f353c88d41e739a3ec0d76f7b704539e7076427", + "sha256:b3b2d53274858e50ad2ffdd6d97ce1d014e1e530f82ec8b307edd5d4c921badf", + "sha256:bab26a729befc7b9fab9ded1bba9c51b785188b79f8a2796ba03e7e734269e2e", + "sha256:daa1a593629aa49f506eddc9d23dc7f89b35693b90e1fbcd4480182d1203ea90", + "sha256:dd111280ce40e89fd17b19c1269fd1b74a30fce9d44a550840e86edb33924eb8", + "sha256:e0b86084f1e2e78c451994410de756deba206884d6bed68d5a3d7f39ff5fea1d", + "sha256:eb86520753560a7e89639500e2a254bb6f683342af598088cb72c73edcad21e6", + "sha256:ff18c5c40a38d41811c23e2480615425c97ea81fd7e9118b8b899c512d97c737" + ], + "index": "pypi", + "version": "==2.7.6.1" + }, "python-decouple": { "hashes": [ "sha256:1317df14b43efee4337a4aa02914bf004f010cd56d6c4bd894e6474ec8c4fe2d" @@ -45,6 +97,14 @@ "sha256:8e0f8568c118d3077b46be7d654cc8167fa916092e28320cde048e54bfc9f1e6" ], "version": "==2018.7" + }, + "whitenoise": { + "hashes": [ + "sha256:118ab3e5f815d380171b100b05b76de2a07612f422368a201a9ffdeefb2251c1", + "sha256:42133ddd5229eeb6a0c9899496bdbe56c292394bf8666da77deeb27454c0456a" + ], + "index": "pypi", + "version": "==4.1.2" } }, "develop": {} diff --git a/practice/Procfile b/practice/Procfile new file mode 100644 index 000000000..dd0c623da --- /dev/null +++ b/practice/Procfile @@ -0,0 +1 @@ +web: gunicorn djorg2.wsgi --log-file - \ No newline at end of file diff --git a/practice/djorg2/settings.py b/practice/djorg2/settings.py index 13bf998ea..beea6fa06 100644 --- a/practice/djorg2/settings.py +++ b/practice/djorg2/settings.py @@ -8,11 +8,13 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.1/ref/settings/ -""" +""" import os from decouple import config +import dj_database_url +import django_heroku # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -28,7 +30,13 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = config('DEBUG', cast=bool) -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['.herokuapp.com'] + +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' + +DATABASES = {} + +DATABASES['default'] = dj_database_url.config(default=config('DATABASE_URL'), conn_max_age=600) # Application definition @@ -46,6 +54,7 @@ ] MIDDLEWARE = [ + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -124,6 +133,7 @@ # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': [ @@ -138,7 +148,8 @@ } - - +# Activate Django-Heroku. +django_heroku.settings(locals()) +del DATABASES['default']['OPTIONS']['sslmode'] diff --git a/practice/requirements.txt b/practice/requirements.txt new file mode 100644 index 000000000..d46cf4a6b --- /dev/null +++ b/practice/requirements.txt @@ -0,0 +1,8 @@ +dj-database-url==0.5.0 +Django==2.1.4 +djangorestframework==3.9.0 +gunicorn==19.9.0 +psycopg2-binary==2.7.6.1 +python-decouple==3.1 +pytz==2018.7 +whitenoise==4.1.2 From d1c467f17e38faae584caed3cec8cd5239874636 Mon Sep 17 00:00:00 2001 From: marshall Date: Wed, 5 Dec 2018 15:47:10 -0800 Subject: [PATCH 6/6] fixing for heroku --- practice/djorg2/settings.py | 7 ++++++- practice/requirements.txt | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/practice/djorg2/settings.py b/practice/djorg2/settings.py index beea6fa06..a6604a0a9 100644 --- a/practice/djorg2/settings.py +++ b/practice/djorg2/settings.py @@ -38,11 +38,14 @@ DATABASES['default'] = dj_database_url.config(default=config('DATABASE_URL'), conn_max_age=600) +CORS_ORIGIN_ALLOW_ALL = True + # Application definition INSTALLED_APPS = [ 'notes2', + 'corsheaders', 'rest_framework', 'rest_framework.authtoken', 'django.contrib.admin', @@ -54,8 +57,10 @@ ] MIDDLEWARE = [ - 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', diff --git a/practice/requirements.txt b/practice/requirements.txt index d46cf4a6b..92ebb3fdf 100644 --- a/practice/requirements.txt +++ b/practice/requirements.txt @@ -1,7 +1,10 @@ dj-database-url==0.5.0 Django==2.1.4 +django-cors-headers==2.4.0 +django-heroku==0.3.1 djangorestframework==3.9.0 gunicorn==19.9.0 +psycopg2==2.7.6.1 psycopg2-binary==2.7.6.1 python-decouple==3.1 pytz==2018.7