diff --git a/Code/will/django_labs/django_redo/.gitignore b/Code/will/django_labs/django_redo/.gitignore new file mode 100644 index 00000000..5e49e1af Binary files /dev/null and b/Code/will/django_labs/django_redo/.gitignore differ diff --git a/Code/will/django_labs/django_redo/django_redo/__init__.py b/Code/will/django_labs/django_redo/django_redo/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/django_redo/django_redo/asgi.py b/Code/will/django_labs/django_redo/django_redo/asgi.py new file mode 100644 index 00000000..a3c77a4c --- /dev/null +++ b/Code/will/django_labs/django_redo/django_redo/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for django_redo 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_redo.settings') + +application = get_asgi_application() diff --git a/Code/will/django_labs/django_redo/django_redo/settings.py b/Code/will/django_labs/django_redo/django_redo/settings.py new file mode 100644 index 00000000..ca28045f --- /dev/null +++ b/Code/will/django_labs/django_redo/django_redo/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for django_redo project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +from decouple import config +from pathlib import Path + +# 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/4.0/howto/deployment/checklist/ + +SECRET_KEY = config("SECRET_KEY") + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # project apps + 'redoapp' +] + +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 = 'django_redo.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 = 'django_redo.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Chicago' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/will/django_labs/django_redo/django_redo/urls.py b/Code/will/django_labs/django_redo/django_redo/urls.py new file mode 100644 index 00000000..5e865be0 --- /dev/null +++ b/Code/will/django_labs/django_redo/django_redo/urls.py @@ -0,0 +1,22 @@ +"""django_redo URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('unitcon/', include('redoapp.urls')) +] diff --git a/Code/will/django_labs/django_redo/django_redo/wsgi.py b/Code/will/django_labs/django_redo/django_redo/wsgi.py new file mode 100644 index 00000000..7ff1f511 --- /dev/null +++ b/Code/will/django_labs/django_redo/django_redo/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for django_redo 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_redo.settings') + +application = get_wsgi_application() diff --git a/Code/will/django_labs/django_redo/manage.py b/Code/will/django_labs/django_redo/manage.py new file mode 100644 index 00000000..08e5c2c5 --- /dev/null +++ b/Code/will/django_labs/django_redo/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', 'django_redo.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/Code/will/django_labs/django_redo/redoapp/__init__.py b/Code/will/django_labs/django_redo/redoapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/django_redo/redoapp/admin.py b/Code/will/django_labs/django_redo/redoapp/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/Code/will/django_labs/django_redo/redoapp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/Code/will/django_labs/django_redo/redoapp/apps.py b/Code/will/django_labs/django_redo/redoapp/apps.py new file mode 100644 index 00000000..4915506e --- /dev/null +++ b/Code/will/django_labs/django_redo/redoapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class RedoappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'redoapp' diff --git a/Code/will/django_labs/django_redo/redoapp/migrations/__init__.py b/Code/will/django_labs/django_redo/redoapp/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/django_redo/redoapp/models.py b/Code/will/django_labs/django_redo/redoapp/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/Code/will/django_labs/django_redo/redoapp/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/Code/will/django_labs/django_redo/redoapp/templates/redoapp/result.html b/Code/will/django_labs/django_redo/redoapp/templates/redoapp/result.html new file mode 100644 index 00000000..3d1ca2a8 --- /dev/null +++ b/Code/will/django_labs/django_redo/redoapp/templates/redoapp/result.html @@ -0,0 +1,16 @@ + + + + + + + Unit Conversion Results + + +

Results:

+ + +

{{distance_to_convert}} {{units_to_convert}} is equal to {{converted_units}} {{meters_to_units}}

+ + + \ No newline at end of file diff --git a/Code/will/django_labs/django_redo/redoapp/templates/redoapp/unitcon.html b/Code/will/django_labs/django_redo/redoapp/templates/redoapp/unitcon.html new file mode 100644 index 00000000..413dcd3a --- /dev/null +++ b/Code/will/django_labs/django_redo/redoapp/templates/redoapp/unitcon.html @@ -0,0 +1,28 @@ + + + + + + + Unit Converter + + +

Unit Converting

+

This converter can convert feet, miles, meters, kilometers, yards, and inches.

+ + +
+ {% csrf_token %} + + + + + + + + + + +
+ + \ No newline at end of file diff --git a/Code/will/django_labs/django_redo/redoapp/tests.py b/Code/will/django_labs/django_redo/redoapp/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/django_labs/django_redo/redoapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/django_labs/django_redo/redoapp/urls.py b/Code/will/django_labs/django_redo/redoapp/urls.py new file mode 100644 index 00000000..28028e0d --- /dev/null +++ b/Code/will/django_labs/django_redo/redoapp/urls.py @@ -0,0 +1,10 @@ +from django.urls import path +from . import views + +app_name = 'redoapp' +urlpatterns = [ + path('', views.unitcon, name='unitcon'), + + path('result/', views.result, name='result') + +] diff --git a/Code/will/django_labs/django_redo/redoapp/views.py b/Code/will/django_labs/django_redo/redoapp/views.py new file mode 100644 index 00000000..3915b4a7 --- /dev/null +++ b/Code/will/django_labs/django_redo/redoapp/views.py @@ -0,0 +1,33 @@ +from http.client import HTTPResponse +from django.shortcuts import render +from django.http import HttpResponse + +# Create your views here. + + +def unitcon(request): + return render(request, 'redoapp/unitcon.html') + + +def result(request): + conversion = request.POST + + units_to_convert = conversion['convert'] + distance_to_convert = conversion['amount'] + meters_to_units = conversion['converted'] + distance_to_convert = int(distance_to_convert) + + distances = {'feet': 0.3048, 'miles': 1609.34, 'meters': 1.0, + 'kilometers': 1000, 'yards': 0.9144, 'inches': 0.0254} + # convert the meters into the desired second unit and print results + units_to_meters = distance_to_convert * distances.get(units_to_convert) + converted_units = units_to_meters / distances.get(meters_to_units) + converted_units = round(converted_units, 3) + + context = {'converted_units': converted_units, + 'meters_to_units': meters_to_units, + 'units_to_convert': units_to_convert, + 'distance_to_convert': distance_to_convert + } + + return render(request, 'redoapp/result.html', context) diff --git a/Code/will/django_labs/grocery_list_proj/.gitignore b/Code/will/django_labs/grocery_list_proj/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Code/will/django_labs/grocery_list_proj/grocery_list_proj/__init__.py b/Code/will/django_labs/grocery_list_proj/grocery_list_proj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/grocery_list_proj/grocery_list_proj/asgi.py b/Code/will/django_labs/grocery_list_proj/grocery_list_proj/asgi.py new file mode 100644 index 00000000..2b31c0c2 --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/grocery_list_proj/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for grocery_list_proj 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'grocery_list_proj.settings') + +application = get_asgi_application() diff --git a/Code/will/django_labs/grocery_list_proj/grocery_list_proj/settings.py b/Code/will/django_labs/grocery_list_proj/grocery_list_proj/settings.py new file mode 100644 index 00000000..d48ff619 --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/grocery_list_proj/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for grocery_list_proj project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +from decouple import config +from pathlib import Path + +# 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/4.0/howto/deployment/checklist/ + + +SECRET_KEY = config("SECRET_KEY") + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # Project apps + 'listapp' +] + +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 = 'grocery_list_proj.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 = 'grocery_list_proj.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Chicago' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/will/django_labs/grocery_list_proj/grocery_list_proj/urls.py b/Code/will/django_labs/grocery_list_proj/grocery_list_proj/urls.py new file mode 100644 index 00000000..719234e9 --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/grocery_list_proj/urls.py @@ -0,0 +1,22 @@ +"""grocery_list_proj URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('index/', include('listapp.urls')) +] diff --git a/Code/will/django_labs/grocery_list_proj/grocery_list_proj/wsgi.py b/Code/will/django_labs/grocery_list_proj/grocery_list_proj/wsgi.py new file mode 100644 index 00000000..b291aef5 --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/grocery_list_proj/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for grocery_list_proj 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'grocery_list_proj.settings') + +application = get_wsgi_application() diff --git a/Code/will/django_labs/grocery_list_proj/listapp/__init__.py b/Code/will/django_labs/grocery_list_proj/listapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/grocery_list_proj/listapp/admin.py b/Code/will/django_labs/grocery_list_proj/listapp/admin.py new file mode 100644 index 00000000..95b665dd --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/listapp/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import * + +# Register your models here. +admin.site.register(Department) +admin.site.register(GroceryItem) diff --git a/Code/will/django_labs/grocery_list_proj/listapp/apps.py b/Code/will/django_labs/grocery_list_proj/listapp/apps.py new file mode 100644 index 00000000..c7bcf818 --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/listapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ListappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'listapp' diff --git a/Code/will/django_labs/grocery_list_proj/listapp/migrations/0001_initial.py b/Code/will/django_labs/grocery_list_proj/listapp/migrations/0001_initial.py new file mode 100644 index 00000000..1933114b --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/listapp/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 4.0.3 on 2022-04-13 01:31 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Department', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=20)), + ], + ), + migrations.CreateModel( + name='GroceryItem', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('item', models.CharField(max_length=40)), + ('completed', models.BooleanField(default=False)), + ('department', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='items', to='listapp.department')), + ], + ), + ] diff --git a/Code/will/django_labs/grocery_list_proj/listapp/migrations/__init__.py b/Code/will/django_labs/grocery_list_proj/listapp/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/grocery_list_proj/listapp/models.py b/Code/will/django_labs/grocery_list_proj/listapp/models.py new file mode 100644 index 00000000..c259a2ff --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/listapp/models.py @@ -0,0 +1,20 @@ +from django.db import models + +# Create your models here. + + +class Department(models.Model): + name = models.CharField(max_length=20) + + def __str__(self): + return f'{self.name}' + + +class GroceryItem(models.Model): + item = models.CharField(max_length=40) + completed = models.BooleanField(default=False) + department = models.ForeignKey( + Department, on_delete=models.CASCADE, related_name='items', null=True, blank=True) + + def __str__(self): + return f'{self.item} -- {self.completed} ' # item -- completion status diff --git a/Code/will/django_labs/grocery_list_proj/listapp/templates/listapp/index.html b/Code/will/django_labs/grocery_list_proj/listapp/templates/listapp/index.html new file mode 100644 index 00000000..b181739b --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/listapp/templates/listapp/index.html @@ -0,0 +1,45 @@ + + + + + + + Grocery + + +

My Grocery List

+
+ {% csrf_token %} + + + + + {% for department in departments %} +
+

{{department.name}}

+ +
+ {% endfor %} +
+ + + \ No newline at end of file diff --git a/Code/will/django_labs/grocery_list_proj/listapp/tests.py b/Code/will/django_labs/grocery_list_proj/listapp/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/listapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/django_labs/grocery_list_proj/listapp/urls.py b/Code/will/django_labs/grocery_list_proj/listapp/urls.py new file mode 100644 index 00000000..888a5dfd --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/listapp/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from . import views + +app_name = 'listapp' + +urlpatterns = [ + path('', views.index, name='index'), + path('add_items', views.add_item, name='add'), + path('buy//', views.buy_item, name='buy'), + path('delete/', views.delete_item, name='delete') +] diff --git a/Code/will/django_labs/grocery_list_proj/listapp/views.py b/Code/will/django_labs/grocery_list_proj/listapp/views.py new file mode 100644 index 00000000..2b0be30b --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/listapp/views.py @@ -0,0 +1,41 @@ +from django.shortcuts import render +from . import models +from django.http import HttpResponseRedirect +from django.urls import reverse +# Create your views here. + + +def index(request): + grocery_list = models.GroceryItem.objects.all().order_by('department') + departments = models.Department.objects.all().order_by('name') + + return render(request, 'listapp/index.html', { + 'grocery_list': grocery_list, + 'departments': departments + }) + + +def add_item(request): + item_text = request.POST['item'] + department_id = request.POST['department'] + new_item = models.GroceryItem() + new_item.item = item_text + if department_id: + department = models.Department.objects.get(id=department_id) + new_item.department = department + new_item.save() + + return HttpResponseRedirect(reverse('listapp:index')) + + +def buy_item(request, item_id): + grocery_item = models.GroceryItem.objects.get(id=item_id) + grocery_item.completed = not grocery_item.completed + grocery_item.save() + return HttpResponseRedirect(reverse('listapp:index')) + + +def delete_item(request, item_id): + grocery_item = models.GroceryItem.objects.get(id=item_id) + grocery_item.delete() + return HttpResponseRedirect(reverse('listapp:index')) diff --git a/Code/will/django_labs/grocery_list_proj/manage.py b/Code/will/django_labs/grocery_list_proj/manage.py new file mode 100644 index 00000000..91f82040 --- /dev/null +++ b/Code/will/django_labs/grocery_list_proj/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', 'grocery_list_proj.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/Code/will/django_labs/grocery_list_proj/requirements.txt b/Code/will/django_labs/grocery_list_proj/requirements.txt new file mode 100644 index 00000000..07091272 Binary files /dev/null and b/Code/will/django_labs/grocery_list_proj/requirements.txt differ diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/.gitignore b/Code/will/django_labs/practice_labs/is_it_xmas/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/__init__.py b/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/asgi.py b/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/asgi.py new file mode 100644 index 00000000..61ac89b1 --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for is_it_xmas 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'is_it_xmas.settings') + +application = get_asgi_application() diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/settings.py b/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/settings.py new file mode 100644 index 00000000..ccb31967 --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for is_it_xmas project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +from decouple import config +from pathlib import Path + +# 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/4.0/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 = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # Project Apps + 'xmas_app' +] + +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 = 'is_it_xmas.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 = 'is_it_xmas.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Chicago' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/urls.py b/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/urls.py new file mode 100644 index 00000000..804d96b8 --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/urls.py @@ -0,0 +1,22 @@ +"""is_it_xmas URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('index/', include('xmas_app.urls')) +] diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/wsgi.py b/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/wsgi.py new file mode 100644 index 00000000..ab4eaa69 --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/is_it_xmas/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for is_it_xmas 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'is_it_xmas.settings') + +application = get_wsgi_application() diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/manage.py b/Code/will/django_labs/practice_labs/is_it_xmas/manage.py new file mode 100644 index 00000000..7a87969e --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/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', 'is_it_xmas.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/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/__init__.py b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/admin.py b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/apps.py b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/apps.py new file mode 100644 index 00000000..699d5350 --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class XmasAppConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'xmas_app' diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/migrations/__init__.py b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/models.py b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/templates/xmas_app/index.html b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/templates/xmas_app/index.html new file mode 100644 index 00000000..56efbdba --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/templates/xmas_app/index.html @@ -0,0 +1,12 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/tests.py b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/urls.py b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/urls.py new file mode 100644 index 00000000..98ca879c --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from . import views + +app_name = 'xmas_app' +urlpatterns = [ + path('', views.index, name='index') + +] diff --git a/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/views.py b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/views.py new file mode 100644 index 00000000..13389d86 --- /dev/null +++ b/Code/will/django_labs/practice_labs/is_it_xmas/xmas_app/views.py @@ -0,0 +1,9 @@ +from http.client import HTTPResponse +from django.shortcuts import render +from django.http import HttpResponse + +# Create your views here. + + +def index(request): + return HttpResponse('hello world') diff --git a/Code/will/django_labs/practice_labs/mysite/.gitignore b/Code/will/django_labs/practice_labs/mysite/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/mysite/manage.py b/Code/will/django_labs/practice_labs/mysite/manage.py new file mode 100644 index 00000000..a7da6671 --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/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', '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) + + +if __name__ == '__main__': + main() diff --git a/Code/will/django_labs/practice_labs/mysite/mysite/__init__.py b/Code/will/django_labs/practice_labs/mysite/mysite/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/mysite/mysite/asgi.py b/Code/will/django_labs/practice_labs/mysite/mysite/asgi.py new file mode 100644 index 00000000..674a5a5a --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/mysite/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for mysite 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') + +application = get_asgi_application() diff --git a/Code/will/django_labs/practice_labs/mysite/mysite/settings.py b/Code/will/django_labs/practice_labs/mysite/mysite/settings.py new file mode 100644 index 00000000..c6043e4c --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/mysite/settings.py @@ -0,0 +1,123 @@ +""" +Django settings for mysite project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +from decouple import config +from pathlib import Path + +# 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/4.0/howto/deployment/checklist/ + +SECRET_KEY = config("SECRET_KEY") +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'polls.apps.PollsConfig', + '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 = '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/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Chicago' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/will/django_labs/practice_labs/mysite/mysite/urls.py b/Code/will/django_labs/practice_labs/mysite/mysite/urls.py new file mode 100644 index 00000000..d203d9fc --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/mysite/urls.py @@ -0,0 +1,22 @@ +"""mysite URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('polls/', include('polls.urls')) +] diff --git a/Code/will/django_labs/practice_labs/mysite/mysite/wsgi.py b/Code/will/django_labs/practice_labs/mysite/mysite/wsgi.py new file mode 100644 index 00000000..48d46fe4 --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/mysite/wsgi.py @@ -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/4.0/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() diff --git a/Code/will/django_labs/practice_labs/mysite/polls/__init__.py b/Code/will/django_labs/practice_labs/mysite/polls/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/mysite/polls/admin.py b/Code/will/django_labs/practice_labs/mysite/polls/admin.py new file mode 100644 index 00000000..93a4a5ea --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/polls/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import Question + +# Register your models here. +admin.site.register(Question) diff --git a/Code/will/django_labs/practice_labs/mysite/polls/apps.py b/Code/will/django_labs/practice_labs/mysite/polls/apps.py new file mode 100644 index 00000000..5a5f94ca --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/polls/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class PollsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'polls' diff --git a/Code/will/django_labs/practice_labs/mysite/polls/migrations/0001_initial.py b/Code/will/django_labs/practice_labs/mysite/polls/migrations/0001_initial.py new file mode 100644 index 00000000..93d4bd00 --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/polls/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 4.0.3 on 2022-03-29 03:57 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Question', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('question_text', models.CharField(max_length=200)), + ('pub_date', models.DateTimeField(verbose_name='date published')), + ], + ), + migrations.CreateModel( + name='Choice', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('choice_text', models.CharField(max_length=200)), + ('votes', models.IntegerField(default=0)), + ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.question')), + ], + ), + ] diff --git a/Code/will/django_labs/practice_labs/mysite/polls/migrations/__init__.py b/Code/will/django_labs/practice_labs/mysite/polls/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/mysite/polls/models.py b/Code/will/django_labs/practice_labs/mysite/polls/models.py new file mode 100644 index 00000000..64074017 --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/polls/models.py @@ -0,0 +1,24 @@ +import datetime +from django.db import models +from django.utils import timezone +# Create your models here. + + +class Question(models.Model): + question_text = models.CharField(max_length=200) + pub_date = models.DateTimeField('date published') + + def __str__(self): + return self.question_text + + def was_published_recently(self): + return self.pub_date >= timezone.now() - datetime.timedelta(days=1) + + +class Choice(models.Model): + question = models.ForeignKey(Question, on_delete=models.CASCADE) + choice_text = models.CharField(max_length=200) + votes = models.IntegerField(default=0) + + def __str__(self): + return self.choice_text diff --git a/Code/will/django_labs/practice_labs/mysite/polls/tests.py b/Code/will/django_labs/practice_labs/mysite/polls/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/polls/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/django_labs/practice_labs/mysite/polls/urls.py b/Code/will/django_labs/practice_labs/mysite/polls/urls.py new file mode 100644 index 00000000..9e6ca5f5 --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/polls/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index, name='index'), + path('/', views.detail, name='detail'), + path('/results/', views.results, name='results'), + path('/vote/', views.vote, name='vote') +] diff --git a/Code/will/django_labs/practice_labs/mysite/polls/views.py b/Code/will/django_labs/practice_labs/mysite/polls/views.py new file mode 100644 index 00000000..019cb3bf --- /dev/null +++ b/Code/will/django_labs/practice_labs/mysite/polls/views.py @@ -0,0 +1,21 @@ +from django.shortcuts import render +from django.http import HttpResponse + +# Create your views here. + + +def index(request): + return HttpResponse("Hello, world. You're at the polls index.") + + +def detail(request, question_id): + return HttpResponse("You're looking at question %s." % question_id) + + +def results(request, question_id): + response = "You're looking athe the results of question %s." + return HttpResponse(response % question_id) + + +def vote(request, question_id): + return HttpResponse*("You're voting on question %s." % question_id) diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/.gitignore b/Code/will/django_labs/practice_labs/phonebook_proj/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/__init__.py b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/admin.py b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/admin.py new file mode 100644 index 00000000..5913a1bc --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import * + +# Register your models here. +admin.site.register(Contact) diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/apps.py b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/apps.py new file mode 100644 index 00000000..489746a5 --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ContactsappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'contactsapp' diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/migrations/0001_initial.py b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/migrations/0001_initial.py new file mode 100644 index 00000000..a5fa53ae --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# Generated by Django 4.0.3 on 2022-04-14 01:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Contact', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=50)), + ('last_name', models.CharField(blank=True, max_length=50, null=True)), + ('phone_number', models.CharField(max_length=15)), + ('email', models.EmailField(blank=True, max_length=254, null=True)), + ('address', models.CharField(blank=True, max_length=150, null=True)), + ('is_cool', models.BooleanField(default=False)), + ], + ), + ] diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/migrations/__init__.py b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/models.py b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/models.py new file mode 100644 index 00000000..4ed95a65 --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/models.py @@ -0,0 +1,32 @@ +from django.db import models + +# Create your models here. + + +class Contact(models.Model): + first_name = models.CharField(max_length=50) + last_name = models.CharField(max_length=50, null=True, blank=True) + phone_number = models.CharField(max_length=15) + email = models.EmailField(null=True, blank=True) + address = models.CharField(max_length=150, null=True, blank=True) + is_cool = models.BooleanField(default=False) + + def __str__(self): + return f'{self.first_name} {self.last_name}' + + def full_name(self): + if self.last_name: + return f'{self.first_name} {self.last_name}' + + else: + return f'{self.first_name}' + + def coolness(self): + if self.is_cool: + return 'cool' + + else: + return 'not cool' + + def __str__(self): + return f'{self.full_name()} -- {self.coolness()}' diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/templates/contactsapp/all_contacts.html b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/templates/contactsapp/all_contacts.html new file mode 100644 index 00000000..a4442ac1 --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/templates/contactsapp/all_contacts.html @@ -0,0 +1,30 @@ + + + + + + + Contacts + + +

All Contacts

+ +
+ {% csrf_token %} + + + + + + + + +
+ + {% for contact in contacts %} +
{{contact.full_name}} is {{contact.coolness}}
+ {% endfor %} + + \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/templates/contactsapp/index.html b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/templates/contactsapp/index.html new file mode 100644 index 00000000..fbc4a7f6 --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/templates/contactsapp/index.html @@ -0,0 +1,18 @@ + + + + + + + Home + + +

Welcome to the Contacts App

+
+ {% csrf_token %} + + +
+ + + \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/tests.py b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/urls.py b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/urls.py new file mode 100644 index 00000000..ca8c7e1a --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from . import views + +app_name = 'contactsapp' + +urlpatterns = [ + path('', views.home_page, name='home'), + path('all/', views.all_contacts, name='all_contacts'), + path('save_contact/', views.save_contact, name='save_contact'), + path('search/', views.search_contact, name='search_contact') +] diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/views.py b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/views.py new file mode 100644 index 00000000..be0171a4 --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/contactsapp/views.py @@ -0,0 +1,50 @@ +from django.shortcuts import render +from .models import * +from django.http import HttpResponse, HttpResponseRedirect +from django.urls import reverse +# Create your views here. + + +def home_page(request): + return render(request, 'contactsapp/index.html') + + +def all_contacts(request): + contacts = Contact.objects.all() + + contact = { + 'contacts': contacts + } + return render(request, 'contactsapp/all_contacts.html', contact) + + +def save_contact(request): + contact = Contact() + form = request.POST + + if request.POST: + + contact.first_name = form['first_name'] + contact.last_name = form['last_name'] + contact.phone_number = form['phone_number'] + contact.email = form['email'] + contact.address = form['address'] + if form.get('is_cool') == 'on': + contact.is_cool = True + else: + contact.is_cool = False + + contact.save() + + return HttpResponseRedirect(reverse('contactsapp:all_contacts')) + + +def search_contact(request): + name = request.POST['first_name'] + if name: + contact = Contact.objects.filter(first_name=name) + + else: + contact = '' + + return HttpResponse(contact) diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/manage.py b/Code/will/django_labs/practice_labs/phonebook_proj/manage.py new file mode 100644 index 00000000..75f0d8b9 --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/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', 'phonebook_proj.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/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/__init__.py b/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/asgi.py b/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/asgi.py new file mode 100644 index 00000000..9226ab4b --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for phonebook_proj 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'phonebook_proj.settings') + +application = get_asgi_application() diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/settings.py b/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/settings.py new file mode 100644 index 00000000..2e35a4f1 --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for phonebook_proj project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" +from decouple import config +from pathlib import Path + +# 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/4.0/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 = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # Project Apps + 'contactsapp' +] + +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 = 'phonebook_proj.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 = 'phonebook_proj.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Chicago' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/urls.py b/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/urls.py new file mode 100644 index 00000000..c069f3e5 --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/urls.py @@ -0,0 +1,22 @@ +"""phonebook_proj URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('contacts/', include('contactsapp.urls')) +] diff --git a/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/wsgi.py b/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/wsgi.py new file mode 100644 index 00000000..54e908f5 --- /dev/null +++ b/Code/will/django_labs/practice_labs/phonebook_proj/phonebook_proj/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for phonebook_proj 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'phonebook_proj.settings') + +application = get_wsgi_application() diff --git a/Code/will/django_labs/practice_labs/project_1/.gitignore b/Code/will/django_labs/practice_labs/project_1/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/project_1/hello_app/__init__.py b/Code/will/django_labs/practice_labs/project_1/hello_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/project_1/hello_app/admin.py b/Code/will/django_labs/practice_labs/project_1/hello_app/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/hello_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/Code/will/django_labs/practice_labs/project_1/hello_app/apps.py b/Code/will/django_labs/practice_labs/project_1/hello_app/apps.py new file mode 100644 index 00000000..37e3c0e4 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/hello_app/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class HelloAppConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'hello_app' diff --git a/Code/will/django_labs/practice_labs/project_1/hello_app/migrations/__init__.py b/Code/will/django_labs/practice_labs/project_1/hello_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/project_1/hello_app/models.py b/Code/will/django_labs/practice_labs/project_1/hello_app/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/hello_app/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/Code/will/django_labs/practice_labs/project_1/hello_app/templates/hello_app/index.html b/Code/will/django_labs/practice_labs/project_1/hello_app/templates/hello_app/index.html new file mode 100644 index 00000000..6c93d969 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/hello_app/templates/hello_app/index.html @@ -0,0 +1,12 @@ + + + + + + + Document + + +

Hello {{name}}

+ + \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/project_1/hello_app/tests.py b/Code/will/django_labs/practice_labs/project_1/hello_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/hello_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/django_labs/practice_labs/project_1/hello_app/urls.py b/Code/will/django_labs/practice_labs/project_1/hello_app/urls.py new file mode 100644 index 00000000..16157d01 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/hello_app/urls.py @@ -0,0 +1,17 @@ +from django.urls import path +from . import views + +urlpatterns = [ + #8000/ + path('', views.hello, name='hello'), + + #8000/bruce + path('bruce', views.bruce, name='bruce'), + + #8000/batman + path('batman', views.batman, name='batman'), + + #8000/string + path('', views.say_hello, name='say_hello') + +] \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/project_1/hello_app/views.py b/Code/will/django_labs/practice_labs/project_1/hello_app/views.py new file mode 100644 index 00000000..b82a9220 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/hello_app/views.py @@ -0,0 +1,16 @@ +from django.http import HttpResponse +from django.shortcuts import render + +# Create your views here. +def hello(request): + return HttpResponse('

Hello World') + +def bruce(request): + return HttpResponse('Hello Bruce') + +def batman(request): + return HttpResponse("Sup Bruce, we know you're Batman") + +def say_hello(request, name): +# return HttpResponse(f'Hello {name}') + return render(request, 'hello_app/index.html', {'name':name}) diff --git a/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/__init__.py b/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/asgi.py b/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/asgi.py new file mode 100644 index 00000000..8d6f1c66 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for kiwi_first_proj 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'kiwi_first_proj.settings') + +application = get_asgi_application() diff --git a/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/settings.py b/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/settings.py new file mode 100644 index 00000000..8e044490 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for kiwi_first_proj project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +from decouple import config +from pathlib import Path + +# 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/4.0/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 = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # project apps + 'hello_app' +] + +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 = 'kiwi_first_proj.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 = 'kiwi_first_proj.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Detroit' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/urls.py b/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/urls.py new file mode 100644 index 00000000..794a5ed1 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/urls.py @@ -0,0 +1,22 @@ +"""kiwi_first_proj URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/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 + +urlpatterns = [ + path('hello/', include('hello_app.urls')), + path('admin/', admin.site.urls) +] diff --git a/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/wsgi.py b/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/wsgi.py new file mode 100644 index 00000000..97eac6ce --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/kiwi_first_proj/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for kiwi_first_proj 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'kiwi_first_proj.settings') + +application = get_wsgi_application() diff --git a/Code/will/django_labs/practice_labs/project_1/manage.py b/Code/will/django_labs/practice_labs/project_1/manage.py new file mode 100644 index 00000000..e77fbc01 --- /dev/null +++ b/Code/will/django_labs/practice_labs/project_1/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', 'kiwi_first_proj.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/Code/will/django_labs/practice_labs/sessions/.gitignore b/Code/will/django_labs/practice_labs/sessions/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/sessions/manage.py b/Code/will/django_labs/practice_labs/sessions/manage.py new file mode 100644 index 00000000..3b4a18bb --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/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', 'sessions.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/Code/will/django_labs/practice_labs/sessions/seshapp/__init__.py b/Code/will/django_labs/practice_labs/sessions/seshapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/sessions/seshapp/admin.py b/Code/will/django_labs/practice_labs/sessions/seshapp/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/seshapp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/Code/will/django_labs/practice_labs/sessions/seshapp/apps.py b/Code/will/django_labs/practice_labs/sessions/seshapp/apps.py new file mode 100644 index 00000000..de092c20 --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/seshapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class SeshappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'seshapp' diff --git a/Code/will/django_labs/practice_labs/sessions/seshapp/migrations/__init__.py b/Code/will/django_labs/practice_labs/sessions/seshapp/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/sessions/seshapp/models.py b/Code/will/django_labs/practice_labs/sessions/seshapp/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/seshapp/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/Code/will/django_labs/practice_labs/sessions/seshapp/templates/seshapp/add.html b/Code/will/django_labs/practice_labs/sessions/seshapp/templates/seshapp/add.html new file mode 100644 index 00000000..bace3fc5 --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/seshapp/templates/seshapp/add.html @@ -0,0 +1,18 @@ + + + + + + + Add A Task + + +

Add A Task

+
+ {% csrf_token %} + {{form}} + +
+ View Tasks + + \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/sessions/seshapp/templates/seshapp/index.html b/Code/will/django_labs/practice_labs/sessions/seshapp/templates/seshapp/index.html new file mode 100644 index 00000000..b63698c0 --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/seshapp/templates/seshapp/index.html @@ -0,0 +1,20 @@ + + + + + + + Sessions + + + {% for task in tasks %} +
  • + {{task}} +
  • + + {%empty%} +
  • No tasks currently managed
  • + + {% endfor %} + + \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/sessions/seshapp/tests.py b/Code/will/django_labs/practice_labs/sessions/seshapp/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/seshapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/django_labs/practice_labs/sessions/seshapp/urls.py b/Code/will/django_labs/practice_labs/sessions/seshapp/urls.py new file mode 100644 index 00000000..1a204ff8 --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/seshapp/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from . import views + +app_name = 'tasks' +urlpatterns = [ + path('', views.index, name='index'), + path('add/', views.add, name='add') +] diff --git a/Code/will/django_labs/practice_labs/sessions/seshapp/views.py b/Code/will/django_labs/practice_labs/sessions/seshapp/views.py new file mode 100644 index 00000000..1a915f31 --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/seshapp/views.py @@ -0,0 +1,35 @@ +from django.urls import reverse +from django.http import HttpResponse, HttpResponseRedirect +from django.shortcuts import render +from django import forms + +# Create your views here. + +tasks = [] + + +def index(request): + if 'tasks' not in request.session: + request.session['tasks'] = [] + + return render(request, 'seshapp/index.html', {'tasks': tasks}) + + +class NewTaskForm(forms.Form): + task = forms.CharField(label='New Task', max_length=200) + + +def add(request): + if request.method == 'POST': + form = NewTaskForm(request.POST) + if form.is_valid(): + task = form.cleaned_data['task'] + tasks.append(task) + return HttpResponseRedirect(reverse('tasks:index')) + else: + return render(request, 'seshapp/add.html', { + 'form': form + }) + return render(request, 'seshapp/add.html', { + 'form': NewTaskForm() + }) diff --git a/Code/will/django_labs/practice_labs/sessions/sessions/__init__.py b/Code/will/django_labs/practice_labs/sessions/sessions/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/sessions/sessions/asgi.py b/Code/will/django_labs/practice_labs/sessions/sessions/asgi.py new file mode 100644 index 00000000..03106f0e --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/sessions/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for sessions 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sessions.settings') + +application = get_asgi_application() diff --git a/Code/will/django_labs/practice_labs/sessions/sessions/settings.py b/Code/will/django_labs/practice_labs/sessions/sessions/settings.py new file mode 100644 index 00000000..a738e65f --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/sessions/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for sessions project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +from decouple import config +from pathlib import Path + +# 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/4.0/howto/deployment/checklist/ + +SECRET_KEY = config("SECRET_KEY") + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # Project Apps + 'seshapp' +] + +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 = 'sessions.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 = 'sessions.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Chicago' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/will/django_labs/practice_labs/sessions/sessions/urls.py b/Code/will/django_labs/practice_labs/sessions/sessions/urls.py new file mode 100644 index 00000000..494027d2 --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/sessions/urls.py @@ -0,0 +1,22 @@ +"""sessions URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('sessions/', include('seshapp.urls')) +] diff --git a/Code/will/django_labs/practice_labs/sessions/sessions/wsgi.py b/Code/will/django_labs/practice_labs/sessions/sessions/wsgi.py new file mode 100644 index 00000000..eec6507a --- /dev/null +++ b/Code/will/django_labs/practice_labs/sessions/sessions/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for sessions 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sessions.settings') + +application = get_wsgi_application() diff --git a/Code/will/django_labs/practice_labs/twitter_proj/.gitignore b/Code/will/django_labs/practice_labs/twitter_proj/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/twitter_proj/manage.py b/Code/will/django_labs/practice_labs/twitter_proj/manage.py new file mode 100644 index 00000000..91206c78 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/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', 'twitter_proj.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/Code/will/django_labs/practice_labs/twitter_proj/messages_app/__init__.py b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/twitter_proj/messages_app/admin.py b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/admin.py new file mode 100644 index 00000000..bdfd93c7 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import * + +# Register your models here. +admin.site.register(Tweet) diff --git a/Code/will/django_labs/practice_labs/twitter_proj/messages_app/apps.py b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/apps.py new file mode 100644 index 00000000..e44dcdbc --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MessagesAppConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'messages_app' diff --git a/Code/will/django_labs/practice_labs/twitter_proj/messages_app/forms.py b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/forms.py new file mode 100644 index 00000000..73ff6be5 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/forms.py @@ -0,0 +1,5 @@ +from django import forms + + +class NewTweetForm(forms.Form): + text = forms.CharField(label='Tweet', max_length=120) diff --git a/Code/will/django_labs/practice_labs/twitter_proj/messages_app/migrations/0001_initial.py b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/migrations/0001_initial.py new file mode 100644 index 00000000..296cf32b --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 4.0.3 on 2022-04-07 03:58 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Tweet', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('text', models.CharField(max_length=120)), + ('likes', models.IntegerField(default=1)), + ('dislikes', models.IntegerField(default=0)), + ('publish_date', models.DateTimeField(auto_now=True)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tweets', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/Code/will/django_labs/practice_labs/twitter_proj/messages_app/migrations/__init__.py b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/twitter_proj/messages_app/models.py b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/models.py new file mode 100644 index 00000000..66d8b573 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/models.py @@ -0,0 +1,16 @@ +from django.db import models +from django.contrib.auth.models import User + +# Create your models here. + + +class Tweet(models.Model): + text = models.CharField(max_length=120) + user = models.ForeignKey( + User, on_delete=models.CASCADE, related_name='tweets') + likes = models.IntegerField(default=1) + dislikes = models.IntegerField(default=0) + publish_date = models.DateTimeField(auto_now=True) + + def __str__(self): + return f'{self.user}: {self.text[:15]} {self.published_date.year}/{self.published_date.month}/{self.published_date.day}' diff --git a/Code/will/django_labs/practice_labs/twitter_proj/messages_app/templates/messages_app/index.html b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/templates/messages_app/index.html new file mode 100644 index 00000000..9ee2b642 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/templates/messages_app/index.html @@ -0,0 +1,36 @@ + + + + + + + Welcome + + +

    Welcome 2 Twitter

    + {% if not request.user.is_anonymous %} +
    + {% csrf_token %} + {{form}} + +
    + {% endif %} + + + {% for tweet in tweets %} +
    +

    {{tweet.text}}

    + + {% if request.user == tweet.user %} + X + {% endif %} + + +
    {{tweet.user}}
    + +

    Likes: {{tweet.likes}} Dislikes: {{tweet.dislikes}}

    +

    {{tweet.published.date}}

    +
    + {% endfor %} + + \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/twitter_proj/messages_app/tests.py b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/django_labs/practice_labs/twitter_proj/messages_app/urls.py b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/urls.py new file mode 100644 index 00000000..248f45bd --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index, name='index'), + path('new', views.new_tweet, name='new_tweet'), + path('delete/', views.delete_tweet, name='delete_tweet') +] diff --git a/Code/will/django_labs/practice_labs/twitter_proj/messages_app/views.py b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/views.py new file mode 100644 index 00000000..85d6140d --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/messages_app/views.py @@ -0,0 +1,35 @@ +from django.shortcuts import render +from django.http import HttpResponseRedirect +from django.urls import reverse +from .forms import * +from .models import Tweet +from django.contrib.auth.decorators import login_required +from messages_app.forms import NewTweetForm +# Create your views here. + + +def index(request): + tweets = Tweet.objects.all().order_by('-publish_date')[:20] + return render(request, 'messages_app/index.html', { + 'tweets': tweets, 'form': NewTweetForm() + }) + + +@login_required +def new_tweet(request): + if request.method == 'POST': + form = NewTweetForm(request.POST) + if form.is_valid(): + tweet = Tweet() + tweet.user = request.user + tweet.text = forms.cleaned_data['text'] + tweet.save() + + return HttpResponseRedirect(reverse('index')) + + +@login_required +def delete_tweet(request, tweet_id): + tweet = Tweet.objects.get(id=tweet_id, user=request.user) + tweet.delete() + return HttpResponseRedirect(reverse('index')) diff --git a/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/__init__.py b/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/asgi.py b/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/asgi.py new file mode 100644 index 00000000..2c01d7f1 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for twitter_proj 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'twitter_proj.settings') + +application = get_asgi_application() diff --git a/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/settings.py b/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/settings.py new file mode 100644 index 00000000..bb5f8716 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/settings.py @@ -0,0 +1,128 @@ +""" +Django settings for twitter_proj project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +from decouple import config +from pathlib import Path + +# 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/4.0/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 = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # Project Applications + 'users_app', + 'messages_app' +] + +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 = 'twitter_proj.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 = 'twitter_proj.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Chicago' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/urls.py b/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/urls.py new file mode 100644 index 00000000..d0912696 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/urls.py @@ -0,0 +1,23 @@ +"""twitter_proj URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('users/', include('users_app.urls')), + path('', include('messages_app.urls')) +] diff --git a/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/wsgi.py b/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/wsgi.py new file mode 100644 index 00000000..242d53ea --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/twitter_proj/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for twitter_proj 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'twitter_proj.settings') + +application = get_wsgi_application() diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/__init__.py b/Code/will/django_labs/practice_labs/twitter_proj/users_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/admin.py b/Code/will/django_labs/practice_labs/twitter_proj/users_app/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/users_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/apps.py b/Code/will/django_labs/practice_labs/twitter_proj/users_app/apps.py new file mode 100644 index 00000000..7200dd57 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/users_app/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UsersAppConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'users_app' diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/forms.py b/Code/will/django_labs/practice_labs/twitter_proj/users_app/forms.py new file mode 100644 index 00000000..2b19481f --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/users_app/forms.py @@ -0,0 +1,16 @@ +from django import forms + + +class NewSignupForm(forms.Form): + username = forms.CharField(label='Username', max_length=20) + password = forms.CharField( + widget=forms.PasswordInput, label='Password', max_length=10) + first_name = forms.CharField(label='First Name', max_length=20) + last_name = forms.CharField(label='Last Name', max_length=20) + email = forms.EmailField(label='Email') + + +class NewLoginForm(forms.Form): + username = forms.CharField(label='Username', max_length=20) + password = forms.CharField( + widget=forms.PasswordInput, label='Password', max_length=10) diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/migrations/__init__.py b/Code/will/django_labs/practice_labs/twitter_proj/users_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/models.py b/Code/will/django_labs/practice_labs/twitter_proj/users_app/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/users_app/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/templates/users_app/login.html b/Code/will/django_labs/practice_labs/twitter_proj/users_app/templates/users_app/login.html new file mode 100644 index 00000000..09ea283d --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/users_app/templates/users_app/login.html @@ -0,0 +1,16 @@ + + + + + + + Login + + +
    + {% csrf_token %} + {{form}} + +
    + + \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/templates/users_app/profile.html b/Code/will/django_labs/practice_labs/twitter_proj/users_app/templates/users_app/profile.html new file mode 100644 index 00000000..3940eecd --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/users_app/templates/users_app/profile.html @@ -0,0 +1,14 @@ + + + + + + + {{request.user}}'s Profile + + +

    Welcome {{request.user}}

    + + Logout + + \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/templates/users_app/signup.html b/Code/will/django_labs/practice_labs/twitter_proj/users_app/templates/users_app/signup.html new file mode 100644 index 00000000..cd2a0dd9 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/users_app/templates/users_app/signup.html @@ -0,0 +1,16 @@ + + + + + + + Sign Up + + +
    + {% csrf_token %} + {{form}} + +
    + + \ No newline at end of file diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/tests.py b/Code/will/django_labs/practice_labs/twitter_proj/users_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/users_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/urls.py b/Code/will/django_labs/practice_labs/twitter_proj/users_app/urls.py new file mode 100644 index 00000000..2ad39f8b --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/users_app/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('signup/', views.signup, name='signup'), + path('login/', views.user_login, name='login'), + path('profile/', views.profile, name='profile'), + path('logout/', views.user_logout, name='logout') +] diff --git a/Code/will/django_labs/practice_labs/twitter_proj/users_app/views.py b/Code/will/django_labs/practice_labs/twitter_proj/users_app/views.py new file mode 100644 index 00000000..7e2b866b --- /dev/null +++ b/Code/will/django_labs/practice_labs/twitter_proj/users_app/views.py @@ -0,0 +1,53 @@ +from django.http import HttpResponseRedirect +from django.shortcuts import render +from .forms import * +from django.contrib.auth.models import User +from django.urls import reverse +from django.contrib.auth import authenticate, login, logout +# Create your views here. + + +def signup(request): + if request.method == 'GET': + form = NewSignupForm() + return render(request, 'users_app/signup.html', {'form': form}) + + elif request.method == 'POST': + form = NewSignupForm(request.POST) + if form.is_valid(): + # create a new user + user = User.objects.create_user( + username=form.cleaned_data['username'], + first_name=form.cleaned_data['first_name'], + last_name=form.cleaned_data['last_name'], + email=form.cleaned_data['email'], + password=form.cleaned_data['password'] + ) + return HttpResponseRedirect(reverse('signup')) + + +def user_login(request): + if request.method == 'GET': + return render(request, 'users_app/login.html', {'form': NewLoginForm()}) + + elif request.method == 'POST': + form = NewLoginForm(request.POST) + if form.is_valid(): + password = form.cleaned_data['password'] + user = authenticate( + request, username=form.cleaned_data['username'], password=password) + if user is not None: + login(request, user) + return HttpResponseRedirect(reverse('profile')) + else: + form.add_error('username', 'Invalid username or password') + return render(request, 'users_app/login.html', {'form': form}) + + +def profile(request): + return render(request, 'users_app/profile.html') + + +def user_logout(request): + logout(request) + return HttpResponseRedirect(reverse('login')) diff --git a/Code/will/django_labs/todo_proj/.gitignore b/Code/will/django_labs/todo_proj/.gitignore new file mode 100644 index 00000000..4c49bd78 --- /dev/null +++ b/Code/will/django_labs/todo_proj/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Code/will/django_labs/todo_proj/manage.py b/Code/will/django_labs/todo_proj/manage.py new file mode 100644 index 00000000..6be564d2 --- /dev/null +++ b/Code/will/django_labs/todo_proj/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', 'todo_proj.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/Code/will/django_labs/todo_proj/todo_app/__init__.py b/Code/will/django_labs/todo_proj/todo_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/todo_proj/todo_app/admin.py b/Code/will/django_labs/todo_proj/todo_app/admin.py new file mode 100644 index 00000000..da7003ed --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_app/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import * + +# Register your models here. +admin.site.register(TodoItem) +admin.site.register(Priority) diff --git a/Code/will/django_labs/todo_proj/todo_app/apps.py b/Code/will/django_labs/todo_proj/todo_app/apps.py new file mode 100644 index 00000000..d8f1498d --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_app/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TodoAppConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'todo_app' diff --git a/Code/will/django_labs/todo_proj/todo_app/migrations/0001_initial.py b/Code/will/django_labs/todo_proj/todo_app/migrations/0001_initial.py new file mode 100644 index 00000000..20dfa0e5 --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_app/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 4.0.3 on 2022-04-09 03:12 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Priority', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(choices=[('high', 'HIGH'), ('medium', 'MEDIUM'), ('low', 'LOW')], default='low', max_length=6)), + ], + ), + migrations.CreateModel( + name='TodoItem', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('text', models.CharField(max_length=120)), + ('created_date', models.DateTimeField(auto_now=True)), + ('priority', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tasks', to='todo_app.priority')), + ], + ), + ] diff --git a/Code/will/django_labs/todo_proj/todo_app/migrations/0002_alter_priority_name_alter_todoitem_priority.py b/Code/will/django_labs/todo_proj/todo_app/migrations/0002_alter_priority_name_alter_todoitem_priority.py new file mode 100644 index 00000000..a70d7b34 --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_app/migrations/0002_alter_priority_name_alter_todoitem_priority.py @@ -0,0 +1,24 @@ +# Generated by Django 4.0.3 on 2022-04-15 02:16 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo_app', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='priority', + name='name', + field=models.CharField(choices=[('high', 'High'), ('medium', 'Medium'), ('low', 'Low')], default='low', max_length=6), + ), + migrations.AlterField( + model_name='todoitem', + name='priority', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='todo_app.priority'), + ), + ] diff --git a/Code/will/django_labs/todo_proj/todo_app/migrations/__init__.py b/Code/will/django_labs/todo_proj/todo_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/todo_proj/todo_app/models.py b/Code/will/django_labs/todo_proj/todo_app/models.py new file mode 100644 index 00000000..2f307fd5 --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_app/models.py @@ -0,0 +1,20 @@ +from django.db import models +# Create your models here. + + +class Priority(models.Model): + name = models.CharField( + max_length=6, choices=(('High', 'High'), ('Medium', 'Medium'), ('Low', 'Low'))) + + def __str__(self): + return f'{self.name}' + + +class TodoItem(models.Model): + text = models.CharField(max_length=120) + priority = models.ForeignKey( + Priority, on_delete=models.CASCADE, related_name='items') + created_date = models.DateTimeField(auto_now=True) + + def __str__(self): + return f'{self.text} {self.created_date.month}/{self.created_date.day}' diff --git a/Code/will/django_labs/todo_proj/todo_app/templates/todo_app/index.html b/Code/will/django_labs/todo_proj/todo_app/templates/todo_app/index.html new file mode 100644 index 00000000..c8cb0e7b --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_app/templates/todo_app/index.html @@ -0,0 +1,38 @@ + + + + + + + Home + + + +
    + {% csrf_token %} + + + + + +

    To Do List:

    + + {% for priority in priorities %} +
    +

    {{priority.name}}

    + + {% for task in priority.items.all %} +
    +
    {{task.text}} {{task.created_date.month}}/{{task.created_date.day}}
    +
    + {% endfor %} +
    + {% endfor %} + + \ No newline at end of file diff --git a/Code/will/django_labs/todo_proj/todo_app/tests.py b/Code/will/django_labs/todo_proj/todo_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/django_labs/todo_proj/todo_app/urls.py b/Code/will/django_labs/todo_proj/todo_app/urls.py new file mode 100644 index 00000000..e90482f6 --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_app/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from . import views + +app_name = 'todo_app' + +urlpatterns = [ + path('', views.index, name='index'), + path('save', views.save_task, name='save_task') +] diff --git a/Code/will/django_labs/todo_proj/todo_app/views.py b/Code/will/django_labs/todo_proj/todo_app/views.py new file mode 100644 index 00000000..bf08593f --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_app/views.py @@ -0,0 +1,26 @@ +from django.shortcuts import render +from .models import * +from django.http import HttpResponseRedirect +from django.urls import reverse +# Create your views here. + + +def index(request): + priorities = Priority.objects.all() + tasks = TodoItem.objects.all().order_by('-created_date') + return render(request, 'todo_app/index.html', { + 'tasks': tasks, 'priorities': priorities + }) + + +def save_task(request): + task_text = request.POST['item'] + task_prio = request.POST['priority'] + new_task = TodoItem() + new_task.text = task_text + if task_prio: + priority = Priority.objects.get(id=task_prio) + new_task.priority = priority + new_task.save() + + return HttpResponseRedirect(reverse('todo_app:index')) diff --git a/Code/will/django_labs/todo_proj/todo_proj/__init__.py b/Code/will/django_labs/todo_proj/todo_proj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/django_labs/todo_proj/todo_proj/asgi.py b/Code/will/django_labs/todo_proj/todo_proj/asgi.py new file mode 100644 index 00000000..5a0fd4de --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_proj/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for todo_proj 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todo_proj.settings') + +application = get_asgi_application() diff --git a/Code/will/django_labs/todo_proj/todo_proj/settings.py b/Code/will/django_labs/todo_proj/todo_proj/settings.py new file mode 100644 index 00000000..4376c7bd --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_proj/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for todo_proj project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +from decouple import config +from pathlib import Path + +# 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/4.0/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 = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # Project apps + 'todo_app' +] + +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 = 'todo_proj.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 = 'todo_proj.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Chicago' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/will/django_labs/todo_proj/todo_proj/urls.py b/Code/will/django_labs/todo_proj/todo_proj/urls.py new file mode 100644 index 00000000..02fb6069 --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_proj/urls.py @@ -0,0 +1,22 @@ +"""todo_proj URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('index/', include('todo_app.urls')) +] diff --git a/Code/will/django_labs/todo_proj/todo_proj/wsgi.py b/Code/will/django_labs/todo_proj/todo_proj/wsgi.py new file mode 100644 index 00000000..5f96a37b --- /dev/null +++ b/Code/will/django_labs/todo_proj/todo_proj/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for todo_proj 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todo_proj.settings') + +application = get_wsgi_application() diff --git a/Code/will/html_css/Labs/Burrito_Order_Form/index.html b/Code/will/html_css/Labs/Burrito_Order_Form/index.html new file mode 100644 index 00000000..4b9b5a83 --- /dev/null +++ b/Code/will/html_css/Labs/Burrito_Order_Form/index.html @@ -0,0 +1,92 @@ + + + + + + + + + Loco Burrito + + +
    Loco Burrito
    + + + Picture of burrito +
    +

    Customize Your Burrito

    + + +
    + +

    Tortilla:

    + + + + + + + + + +
    + +

    Meat:

    + + + + + + + + + + + +
    + +

    Rice:

    + + + + + +
    + +

    Beans:

    + + + + + +
    + +

    Additional Options:

    + + + + + + + + + + + +
    +
    + + + +
    +
    + + +
    +
    +

    Loco Burrito © 2022

    +
    +
    + + + \ No newline at end of file diff --git a/Code/will/html_css/Labs/Burrito_Order_Form/style.css b/Code/will/html_css/Labs/Burrito_Order_Form/style.css new file mode 100644 index 00000000..374f3e19 --- /dev/null +++ b/Code/will/html_css/Labs/Burrito_Order_Form/style.css @@ -0,0 +1,70 @@ +body { + margin: 0; + text-align: center; + font-size: 18px; + background-color: rgb(223, 221, 221); +} + +img { + display: block; + float: left; + width: 20%; + margin-top: 1px; +} + +h2 { + text-decoration: underline; + font-weight: bold; +} + +header { + display: flex; + justify-content: center; + font-size: 80px; + background-color: rgba(255, 0, 0, 0.918); + font-family: "Amatic SC"; + font-weight: bolder; + margin: 0; + color: rgb(196, 151, 4); + text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, + 1px 1px 0 #000; + box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.397); +} + +input { + display: inline-flex; + justify-content: center; + margin-right: 30px; +} + +main { + display: block; + float: right; + width: 75%; +} + +.first { + margin-left: 10px; +} + +p { + display: inline-flex; + justify-content: center; + margin-left: 10px; + font-weight: bold; + font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; +} + +input { + display: inline-flex; + justify-content: center; +} + +footer { + position: absolute; + bottom: 0; + background-color: black; + color: white; + text-align: center; + width: 100vw; +} diff --git a/Code/will/html_css/Labs/Company_Page/index.html b/Code/will/html_css/Labs/Company_Page/index.html new file mode 100644 index 00000000..cecfdd38 --- /dev/null +++ b/Code/will/html_css/Labs/Company_Page/index.html @@ -0,0 +1,115 @@ + + + + + + + + + We Make Games + + +
    + +
    + +
    +
    +
    +
    +
    + + New Game Announcement +
    +
    +
    +

    Hype information about new game coming out soon!

    +
    +
    + +
    +
    +
    + +
    +
    +
    +
    + Hotfix 19.2 +

    Here are the patch notes for Hotfix 19.2 for Big Game.

    +
    + +
    +
    +
    +
    +
    + Community Spotlight +

    Shining the spotlight on a cool creator.

    +
    + +
    +
    +
    + +
    +
    +
    +
    + Holiday Sale +

    Sale that includes that really cool item from the shop you have been wanting for months!

    +
    + +
    +
    +
    + +
    + + + + \ No newline at end of file diff --git a/Code/will/html_css/Labs/Company_Page/style.css b/Code/will/html_css/Labs/Company_Page/style.css new file mode 100644 index 00000000..d2729286 --- /dev/null +++ b/Code/will/html_css/Labs/Company_Page/style.css @@ -0,0 +1,10 @@ +body { + display: flex; + min-height: 100vh; + flex-direction: column; + background-color: #37474f; +} + +main { + flex: 1 0 auto; +} diff --git a/Code/will/html_css/Labs/Flask_Redo/app.py b/Code/will/html_css/Labs/Flask_Redo/app.py new file mode 100644 index 00000000..463f31b2 --- /dev/null +++ b/Code/will/html_css/Labs/Flask_Redo/app.py @@ -0,0 +1,23 @@ +from flask import Flask, render_template, request +app = Flask(__name__) + +# localhost:5000/ +@app.route('/') +def index(): + return render_template('index.html') + +@app.route('/results', methods=['post']) +def results(): + conversion = request.form + + units_to_convert = conversion['convert'] + distance_to_convert = conversion['amount'] + meters_to_units = conversion['converted'] + distance_to_convert = int(distance_to_convert) + + distances = {'feet': 0.3048, 'miles': 1609.34, 'meters': 1.0, 'kilometers': 1000, 'yards': 0.9144, 'inches': 0.0254} + units_to_meters = distance_to_convert * distances.get(units_to_convert) # convert the meters into the desired second unit and print results + converted_units = units_to_meters / distances.get(meters_to_units) + converted_units = round(converted_units, 3) + + return render_template('results.html', converted_units=converted_units, meters_to_units=meters_to_units, units_to_convert=units_to_convert, distance_to_convert=distance_to_convert) \ No newline at end of file diff --git a/Code/will/html_css/Labs/Flask_Redo/static/style.css b/Code/will/html_css/Labs/Flask_Redo/static/style.css new file mode 100644 index 00000000..e1a53266 --- /dev/null +++ b/Code/will/html_css/Labs/Flask_Redo/static/style.css @@ -0,0 +1,9 @@ +body { + text-align: center; + background-color: grey; +} + +label { + font-size: 22px; + margin-left: 16px; +} diff --git a/Code/will/html_css/Labs/Flask_Redo/templates/index.html b/Code/will/html_css/Labs/Flask_Redo/templates/index.html new file mode 100644 index 00000000..111bd77d --- /dev/null +++ b/Code/will/html_css/Labs/Flask_Redo/templates/index.html @@ -0,0 +1,27 @@ + + + + + + + + Unit Converter + + +

    Unit Converting

    +

    This converter can convert feet, miles, meters, kilometers, yards, and inches.

    + +
    + + + + + + + + + + +
    + + \ No newline at end of file diff --git a/Code/will/html_css/Labs/Flask_Redo/templates/results.html b/Code/will/html_css/Labs/Flask_Redo/templates/results.html new file mode 100644 index 00000000..9d17400f --- /dev/null +++ b/Code/will/html_css/Labs/Flask_Redo/templates/results.html @@ -0,0 +1,17 @@ + + + + + + + + Unit Conversion Results + + +

    Results:

    + +

    {{distance_to_convert}} {{units_to_convert}} is equal to {{converted_units}} {{meters_to_units}}

    + + Convert more? + + \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/flask/app.py b/Code/will/html_css/notes_and_practice/flask/app.py new file mode 100644 index 00000000..1c0d9be6 --- /dev/null +++ b/Code/will/html_css/notes_and_practice/flask/app.py @@ -0,0 +1,25 @@ +from flask import Flask, render_template, request +app = Flask(__name__) + +# localhost:5000/ +@app.route('/') +def index(): + name = "Bill" + return render_template('index.html', name=name) + +@app.route('/about') +def about(): + return render_template('about.html') + +@app.route('/contact') +def contact(): + return render_template('contact.html') + +@app.route('/check-grade/') +def check_grade(grade): + return render_template('check_grade.html', grade=grade) + +@app.route('/llama', methods=['post']) +def display_name(): + name = request.form['username'] + return render_template('contact.html', name=name) \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/flask/static/style.css b/Code/will/html_css/notes_and_practice/flask/static/style.css new file mode 100644 index 00000000..d29c110a --- /dev/null +++ b/Code/will/html_css/notes_and_practice/flask/static/style.css @@ -0,0 +1,4 @@ +body { + text-align: center; + background-color: gray; +} diff --git a/Code/will/html_css/notes_and_practice/flask/templates/about.html b/Code/will/html_css/notes_and_practice/flask/templates/about.html new file mode 100644 index 00000000..3184da1f --- /dev/null +++ b/Code/will/html_css/notes_and_practice/flask/templates/about.html @@ -0,0 +1,16 @@ + + + + + + + + About + + + Home + Contact Us +

    This is the about page.

    + + + \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/flask/templates/check_grade.html b/Code/will/html_css/notes_and_practice/flask/templates/check_grade.html new file mode 100644 index 00000000..14a3140c --- /dev/null +++ b/Code/will/html_css/notes_and_practice/flask/templates/check_grade.html @@ -0,0 +1,30 @@ + + + + + + + + Grade Check + + +

    Grade Checker

    + + {% if grade >= 90 %} +

    You got an A!

    + + {% elif grade >= 80 %} +

    You got a B!

    + + {% elif grade >= 70 %} +

    You got a C.

    + + {% elif grade >= 60 %} +

    You got a D.

    + + {% else %} +
    You got an F.
    + + {% endif %} + + \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/flask/templates/contact.html b/Code/will/html_css/notes_and_practice/flask/templates/contact.html new file mode 100644 index 00000000..eb46a055 --- /dev/null +++ b/Code/will/html_css/notes_and_practice/flask/templates/contact.html @@ -0,0 +1,16 @@ + + + + + + + + Contact Us + + + Home + About +

    This is our contact page.

    +

    Welcome {{ name }}

    + + \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/flask/templates/index.html b/Code/will/html_css/notes_and_practice/flask/templates/index.html new file mode 100644 index 00000000..3cf2242b --- /dev/null +++ b/Code/will/html_css/notes_and_practice/flask/templates/index.html @@ -0,0 +1,21 @@ + + + + + + + + Flask + + + About + Contact Us +

    Welcome to my Flask app!

    +

    Hello {{ name }}

    + +
    + + +
    + + \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/frameworks/materialize.html b/Code/will/html_css/notes_and_practice/frameworks/materialize.html new file mode 100644 index 00000000..380848ac --- /dev/null +++ b/Code/will/html_css/notes_and_practice/frameworks/materialize.html @@ -0,0 +1,33 @@ + + + + + + + + + Materialize Example + + + + + + Link to Somewhere +

    Hello There

    +

    General Kenobi

    + +

    + Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore enim asperiores autem eligendi tenetur ipsam reiciendis cupiditate placeat, sunt aliquid recusandae ipsum blanditiis laborum, dolorum iusto tempora, laudantium quaerat sint. +

    + + \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/html_forms/index.html b/Code/will/html_css/notes_and_practice/html_forms/index.html new file mode 100644 index 00000000..40ae671d --- /dev/null +++ b/Code/will/html_css/notes_and_practice/html_forms/index.html @@ -0,0 +1,53 @@ + + + + + + + + HTML Forms + + +
    + + + + +
    + + + +
    + + + +
    + + + + + + + + + + +
    + + + +
    + + + + + + + +
    + + \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/html_forms/style.css b/Code/will/html_css/notes_and_practice/html_forms/style.css new file mode 100644 index 00000000..458132e8 --- /dev/null +++ b/Code/will/html_css/notes_and_practice/html_forms/style.css @@ -0,0 +1,3 @@ +body { + background-color: grey; +} diff --git a/Code/will/html_css/notes_and_practice/responsive_design/index.html b/Code/will/html_css/notes_and_practice/responsive_design/index.html new file mode 100644 index 00000000..242f1709 --- /dev/null +++ b/Code/will/html_css/notes_and_practice/responsive_design/index.html @@ -0,0 +1,80 @@ + + + + + + + + Responsive Design + + +
    +

    Class Kiwi

    + +
    +
    + +
    +
    +
    +

    Title 1

    +

    + Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil earum + rerum porro ducimus, rem dolorum, nisi qui possimus, assumenda + quisquam ipsum aliquam nostrum velit exercitationem harum similique. + Dolorem, nostrum sequi. +

    +
    +
    +

    Title 2

    +

    + Architecto corrupti, veritatis ullam facilis odit nihil, deleniti + soluta accusantium, corporis iste dolore! A itaque deleniti + dignissimos cum, consequuntur natus aliquam nemo ex aut non obcaecati + ipsum perferendis reiciendis exercitationem. +

    +
    +
    +

    Title 3

    +

    + Pariatur voluptas ratione illo asperiores ad, non fugiat. Harum, saepe + veniam. Facere provident reiciendis odit aliquam repudiandae eligendi. + Ipsa suscipit delectus deleniti officiis quod deserunt asperiores + blanditiis amet corrupti quaerat! +

    +
    +
    +

    Title 4

    +

    + Culpa quisquam, eos sapiente, aliquid fuga dolorem repudiandae totam, + in molestias iste itaque ipsa! Quod adipisci possimus, natus sunt rem + voluptate odio obcaecati sit nihil suscipit nam harum. Nostrum, rerum. +

    +
    +
    +

    Title 5

    +

    + Qui odio aspernatur vero voluptatum, similique minus blanditiis et + cupiditate autem quia atque expedita, ducimus sequi, non vel totam ab. + Libero cumque eos assumenda dolorem officia, expedita sint dolorum + itaque! +

    +
    +
    +

    Title 6

    +

    + Deserunt perspiciatis excepturi ipsum consequatur aperiam quod veniam + distinctio doloribus. Velit, dignissimos sapiente error qui fugit, + ipsam ipsa cupiditate, illum eos expedita odio nesciunt omnis tenetur. + Officiis molestias aliquam quos! +

    +
    +
    +
    ©2022 Class Kiwi
    + + \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/responsive_design/style.css b/Code/will/html_css/notes_and_practice/responsive_design/style.css new file mode 100644 index 00000000..043e7f2f --- /dev/null +++ b/Code/will/html_css/notes_and_practice/responsive_design/style.css @@ -0,0 +1,101 @@ +body { + font-size: 24px; + display: flex; + flex-direction: column; + justify-content: center; +} + +body > * { + margin: 4px; +} + +h1 { + text-align: center; +} + +.links { + display: flex; + flex-direction: column; +} + +.links > a { + border: 1px solid black; + background-color: aqua; + margin: 0.5em 0.25em; + box-shadow: inset 0 0 8px 2px rgba(0, 0, 0, 0.89); + padding: 0.25em 0; + text-align: center; + text-decoration: none; +} + +img { + max-width: 100%; + display: flex; +} + +main { + display: flex; + flex-direction: column; + align-items: center; +} +section { + border: 1px solid black; + margin-bottom: 0.5em; + max-width: 54ch; +} + +section > p { + text-align: center; +} + +section > h1 { + text-decoration: underline; +} + +/* Tablet Styles */ +@media screen and (min-width: 768px) { + .links { + display: flex; + flex-direction: row; + justify-content: space-evenly; + } + + .links > a { + padding: 0.5em; + } + + img { + width: 650px; + } + + .hero { + display: flex; + justify-content: center; + } +} + +/* Desktop Styles */ +@media screen and (min-width: 1440px) { + header { + display: flex; + align-items: center; + justify-content: space-around; + } + + img { + max-width: 900px; + } + + main { + flex-flow: row wrap; + justify-content: center; + } + + .links { + display: block; + } + + .links > a { + padding: 0.2em; + } +} diff --git a/Code/will/html_css/notes_and_practice/rock_paper_scissors/app.py b/Code/will/html_css/notes_and_practice/rock_paper_scissors/app.py new file mode 100644 index 00000000..92be2357 --- /dev/null +++ b/Code/will/html_css/notes_and_practice/rock_paper_scissors/app.py @@ -0,0 +1,45 @@ +from flask import Flask, render_template, request +import random + +app = Flask(__name__) + +# localhost:5000/ +@app.route('/') +def index(): + return render_template('index.html') + +@app.route('/results', methods=['post']) +def results(): + outcome = request.form + + user = outcome['rps'] + comp = random.choice(['rock', 'paper', 'scissors']) + + if user == comp: + message = 'It is a tie!' + + elif user == 'rock': + if comp == 'scissors': + message = 'You win!' + + else: + message = 'Computer wins' + elif user == 'paper': + if comp == 'rock': + message = 'You win!' + + else: + message = 'Computer wins' + + elif user == 'scissors': + if comp == 'paper': + message = 'You win!' + + else: + message = 'Computer wins' + + return render_template('results.html', user=user, comp=comp, message=message) + +#@app.route('/contact') +#def contact(): +# return render_template('contact.html') \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/rock_paper_scissors/templates/index.html b/Code/will/html_css/notes_and_practice/rock_paper_scissors/templates/index.html new file mode 100644 index 00000000..aea6f473 --- /dev/null +++ b/Code/will/html_css/notes_and_practice/rock_paper_scissors/templates/index.html @@ -0,0 +1,25 @@ + + + + + + + Rock, Paper, Scissors + + +

    Welcome to Rock, Paper, Scissors!

    + +
    + + + + + + + + + + +
    + + \ No newline at end of file diff --git a/Code/will/html_css/notes_and_practice/rock_paper_scissors/templates/results.html b/Code/will/html_css/notes_and_practice/rock_paper_scissors/templates/results.html new file mode 100644 index 00000000..a7bc257a --- /dev/null +++ b/Code/will/html_css/notes_and_practice/rock_paper_scissors/templates/results.html @@ -0,0 +1,18 @@ + + + + + + + {{message}} + + +

    Results:

    + +

    You chose {{user}}

    +

    The computer chose {{comp}}

    +

    {{message}}

    + + Play again? + + \ No newline at end of file diff --git a/Code/will/javascript/Labs/javascript_redo/app.js b/Code/will/javascript/Labs/javascript_redo/app.js new file mode 100644 index 00000000..78f31adc --- /dev/null +++ b/Code/will/javascript/Labs/javascript_redo/app.js @@ -0,0 +1,36 @@ +const button = document.querySelector('#submit') +const choiceInput = document.querySelector('.choice-input') +var compChoices = ["rock", "paper", "scissors"] + + +button.addEventListener('click', function(e){ + e.preventDefault() + const compSelect = compChoices[(Math.random() * compChoices.length) | 0] + playerChoice = choiceInput.value + playerChoice = playerChoice.toLowerCase() + console.log(playerChoice) + console.log(compSelect) + + if(playerChoice === compSelect){ + alert("It's a tie!") + }else if(playerChoice === 'rock'){ + if(compSelect === 'scissors'){ + alert("You win!") + }else if(compSelect === 'paper'){ + alert("You lose.") + } + }else if(playerChoice === 'paper'){ + if(compSelect === 'rock'){ + alert("You win!") + }else if(compSelect === 'scissors'){ + alert("You lose.") + } + }else if(playerChoice === 'scissors'){ + if(compSelect === 'paper'){ + alert("You win!") + }else if(compSelect === 'rock'){ + alert("You lose.") + } + } + choiceInput.value = '' +}) \ No newline at end of file diff --git a/Code/will/javascript/Labs/javascript_redo/index.html b/Code/will/javascript/Labs/javascript_redo/index.html new file mode 100644 index 00000000..1c37aa31 --- /dev/null +++ b/Code/will/javascript/Labs/javascript_redo/index.html @@ -0,0 +1,19 @@ + + + + + + + + Rock Paper Scissors + + +

    Rock, Paper, or Scissors?

    + +
    + + + +
    + + \ No newline at end of file diff --git a/Code/will/javascript/Labs/todo_list/app.js b/Code/will/javascript/Labs/todo_list/app.js new file mode 100644 index 00000000..57995603 --- /dev/null +++ b/Code/will/javascript/Labs/todo_list/app.js @@ -0,0 +1,38 @@ +const button = document.querySelector("#submit") +const todoList = document.querySelector('#todo-list') +const todoItems = todoList.children +const nameInput = document.querySelector('.name-input') +const taskList = document.getElementsByTagName('li') + +//LISTENERS +button.addEventListener('click', function(e){ + e.preventDefault() + const newItem = document.createElement('li') + newItem.classList.add('item') + newItem.innerText = nameInput.value + todoList.appendChild(newItem) + nameInput.value = '' + + newItem.addEventListener('dblclick', deleteItem) +}) + +todoList.addEventListener('click', function(){ + todoList.classList.toggle('fade') + +}) + +todoList.addEventListener('click', function(){ + +}) + +todoList.addEventListener('click', markComplete) + +function deleteItem(e){ + e.stopPropagation() + e.target.remove() +} + +function markComplete(e){ + e.stopPropagation() + e.target.style.setProperty("text-decoration", "line-through") +} \ No newline at end of file diff --git a/Code/will/javascript/Labs/todo_list/index.html b/Code/will/javascript/Labs/todo_list/index.html new file mode 100644 index 00000000..a3ae800f --- /dev/null +++ b/Code/will/javascript/Labs/todo_list/index.html @@ -0,0 +1,21 @@ + + + + + + + + Todo List + + +

    To Do:

    +
      + +
    + +
    + + +
    + + \ No newline at end of file diff --git a/Code/will/javascript/Labs/vue_redo/index.html b/Code/will/javascript/Labs/vue_redo/index.html new file mode 100644 index 00000000..06aa8c0c --- /dev/null +++ b/Code/will/javascript/Labs/vue_redo/index.html @@ -0,0 +1,68 @@ + + + + + + + + + + + + Rock, Paper, Scissors + + + +
    +
    +
    +

    Rock, Paper, Scissors

    +
    + +
    +

    Player's Choice

    +
    + +
    +

    Opponent's Choice

    +
    + +
    + [[playerResult]] +
    + +
    + [[compResult]] +
    + + +
    + + + +
    +
    +
    + + + + + \ No newline at end of file diff --git a/Code/will/javascript/practice/APIs/app.js b/Code/will/javascript/practice/APIs/app.js new file mode 100644 index 00000000..292b9f66 --- /dev/null +++ b/Code/will/javascript/practice/APIs/app.js @@ -0,0 +1,42 @@ +// ************* FETCH REQUEST ************** +// console.log(fetch('http://jsonplaceholder.typicode.com/posts/1')) + +// fetch('http://jsonplaceholder.typicode.com/posts/1') +// .then(function(response){ +// return response.json +// }) +// .then(function(data){ +// console.log(data) +// console.log(data.title) +// console.log(data.id) +// }) + + +// ********** POST REQUEST ************ +// const blogPost = { +// title: "Kiwi Post", +// body: "Class Kiwi 2022", +// userId: 1 +// } + +// fetch('http://jsonplaceholder.typicode.com/posts', { +// method: "POST", +// headers: {"Content-Type": "application/json"}, +// body: JSON.stringify(blogPost) +// }) +// .then(function(response){ +// return response.json() +// }) +// .then(function(data){ +// console.log(data) +// }) + +fetch('http://jsonplaceholder.typicode.com/postss/1') +.then(function(response){ + if(!response.ok) + return new Error('Bad Requests ') +}) +.then(function(data){ + console.log(data) +}) + diff --git a/Code/will/javascript/practice/APIs/index.html b/Code/will/javascript/practice/APIs/index.html new file mode 100644 index 00000000..5f8062be --- /dev/null +++ b/Code/will/javascript/practice/APIs/index.html @@ -0,0 +1,13 @@ + + + + + + + + API + + +

    API/Fetch Introduction

    + + \ No newline at end of file diff --git a/Code/will/javascript/practice/DOM/app.js b/Code/will/javascript/practice/DOM/app.js new file mode 100644 index 00000000..e82d5cd9 --- /dev/null +++ b/Code/will/javascript/practice/DOM/app.js @@ -0,0 +1,75 @@ +// const headers = document.getElementsByTagName('h2') +// console.log(headers) +// console.log(headers[1]) + +// const list = document.getElementsByClassName('item') +// console.log(list) + +// const button = document.getElementById('submit') //getElementById gets first instance of given Id +// console.log(button) + +// const headers = document.querySelectorAll('h2') +// console.log(headers) + +// const list = document.querySelectorAll('.item') // reference classes with .classname, id with #id +// console.log(list) + +// const list = document.querySelector('#list a') +// console.log(list) + +//SELECTORS +// const button = document.querySelector('#submit') + + +//LISTENERS +// button.addEventListener('click', function(){ +// console.log('Test Button') +// }) + +// button.addEventListener('click', addItem) +// function addItem(){ +// console.log('Test Button') +// } + +//SELECTORS +const button = document.querySelector('#submit') +const todoList = document.querySelector('#todo-list') +const todoItems = todoList.children +const todoNum = document.querySelector('.todo-num b') +const mainTitle = document.querySelector('.main-title') +const nameInput = document.querySelector('.name-input') + +//LISTENERS +button.addEventListener('click', function(e){ + e.preventDefault() + const newItem = document.createElement('li') + newItem.classList.add('item') + // newItem.innerText = `Item ${todoItems.length + 1}` + newItem.innerText = nameInput.value + todoList.appendChild(newItem) + nameInput.value = '' + + newItem.addEventListener('click', deleteItem) +}) + +button.addEventListener('click', function(){ mainTitle.style.color = 'blue' + mainTitle.style.fontSize = '2.5rem' +}) + +// for (item of items){ +// item.addEventListener('click', deleteItem) +// } + +todoList.addEventListener('click', function(){ + todoList.classList.toggle('fade') + +}) + + +function deleteItem(e){ + // console.log(e) + // console.log(e.target) + e.stopPropagation() + e.target.remove() + todoNum.innerText = todoItems.length +} \ No newline at end of file diff --git a/Code/will/javascript/practice/DOM/index.html b/Code/will/javascript/practice/DOM/index.html new file mode 100644 index 00000000..a55e231b --- /dev/null +++ b/Code/will/javascript/practice/DOM/index.html @@ -0,0 +1,23 @@ + + + + + + + + + DOM + + +

    Javascript - Working with DOM

    +
      +
    + +

    Number of items:

    +
    + + + +
    + + \ No newline at end of file diff --git a/Code/will/javascript/practice/DOM/style.css b/Code/will/javascript/practice/DOM/style.css new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/javascript/practice/cards_api/app.js b/Code/will/javascript/practice/cards_api/app.js new file mode 100644 index 00000000..02b37447 --- /dev/null +++ b/Code/will/javascript/practice/cards_api/app.js @@ -0,0 +1,97 @@ +const shuffleBtn = document.querySelector("#shuffle-btn") +const dealBtn = document.querySelector("#deal-btn") +let deckID = null +let hands = { + dealer: [], + player: [] +} + + +shuffleBtn.addEventListener("click", getCards) +dealBtn.addEventListener("click", dealCards) + + +///// ASYNC WAIT METHOD ///// +async function getCards(){ + const response = await fetch("http://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=6") + const data = await response.json() + console.log(data) + deckID = data.deck_id +} + + +async function dealCards(){ + const url = `http://deckofcardsapi.com/api/deck/${deckID}/draw/?count=4` + const response = await fetch(url) + const data = await response.json() + + hands.dealer = data.cards.splice(0, 2) + hands.player = data.cards + console.log(data) + playerValue = showCards() + dealerValue = showCards(true) + whoWins(playerValue, dealerValue) +} + + +function addHand(value){ + const strValue = value + let intValue = 0 + if(strValue == 'KING'){ + intValue =10 + }else if(strValue == 'QUEEN'){ + intValue =10 + }else if(strValue == 'JACK'){ + intValue = 10 + }else if(strValue == 'ACE'){ + intValue = 11 + }else{ + intValue = parseInt(value) + } + return intValue +} + + + + + +function showCards(dealer = false){ + const hand = dealer ? hands.dealer : hands.player + const selector = dealer ? '#dealer' : '#player' + let handValue = 0 + const handContainer = document.querySelector(selector) + handContainer.innerHTML = '' + + for(card of hand){ + const cardImage = document.createElement('img') + cardImage.src = card.image + handContainer.append(cardImage) + cardValue = addHand(card.value) + handValue += cardValue + } + return handValue +} + + +function whoWins(playerValue, dealerValue){ + if(playerValue > dealerValue && playerValue <= 21){ + alert('You Win!') + }else if(dealerValue > playerValue && dealerValue <= 21){ + alert('Dealer Wins.') + }else if(dealerValue = playerValue){ + alert('Push.') + } +} + + + + + +///// DOT THEN METHOD ///// +// fetch("http://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1") +// .then(function(data){ +// return data.json() +// } +// ).then(function(data){ +// console.log(data) +// }) diff --git a/Code/will/javascript/practice/cards_api/index.html b/Code/will/javascript/practice/cards_api/index.html new file mode 100644 index 00000000..0545e920 --- /dev/null +++ b/Code/will/javascript/practice/cards_api/index.html @@ -0,0 +1,20 @@ + + + + + + + + BlackJack + + +
    + + +
    +

    Your Hand

    +
    +

    Dealer's Hand

    +
    + + \ No newline at end of file diff --git a/Code/will/javascript/practice/intro/app.js b/Code/will/javascript/practice/intro/app.js new file mode 100644 index 00000000..a9b79f2e --- /dev/null +++ b/Code/will/javascript/practice/intro/app.js @@ -0,0 +1,99 @@ +// //alert('Hello World') +// console.log('Hello Class Kiwi') +// console.warn('Something is up...') +// console.info('Page Loaded') + +// //let userInput = prompt('How is your day?') + +// const favColor = 'Orange' //Unchanging variable, constant +// console.log(favColor, 'My favorite color') + +// let lastName = 'Smith' //changeable variable + +// let color = 'bluegreen' +// console.log(typeof color) // returns string + +// let numOne = 1 +// console.log(typeof numOne) // returns int + +// Data Types +// 'Hello World' //string +// "Hello World" //string + +// 4 //number +// 4.7 //number (not a float) + +// true //Boolean +// false //Boolean + +// [1,2,3] //array (works like a list) + +// {name: 'Tom'} //Object (works like a dictionary) + +// undefined //undefined (value does not exist) +// null //intentional absence of value + +// console.log(x) +// let x = 24 + ' Tomorrow' + +// let number = 5 +// console.log(number == '5') // 5 is equal to int 5 and string 5 + +// let number = 5 +// console.log(number === '5') // number IS a string, no coercion + +// let a = 1 // number (Js) int(Py) +// let b = 1.2 //number(Js) float(Py) +// let c = 123e7 //large number +// let d = 123e-7 //scientific notation + +// let number = 5 +// if (number < 10){ +// console.log('Hooray!') +// }else if(number>10){ +// console.log('This is a large number.') +// }else{ +// console.log('This number is 10.') +// } + +// let person = { +// firstName: 'John', +// lastName: 'Snow', +// age: 30, + +// pets: { +// dog: 'Spot', +// cat: 'Claudius' +// } +// } +// console.log(person) +// console.log(person['firstName']) +// console.log(person.lastName) + +// //update.age +// person.age = 40 + +//increment age +// person.age ++ // adds 1 +// person.age += 2 + +// reference nested object +// console.log(person.pets['dog']) + +// function sayHello(){ +// let color = 'blue' +// return color +// } + +// console.log(sayHello()) + +// function addNums(num1, num2){ +// return num1 + num2 +// } + +// console.log(addNums(3,5)) + +// const arrowFunct = (num1, num2) => { +// return num1 + num2 +// } +// console.log(arrowFunct(2,8)) \ No newline at end of file diff --git a/Code/will/javascript/practice/intro/index.html b/Code/will/javascript/practice/intro/index.html new file mode 100644 index 00000000..2465678a --- /dev/null +++ b/Code/will/javascript/practice/intro/index.html @@ -0,0 +1,13 @@ + + + + + + + + Intro + + +

    Javascript Intro

    + + \ No newline at end of file diff --git a/Code/will/javascript/practice/intro2/app.js b/Code/will/javascript/practice/intro2/app.js new file mode 100644 index 00000000..ee6512d0 --- /dev/null +++ b/Code/will/javascript/practice/intro2/app.js @@ -0,0 +1,63 @@ +// var user +// user = 'Lisa' + +// console.log(user) + +// Js variables accept letters, numbers (not leading), and % _ symbols + +// message = 'Hello World' +// console.log(window) +// console.log(window.message) + +// window.console.log('hello') +// console = 'hello' +// console.log('hello') + +// let day +// day = 'Tuesday' +// console.log(day) +// day = 'Friday' +// console.log(day) + +// const numbers = [3,4] + +// numbers.push(5,6) +// console.log(numbers) + +// numbers.unshift(1,2) +// console.log(numbers) + +// numbers.splice(2,0,'a','b') +// console.log(numbers) + +// const numbers = [1,2,3,4] +// console.log(numbers) +// const last = numbers.pop() +// console.log(last) + +// const first = numbers.shift() +// console.log(first) +// console.log(numbers) + +// numbers.push(7,9) +// console.log(numbers) +// // numbers.splice(1, 2) +// // console.log(numbers) +// console.log(numbers.indexOf('2')) +// console.log(numbers.indexOf(9)) +// console.log(numbers.includes(2)) + +// numbers.push(3) +// console.log(numbers) +// console.log(numbers.lastIndexOf(2)) + +// const courses = [ +// {id: 1, name: 'apple'}, +// {id: 2, name: 'banana'}, +// {id: 3, name: 'pear'} +// ] + +// const course = courses.find(function(course){ +// return course.name === 'apple' +// }) +// console.log(course.name) \ No newline at end of file diff --git a/Code/will/javascript/practice/intro2/index.html b/Code/will/javascript/practice/intro2/index.html new file mode 100644 index 00000000..7032d5cc --- /dev/null +++ b/Code/will/javascript/practice/intro2/index.html @@ -0,0 +1,13 @@ + + + + + + + + Intro Pt.2 + + +

    Javascript Day 2

    + + \ No newline at end of file diff --git a/Code/will/javascript/practice/vue/.gitignore b/Code/will/javascript/practice/vue/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/Code/will/javascript/practice/vue/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Code/will/javascript/practice/vue/index.html b/Code/will/javascript/practice/vue/index.html new file mode 100644 index 00000000..450212bf --- /dev/null +++ b/Code/will/javascript/practice/vue/index.html @@ -0,0 +1,111 @@ + + + + + + + + + + + + + Document + + + +
    +

    {{headerText}}

    + +
    +
    + + +
    + + +
    +

    Incomplete

    +
    + {{todo.id}} {{todo.text}} +
    + + +
    +
    +
    + +
    +

    Complete

    +
    + + {{todo.id}} {{todo.text}} + +
    + + +
    +
    +
    +
    +
    + + + + + + + \ No newline at end of file diff --git a/Code/will/javascript/practice/vue/manage.py b/Code/will/javascript/practice/vue/manage.py new file mode 100644 index 00000000..3a1054e8 --- /dev/null +++ b/Code/will/javascript/practice/vue/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', 'todoAPI_proj.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/Code/will/javascript/practice/vue/styles.css b/Code/will/javascript/practice/vue/styles.css new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/javascript/practice/vue/todoAPI_proj/__init__.py b/Code/will/javascript/practice/vue/todoAPI_proj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/javascript/practice/vue/todoAPI_proj/asgi.py b/Code/will/javascript/practice/vue/todoAPI_proj/asgi.py new file mode 100644 index 00000000..afcf347d --- /dev/null +++ b/Code/will/javascript/practice/vue/todoAPI_proj/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for todoAPI_proj 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todoAPI_proj.settings') + +application = get_asgi_application() diff --git a/Code/will/javascript/practice/vue/todoAPI_proj/settings.py b/Code/will/javascript/practice/vue/todoAPI_proj/settings.py new file mode 100644 index 00000000..bd79fc17 --- /dev/null +++ b/Code/will/javascript/practice/vue/todoAPI_proj/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for todoAPI_proj project. + +Generated by 'django-admin startproject' using Django 4.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" +from decouple import config +from pathlib import Path + +# 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/4.0/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 = True + +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', + 'todo_app', +] + +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 = 'todoAPI_proj.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 = 'todoAPI_proj.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Chicago' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/will/javascript/practice/vue/todoAPI_proj/urls.py b/Code/will/javascript/practice/vue/todoAPI_proj/urls.py new file mode 100644 index 00000000..648db019 --- /dev/null +++ b/Code/will/javascript/practice/vue/todoAPI_proj/urls.py @@ -0,0 +1,23 @@ +"""todoAPI_proj URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/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 + +urlpatterns = [ + path('api-auth/', include('rest_framework.urls')), + path('admin/', admin.site.urls), + path('index/', include('todo_app.urls')), +] diff --git a/Code/will/javascript/practice/vue/todoAPI_proj/wsgi.py b/Code/will/javascript/practice/vue/todoAPI_proj/wsgi.py new file mode 100644 index 00000000..22651897 --- /dev/null +++ b/Code/will/javascript/practice/vue/todoAPI_proj/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for todoAPI_proj 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todoAPI_proj.settings') + +application = get_wsgi_application() diff --git a/Code/will/javascript/practice/vue/todo_app/__init__.py b/Code/will/javascript/practice/vue/todo_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/javascript/practice/vue/todo_app/admin.py b/Code/will/javascript/practice/vue/todo_app/admin.py new file mode 100644 index 00000000..9d284016 --- /dev/null +++ b/Code/will/javascript/practice/vue/todo_app/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import * + +# Register your models here. +admin.site.register(TodoItem) diff --git a/Code/will/javascript/practice/vue/todo_app/apps.py b/Code/will/javascript/practice/vue/todo_app/apps.py new file mode 100644 index 00000000..d8f1498d --- /dev/null +++ b/Code/will/javascript/practice/vue/todo_app/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TodoAppConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'todo_app' diff --git a/Code/will/javascript/practice/vue/todo_app/migrations/0001_initial.py b/Code/will/javascript/practice/vue/todo_app/migrations/0001_initial.py new file mode 100644 index 00000000..199b458e --- /dev/null +++ b/Code/will/javascript/practice/vue/todo_app/migrations/0001_initial.py @@ -0,0 +1,22 @@ +# Generated by Django 4.0.3 on 2022-05-12 01:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='TodoItem', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('text', models.CharField(max_length=500)), + ('completed', models.BooleanField(default=False)), + ], + ), + ] diff --git a/Code/will/javascript/practice/vue/todo_app/migrations/__init__.py b/Code/will/javascript/practice/vue/todo_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/will/javascript/practice/vue/todo_app/models.py b/Code/will/javascript/practice/vue/todo_app/models.py new file mode 100644 index 00000000..a54aa1e3 --- /dev/null +++ b/Code/will/javascript/practice/vue/todo_app/models.py @@ -0,0 +1,11 @@ +from django.db import models + +# Create your models here. + + +class TodoItem(models.Model): + text = models.CharField(max_length=500) + completed = models.BooleanField(default=False) + + def __str__(self): + return self.text diff --git a/Code/will/javascript/practice/vue/todo_app/serializers.py b/Code/will/javascript/practice/vue/todo_app/serializers.py new file mode 100644 index 00000000..427e9de7 --- /dev/null +++ b/Code/will/javascript/practice/vue/todo_app/serializers.py @@ -0,0 +1,8 @@ +from rest_framework import serializers +from .models import * + + +class TodoSerializer(serializers.ModelSerializer): + class Meta: + model = TodoItem + fields = '__all__' diff --git a/Code/will/javascript/practice/vue/todo_app/templates/todo_app/index.html b/Code/will/javascript/practice/vue/todo_app/templates/todo_app/index.html new file mode 100644 index 00000000..6bd01927 --- /dev/null +++ b/Code/will/javascript/practice/vue/todo_app/templates/todo_app/index.html @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + Vue + + + {% csrf_token %} + +
    +

    [[headerText]]

    + +
    +
    + + +
    + + +
    +

    Incomplete

    +
    + [[todo.id]] [[todo.text]] +
    + + +
    +
    +
    + +
    +

    Complete

    +
    + + [[todo.id]] [[todo.text]] + +
    + + +
    +
    +
    +
    +
    + + + + + + + \ No newline at end of file diff --git a/Code/will/javascript/practice/vue/todo_app/tests.py b/Code/will/javascript/practice/vue/todo_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/will/javascript/practice/vue/todo_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/will/javascript/practice/vue/todo_app/urls.py b/Code/will/javascript/practice/vue/todo_app/urls.py new file mode 100644 index 00000000..d7afcdc0 --- /dev/null +++ b/Code/will/javascript/practice/vue/todo_app/urls.py @@ -0,0 +1,12 @@ +from django.urls import path +from . import views + +app_name = 'todo_app' +urlpatterns = [ + path('', views.index, name='index'), + path('list/', views.todo_list, name='todo_list'), + path('create/', views.create_todo, name='create_todo'), + path('toggle-complete/', + views.toggle_complete, name='toggle_complete'), + path('delete/', views.delete_todo, name='delete-todo') +] diff --git a/Code/will/javascript/practice/vue/todo_app/views.py b/Code/will/javascript/practice/vue/todo_app/views.py new file mode 100644 index 00000000..7896594a --- /dev/null +++ b/Code/will/javascript/practice/vue/todo_app/views.py @@ -0,0 +1,98 @@ +from django.shortcuts import render, get_object_or_404 +from rest_framework.decorators import api_view +from rest_framework.response import Response +from .models import * +from .serializers import TodoSerializer + +# Create your views here. + + +def index(request): + return render(request, 'todo_app/index.html') + + +@api_view(["GET"]) +def todo_list(request): + response = Response() + + todos = TodoItem.objects.all() + + todo_serializer = TodoSerializer(todos, many=True) + + response.data = { + 'todos': todo_serializer.data + } + + return response + + +@api_view(["POST"]) +def create_todo(request): + response = Response() + + # extract new todo from request data + new_todo_text = request.data.get('new_todo_text') + + # instantiate TodoSerializer with text from the request + todo_serialzer = TodoSerializer(data={'text': new_todo_text}) + + # if serializer fields are valid + if todo_serialzer.is_valid(): + # create new todo object in DB + todo_serialzer.save() + + # pull all todos from DB + todos = TodoItem.objects.all() + + # serialize + todo_serialzer = TodoSerializer(todos, many=True) + + # attach data to response + response.data = { + 'todos': todo_serialzer.data + } + + return response + + +@api_view(["POST"]) +def toggle_complete(request, todo_id): + response = Response() + + # pass TodoItm class where classid = id passed in + todo = get_object_or_404(TodoItem, id=todo_id) + + # flip boolean + todo.completed = not todo.completed + todo.save() + + # get all todos from DB + todos = TodoItem.objects.all() + + # serialize + todo_serialzier = TodoSerializer(todos, many=True) + + response.data = { + 'todos': todo_serialzier.data + } + + return response + + +@api_view(["POST"]) +def delete_todo(request, todo_id): + response = Response() + + todo = get_object_or_404(TodoItem, id=todo_id) + + todo.delete() + + todos = TodoItem.objects.all() + + todo_serializer = TodoSerializer(todos, many=True) + + response.data = { + 'todos': todo_serializer.data + } + + return response