From ab68716e6840bb205c1e866ad58ea7b518185130 Mon Sep 17 00:00:00 2001 From: Alexander Hosking Date: Fri, 19 Nov 2021 21:03:35 -0500 Subject: [PATCH] First Beta! --- .gitignore | 5 + README.md | 9 +- api-workspace.code-workspace | 8 + api/api/.env.sample | 7 + api/api/__init__.py | 0 api/api/asgi.py | 16 ++ api/api/settings.py | 137 ++++++++++++++++++ api/api/urls.py | 29 ++++ api/api/views.py | 4 + api/api/wsgi.py | 16 ++ api/bills/__init__.py | 0 api/bills/admin.py | 5 + api/bills/apps.py | 6 + api/bills/migrations/0001_initial.py | 28 ++++ .../migrations/0002_auto_20211119_2041.py | 23 +++ .../migrations/0003_alter_bill_paid_date.py | 18 +++ api/bills/migrations/__init__.py | 0 api/bills/models.py | 18 +++ api/bills/tests.py | 3 + api/bills/urls.py | 12 ++ api/bills/views.py | 6 + api/manage.py | 22 +++ requirements.txt | 8 + 23 files changed, 379 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 api-workspace.code-workspace create mode 100644 api/api/.env.sample create mode 100644 api/api/__init__.py create mode 100644 api/api/asgi.py create mode 100644 api/api/settings.py create mode 100644 api/api/urls.py create mode 100644 api/api/views.py create mode 100644 api/api/wsgi.py create mode 100644 api/bills/__init__.py create mode 100644 api/bills/admin.py create mode 100644 api/bills/apps.py create mode 100644 api/bills/migrations/0001_initial.py create mode 100644 api/bills/migrations/0002_auto_20211119_2041.py create mode 100644 api/bills/migrations/0003_alter_bill_paid_date.py create mode 100644 api/bills/migrations/__init__.py create mode 100644 api/bills/models.py create mode 100644 api/bills/tests.py create mode 100644 api/bills/urls.py create mode 100644 api/bills/views.py create mode 100644 api/manage.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a0d0b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.pyc +.env + +## No Databases +*.sqlite* \ No newline at end of file diff --git a/README.md b/README.md index 9758e0e..b9d47ed 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ # api -The AHosking.com API \ No newline at end of file +The AHosking.com API + +## Getting Started + +### +1. Activate environment +`.\.env\Scripts\activate` +1. \ No newline at end of file diff --git a/api-workspace.code-workspace b/api-workspace.code-workspace new file mode 100644 index 0000000..876a149 --- /dev/null +++ b/api-workspace.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/api/api/.env.sample b/api/api/.env.sample new file mode 100644 index 0000000..3bd1285 --- /dev/null +++ b/api/api/.env.sample @@ -0,0 +1,7 @@ +SECRET_KEY=django-insecure-7uajhmbt^@)mklk1ur=slkmn3*+9_cnfhww6wi8jg*h@qqd%6u +DEBUG=True +DATABASE_NAME=database +DATABASE_USER=user +DATABASE_PASSWORD=password +DATABASE_HOST=localhost +DATABASE_PORT=5432 \ No newline at end of file diff --git a/api/api/__init__.py b/api/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/api/asgi.py b/api/api/asgi.py new file mode 100644 index 0000000..4214d20 --- /dev/null +++ b/api/api/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for api 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.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings') + +application = get_asgi_application() diff --git a/api/api/settings.py b/api/api/settings.py new file mode 100644 index 0000000..a3328d4 --- /dev/null +++ b/api/api/settings.py @@ -0,0 +1,137 @@ +""" +Django settings for api project. + +Generated by 'django-admin startproject' using Django 3.2.9. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path +import environ + +env = environ.Env() +environ.Env.read_env() + +# 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.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = env("SECRET_KEY", default='django-insecure-7uajhmbt^@)mklk1ur=slkmn3*+9_cnfhww6wi8jg*h@qqd%6u') + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = env("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', + 'rest_framework', + 'rest_framework.authtoken', + 'django_filters', + 'bills.apps.BillsConfig', +] + +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 = 'api.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 = 'api.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': env("DATABASE_NAME"), + 'USER': env("DATABASE_USER"), + 'PASSWORD': env("DATABASE_PASSWORD"), + 'HOST': env("DATABASE_HOST"), + 'PORT': env("DATABASE_PORT"), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/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.2/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.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/api/api/urls.py b/api/api/urls.py new file mode 100644 index 0000000..5d1b74e --- /dev/null +++ b/api/api/urls.py @@ -0,0 +1,29 @@ +"""api URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/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.conf.urls import url +from django.contrib import admin +from django.views.generic import TemplateView +from django.urls import include, path + +from . import views + +urlpatterns = [ + # url(r'^$', view=TemplateView.as_view(template_name='bills/home.html')), + # url(r'^$', view=TemplateView.as_view(template_name='main_api/home.html')), + path('', views.index, name='index'), + path('bills/', include('bills.urls')), + path('admin/', admin.site.urls), +] diff --git a/api/api/views.py b/api/api/views.py new file mode 100644 index 0000000..d8717e3 --- /dev/null +++ b/api/api/views.py @@ -0,0 +1,4 @@ +from django.http import HttpResponse + +def index(request): + return HttpResponse("Hi there! This is the API index") \ No newline at end of file diff --git a/api/api/wsgi.py b/api/api/wsgi.py new file mode 100644 index 0000000..d115c14 --- /dev/null +++ b/api/api/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for api 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.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings') + +application = get_wsgi_application() diff --git a/api/bills/__init__.py b/api/bills/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/bills/admin.py b/api/bills/admin.py new file mode 100644 index 0000000..cbf1328 --- /dev/null +++ b/api/bills/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin + +from .models import Bill + +admin.site.register(Bill) \ No newline at end of file diff --git a/api/bills/apps.py b/api/bills/apps.py new file mode 100644 index 0000000..f768261 --- /dev/null +++ b/api/bills/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class BillsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'bills' diff --git a/api/bills/migrations/0001_initial.py b/api/bills/migrations/0001_initial.py new file mode 100644 index 0000000..9c978fd --- /dev/null +++ b/api/bills/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.9 on 2021-11-09 13:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Bill', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=64)), + ('type', models.CharField(max_length=64)), + ('due', models.DateTimeField(verbose_name='due_date')), + ('amount', models.FloatField(default='00.00')), + ('is_paid', models.BooleanField(default=False)), + ('paid_date', models.DateTimeField(verbose_name='paid_date')), + ('is_overdue', models.BooleanField(default=False)), + ('is_missed', models.BooleanField(default=False)), + ], + ), + ] diff --git a/api/bills/migrations/0002_auto_20211119_2041.py b/api/bills/migrations/0002_auto_20211119_2041.py new file mode 100644 index 0000000..06ee776 --- /dev/null +++ b/api/bills/migrations/0002_auto_20211119_2041.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.9 on 2021-11-20 01:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bills', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='bill', + name='due', + field=models.DateField(verbose_name='due_date'), + ), + migrations.AlterField( + model_name='bill', + name='paid_date', + field=models.DateField(blank=True, verbose_name='paid_date'), + ), + ] diff --git a/api/bills/migrations/0003_alter_bill_paid_date.py b/api/bills/migrations/0003_alter_bill_paid_date.py new file mode 100644 index 0000000..9321151 --- /dev/null +++ b/api/bills/migrations/0003_alter_bill_paid_date.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.9 on 2021-11-20 01:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bills', '0002_auto_20211119_2041'), + ] + + operations = [ + migrations.AlterField( + model_name='bill', + name='paid_date', + field=models.DateField(blank=True, null=True, verbose_name='paid_date'), + ), + ] diff --git a/api/bills/migrations/__init__.py b/api/bills/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/bills/models.py b/api/bills/models.py new file mode 100644 index 0000000..170c79d --- /dev/null +++ b/api/bills/models.py @@ -0,0 +1,18 @@ +from django.db import models + +# Create your models here. +class Bill(models.Model): + name = models.CharField(max_length=64) + type = models.CharField(max_length=64) + due = models.DateField('due_date') + amount = models.FloatField(default='00.00') + is_paid = models.BooleanField(default=False) + paid_date = models.DateField('paid_date',null=True, blank=True) + is_overdue = models.BooleanField(default=False) + is_missed = models.BooleanField(default=False) + + def overdue(self): + return self.is_overdue + + def __str__(self): + return ("%s - %s" % (self.name, self.due)) diff --git a/api/bills/tests.py b/api/bills/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/api/bills/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/api/bills/urls.py b/api/bills/urls.py new file mode 100644 index 0000000..a36f0ff --- /dev/null +++ b/api/bills/urls.py @@ -0,0 +1,12 @@ +from django.conf.urls import url +from django.contrib import admin +from django.views.generic import TemplateView +from django.urls import include, path + +from . import views + +urlpatterns = [ + + path('', views.index, name='index'), + path('admin/', admin.site.urls), +] diff --git a/api/bills/views.py b/api/bills/views.py new file mode 100644 index 0000000..6e05d5c --- /dev/null +++ b/api/bills/views.py @@ -0,0 +1,6 @@ +from django.shortcuts import render +from django.http import HttpResponse + +def index(request): + return HttpResponse("Let there be bills!") +# Create your views here. diff --git a/api/manage.py b/api/manage.py new file mode 100644 index 0000000..8c45ccf --- /dev/null +++ b/api/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.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) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..655a1cc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +asgiref==3.4.1 +Django==3.2.9 +django-environ==0.8.1 +django-filter==21.1 +djangorestframework==3.12.4 +psycopg2==2.9.1 +pytz==2021.3 +sqlparse==0.4.2