Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/Users/mac/.local/share/virtualenvs/Intro-Django-NruQ2JbL/bin/python"
}
20 changes: 20 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
django = "*"
decouple = "*"
python-decouple = "*"
djangorestframework = "*"
django-cors-headers = "*"
gunicorn = "*"
psycopg2-binary = "*"
dj-database-url = "*"
whitenoise = "*"

[requires]
python_version = "3.7"
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn mysite.wsgi --log-file -
15 changes: 15 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
import os
import sys

if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.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)
Empty file added mysite/__init__.py
Empty file.
152 changes: 152 additions & 0 deletions mysite/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
"""
Django settings for mysite 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
import dj_database_url
# 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 = [
'localhost,127.0.0.1',
'heroku-django-app.herokuapp.com',
]


# Application definition

INSTALLED_APPS = [
'notes',
'rest_framework',
'rest_framework.authtoken',
'corsheaders',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

CORS_ORIGIN_ALLOW_ALL = True

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = 'mysite.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 = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases


# ****** SPRINT ******
DATABASES = {}

DATABASES['default'] = dj_database_url.config(default=config('DATABASE_URL'), conn_max_age=600)


# 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/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

from rest_framework.authentication import SessionAuthentication, BasicAuthentication, TokenAuthentication

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES' : [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly',
],
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
}
35 changes: 35 additions & 0 deletions mysite/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""mysite 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, re_path

from rest_framework import routers
from rest_framework.authtoken import views
from notes.api import PersonalNoteViewSet


# What does Router mean
# Client to Server, a Route direction
router = routers.DefaultRouter()
router.register('notes', PersonalNoteViewSet)

urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include(router.urls)),
re_path(r'^api-token-auth/', views.obtain_auth_token)
]


16 changes: 16 additions & 0 deletions mysite/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for mysite 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', 'mysite.settings')

application = get_wsgi_application()
Empty file added notes/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions notes/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.contrib import admin
from .models import Note, PersonalNote, SecretNote
# . means look in the current directory

class NoteAdmin(admin.ModelAdmin):
readonly_fields = ('date_created', 'last_editted')

# Register your models here.

admin.site.register(Note, NoteAdmin)
admin.site.register(PersonalNote, NoteAdmin)
admin.site.register(SecretNote)
36 changes: 36 additions & 0 deletions notes/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file sets control over what fields should be viewable on our API
#
#

from rest_framework import serializers, viewsets
from .models import PersonalNote, URLS

class PersonalNoteSerializer(serializers.HyperlinkedModelSerializer):
# Nested class, called Meta. Chooses which parts of the Meta we want to Access
# Is it always called Meta?
# What does Meta mean? - self referential(arts)/denoting change of position
class Meta:
model = PersonalNote
# Chooses Fields of Records
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
# Chooses which Records to return
queryset = PersonalNote.objects.all()

def get_queryset(self):
user = self.request.user

if user.is_anonymous:
return PersonalNote.objects.none()

else:
return personal.objects.filter(user=user)
5 changes: 5 additions & 0 deletions notes/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class NotesConfig(AppConfig):
name = 'notes'
23 changes: 23 additions & 0 deletions notes/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.1.4 on 2018-12-04 19:34

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)),
],
),
]
21 changes: 21 additions & 0 deletions notes/migrations/0002_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.1.4 on 2018-12-04 20:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('notes', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='URLS',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('url', models.URLField()),
],
),
]
25 changes: 25 additions & 0 deletions notes/migrations/0003_auto_20181204_2059.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.1.4 on 2018-12-04 20:59

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('notes', '0002_urls'),
]

operations = [
migrations.AddField(
model_name='note',
name='date_created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='note',
name='last_editted',
field=models.DateTimeField(auto_now=True),
),
]
Loading