diff --git a/Code/eric/django_projects/grocery/grocery_app/__init__.py b/Code/eric/django_projects/grocery/grocery_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/eric/django_projects/grocery/grocery_app/admin.py b/Code/eric/django_projects/grocery/grocery_app/admin.py new file mode 100644 index 00000000..95b665dd --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_app/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/eric/django_projects/grocery/grocery_app/apps.py b/Code/eric/django_projects/grocery/grocery_app/apps.py new file mode 100644 index 00000000..87b0bfcb --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_app/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class GroceryAppConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'grocery_app' diff --git a/Code/eric/django_projects/grocery/grocery_app/migrations/0001_initial.py b/Code/eric/django_projects/grocery/grocery_app/migrations/0001_initial.py new file mode 100644 index 00000000..cd5fbdc3 --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_app/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 3.2.12 on 2022-04-13 01:32 + +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='grocery_app.department')), + ], + ), + ] diff --git a/Code/eric/django_projects/grocery/grocery_app/migrations/__init__.py b/Code/eric/django_projects/grocery/grocery_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/eric/django_projects/grocery/grocery_app/models.py b/Code/eric/django_projects/grocery/grocery_app/models.py new file mode 100644 index 00000000..5ea247c2 --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_app/models.py @@ -0,0 +1,19 @@ +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} ' + + + \ No newline at end of file diff --git a/Code/eric/django_projects/grocery/grocery_app/templates/grocery_app/index.html b/Code/eric/django_projects/grocery/grocery_app/templates/grocery_app/index.html new file mode 100644 index 00000000..f19446ee --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_app/templates/grocery_app/index.html @@ -0,0 +1,48 @@ + + + + + + + Grocery + + +

My Grocery

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

{{department.name}}

+ +
+ {% endfor %} +
+ + + + \ No newline at end of file diff --git a/Code/eric/django_projects/grocery/grocery_app/tests.py b/Code/eric/django_projects/grocery/grocery_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/eric/django_projects/grocery/grocery_app/urls.py b/Code/eric/django_projects/grocery/grocery_app/urls.py new file mode 100644 index 00000000..1cea3b37 --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_app/urls.py @@ -0,0 +1,13 @@ +from django.urls import path +from .import views + +app_name = 'grocery_list' + +urlpatterns = [ + + path('', views.index, name='index'), + path('add_item', views.add_item, name='add'), + path('buy//', views.buy_item, name='buy'), + path('delete//', views.delete_item, name='delete'), + +] diff --git a/Code/eric/django_projects/grocery/grocery_app/views.py b/Code/eric/django_projects/grocery/grocery_app/views.py new file mode 100644 index 00000000..10f2ed0e --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_app/views.py @@ -0,0 +1,40 @@ +from django.shortcuts import render +from .models import * +#from .import models # results in leading models -> models.GroceryItem +from django.http import HttpResponseRedirect +from django.urls import reverse + +# Create your views here. +def index(request): + grocery_list = GroceryItem.objects.all().order_by('department') + departments = Department.objects.all().order_by('name') + + return render(request, 'grocery_app/index.html',{ + 'grocery_list': grocery_list, + 'departments': departments + }) + +def add_item(request): + item_text = request.POST['item'] + department_id = request.POST['department'] + new_item = GroceryItem() + new_item.item = item_text + if department_id: + department = Department.objects.get(id=department_id) + new_item.department = department + new_item.save() + return HttpResponseRedirect(reverse('grocery_list:index')) + +def buy_item(request, item_id): + grocery_item = GroceryItem.objects.get(id=item_id) + grocery_item.completed = not grocery_item.completed + grocery_item.save() + return HttpResponseRedirect(reverse('grocery_list:index')) + +def delete_item(request, item_id): + grocery_item = GroceryItem.objects.get(id=item_id) + grocery_item.delete() + return HttpResponseRedirect(reverse('grocery_list:index')) + + + \ No newline at end of file diff --git a/Code/eric/django_projects/grocery/grocery_proj/__init__.py b/Code/eric/django_projects/grocery/grocery_proj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/eric/django_projects/grocery/grocery_proj/asgi.py b/Code/eric/django_projects/grocery/grocery_proj/asgi.py new file mode 100644 index 00000000..0e4a45b7 --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_proj/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for grocery_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/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'grocery_proj.settings') + +application = get_asgi_application() diff --git a/Code/eric/django_projects/grocery/grocery_proj/settings.py b/Code/eric/django_projects/grocery/grocery_proj/settings.py new file mode 100644 index 00000000..4c5bf2fc --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_proj/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for grocery_proj project. + +Generated by 'django-admin startproject' using Django 3.2.12. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-1el5co&ci&3w1iduh^v%oemq&opqom6!9bazki#0@sd!0*w562' + +# 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', + + 'grocery_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 = 'grocery_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_proj.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/New_York' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/eric/django_projects/grocery/grocery_proj/urls.py b/Code/eric/django_projects/grocery/grocery_proj/urls.py new file mode 100644 index 00000000..3b496c54 --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_proj/urls.py @@ -0,0 +1,22 @@ +"""grocery_proj URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('grocery_app.urls')) +] diff --git a/Code/eric/django_projects/grocery/grocery_proj/wsgi.py b/Code/eric/django_projects/grocery/grocery_proj/wsgi.py new file mode 100644 index 00000000..7b1ac5f5 --- /dev/null +++ b/Code/eric/django_projects/grocery/grocery_proj/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for grocery_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/3.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'grocery_proj.settings') + +application = get_wsgi_application() diff --git a/Code/eric/django_projects/grocery/manage.py b/Code/eric/django_projects/grocery/manage.py new file mode 100644 index 00000000..f97e4e6d --- /dev/null +++ b/Code/eric/django_projects/grocery/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_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/eric/django_projects/password/manage.py b/Code/eric/django_projects/password/manage.py new file mode 100755 index 00000000..4405e439 --- /dev/null +++ b/Code/eric/django_projects/password/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', 'password_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/eric/django_projects/password/password_app/__init__.py b/Code/eric/django_projects/password/password_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/eric/django_projects/password/password_app/admin.py b/Code/eric/django_projects/password/password_app/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/Code/eric/django_projects/password/password_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/Code/eric/django_projects/password/password_app/apps.py b/Code/eric/django_projects/password/password_app/apps.py new file mode 100644 index 00000000..025792aa --- /dev/null +++ b/Code/eric/django_projects/password/password_app/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class PasswordAppConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'password_app' diff --git a/Code/eric/django_projects/password/password_app/migrations/__init__.py b/Code/eric/django_projects/password/password_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/eric/django_projects/password/password_app/models.py b/Code/eric/django_projects/password/password_app/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/Code/eric/django_projects/password/password_app/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/Code/eric/django_projects/password/password_app/templates/password_app/index.html b/Code/eric/django_projects/password/password_app/templates/password_app/index.html new file mode 100644 index 00000000..4ac56ccd --- /dev/null +++ b/Code/eric/django_projects/password/password_app/templates/password_app/index.html @@ -0,0 +1,15 @@ + + + + + + + Password Generator + + +

Password Generator

+
+ +
+ + \ No newline at end of file diff --git a/Code/eric/django_projects/password/password_app/templates/password_app/password.html b/Code/eric/django_projects/password/password_app/templates/password_app/password.html new file mode 100644 index 00000000..21b09cdb --- /dev/null +++ b/Code/eric/django_projects/password/password_app/templates/password_app/password.html @@ -0,0 +1,15 @@ + + + + + + + Generated Password + + + +Your password is: +{{ password }} + + + \ No newline at end of file diff --git a/Code/eric/django_projects/password/password_app/tests.py b/Code/eric/django_projects/password/password_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/eric/django_projects/password/password_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/eric/django_projects/password/password_app/urls.py b/Code/eric/django_projects/password/password_app/urls.py new file mode 100644 index 00000000..e6c16bda --- /dev/null +++ b/Code/eric/django_projects/password/password_app/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index, name='index'), + path('password/', views.password, name='password'), +] \ No newline at end of file diff --git a/Code/eric/django_projects/password/password_app/views.py b/Code/eric/django_projects/password/password_app/views.py new file mode 100644 index 00000000..bed810ac --- /dev/null +++ b/Code/eric/django_projects/password/password_app/views.py @@ -0,0 +1,18 @@ +from django.shortcuts import render + +import random +# Create your views here. +def index(request): + return render(request, 'password_app/index.html') + +def password(request): + genPassword = '' + length = 14 + length = int(length) + characters = list('abcdefghijklmnopqrstuvwxyz£$%^&*!{}()ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') + + i=0 + while i < length: + i=i+1 + genPassword = genPassword + random.choice(characters) + return render(request, 'password_app/password.html', {'password': genPassword}) diff --git a/Code/eric/django_projects/password/password_proj/__init__.py b/Code/eric/django_projects/password/password_proj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/eric/django_projects/password/password_proj/asgi.py b/Code/eric/django_projects/password/password_proj/asgi.py new file mode 100644 index 00000000..a6807b04 --- /dev/null +++ b/Code/eric/django_projects/password/password_proj/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for password_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', 'password_proj.settings') + +application = get_asgi_application() diff --git a/Code/eric/django_projects/password/password_proj/settings.py b/Code/eric/django_projects/password/password_proj/settings.py new file mode 100644 index 00000000..0083c86a --- /dev/null +++ b/Code/eric/django_projects/password/password_proj/settings.py @@ -0,0 +1,125 @@ +""" +Django settings for password_proj project. + +Generated by 'django-admin startproject' using Django 4.0.4. + +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 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 = 'django-insecure-#v+lmc98j7ah@%ufm4z_pm(e3r$(7x#t+9&p^cgw#xkq1667tn' + +# 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', + + 'password_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 = 'password_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 = 'password_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 = 'UTC' + +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/eric/django_projects/password/password_proj/urls.py b/Code/eric/django_projects/password/password_proj/urls.py new file mode 100644 index 00000000..e393fac5 --- /dev/null +++ b/Code/eric/django_projects/password/password_proj/urls.py @@ -0,0 +1,22 @@ +"""password_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('', include('password_app.urls')) +] diff --git a/Code/eric/django_projects/password/password_proj/wsgi.py b/Code/eric/django_projects/password/password_proj/wsgi.py new file mode 100644 index 00000000..0447c024 --- /dev/null +++ b/Code/eric/django_projects/password/password_proj/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for password_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', 'password_proj.settings') + +application = get_wsgi_application() diff --git a/Code/eric/django_projects/todo/manage.py b/Code/eric/django_projects/todo/manage.py new file mode 100644 index 00000000..6be564d2 --- /dev/null +++ b/Code/eric/django_projects/todo/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/eric/django_projects/todo/todo_app/__init__.py b/Code/eric/django_projects/todo/todo_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/eric/django_projects/todo/todo_app/admin.py b/Code/eric/django_projects/todo/todo_app/admin.py new file mode 100644 index 00000000..4c66e470 --- /dev/null +++ b/Code/eric/django_projects/todo/todo_app/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import * + +# Register your models here. +admin.site.register(Task) diff --git a/Code/eric/django_projects/todo/todo_app/apps.py b/Code/eric/django_projects/todo/todo_app/apps.py new file mode 100644 index 00000000..d8f1498d --- /dev/null +++ b/Code/eric/django_projects/todo/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/eric/django_projects/todo/todo_app/forms.py b/Code/eric/django_projects/todo/todo_app/forms.py new file mode 100644 index 00000000..174083f6 --- /dev/null +++ b/Code/eric/django_projects/todo/todo_app/forms.py @@ -0,0 +1,10 @@ +from django import forms +from django.forms import ModelForm +from .models import * + +class TaskForm(forms.ModelForm): + class Meta: + model = Task + fields = '__all__' + + diff --git a/Code/eric/django_projects/todo/todo_app/migrations/0001_initial.py b/Code/eric/django_projects/todo/todo_app/migrations/0001_initial.py new file mode 100644 index 00000000..c887fbb6 --- /dev/null +++ b/Code/eric/django_projects/todo/todo_app/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.12 on 2022-04-05 02:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Task', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('complete', models.BooleanField(default=False)), + ('created', models.DateTimeField(auto_now_add=True)), + ], + ), + ] diff --git a/Code/eric/django_projects/todo/todo_app/migrations/__init__.py b/Code/eric/django_projects/todo/todo_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/eric/django_projects/todo/todo_app/models.py b/Code/eric/django_projects/todo/todo_app/models.py new file mode 100644 index 00000000..482842d0 --- /dev/null +++ b/Code/eric/django_projects/todo/todo_app/models.py @@ -0,0 +1,10 @@ +from django.db import models + +# Create your models here. +class Task(models.Model): + title = models.CharField(max_length=200) + complete = models.BooleanField(default=False) + created = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return self.title diff --git a/Code/eric/django_projects/todo/todo_app/templates/todo_app/delete.html b/Code/eric/django_projects/todo/todo_app/templates/todo_app/delete.html new file mode 100644 index 00000000..a55e235d --- /dev/null +++ b/Code/eric/django_projects/todo/todo_app/templates/todo_app/delete.html @@ -0,0 +1,18 @@ + + + + + + + Delete + + +

Do you really want to delete {{item}}

+ Cancel + +
+ {% csrf_token %} + +
+ + \ No newline at end of file diff --git a/Code/eric/django_projects/todo/todo_app/templates/todo_app/index.html b/Code/eric/django_projects/todo/todo_app/templates/todo_app/index.html new file mode 100644 index 00000000..16a2e937 --- /dev/null +++ b/Code/eric/django_projects/todo/todo_app/templates/todo_app/index.html @@ -0,0 +1,36 @@ + + + + + + + To DO + + +

To Do

+ +
+ {% csrf_token %} + {{form.title}} +
+ + {% for task in tasks %} +
+ Update + Delete + + + {% if task.complete %} + {{task}} + {% else %} + {{task}} + + {% endif %} + +
+ + {% endfor %} + + + + \ No newline at end of file diff --git a/Code/eric/django_projects/todo/todo_app/templates/todo_app/update.html b/Code/eric/django_projects/todo/todo_app/templates/todo_app/update.html new file mode 100644 index 00000000..c6c6fcf8 --- /dev/null +++ b/Code/eric/django_projects/todo/todo_app/templates/todo_app/update.html @@ -0,0 +1,20 @@ + + + + + + + Update + + +
+ {% csrf_token %} + + {{form}} + +
+ + + + + \ No newline at end of file diff --git a/Code/eric/django_projects/todo/todo_app/tests.py b/Code/eric/django_projects/todo/todo_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/eric/django_projects/todo/todo_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/eric/django_projects/todo/todo_app/urls.py b/Code/eric/django_projects/todo/todo_app/urls.py new file mode 100644 index 00000000..476dd071 --- /dev/null +++ b/Code/eric/django_projects/todo/todo_app/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from .import views + +urlpatterns = [ + path('', views.index, name='index'), + path('update/', views.updateTask, name='update'), + path('delete/', views.deleteTask, name='delete'), +] \ No newline at end of file diff --git a/Code/eric/django_projects/todo/todo_app/views.py b/Code/eric/django_projects/todo/todo_app/views.py new file mode 100644 index 00000000..d393334e --- /dev/null +++ b/Code/eric/django_projects/todo/todo_app/views.py @@ -0,0 +1,44 @@ +from django.shortcuts import render, redirect + +from todo_app.forms import TaskForm +from .models import * + +# Create your views here. +def index(request): + + tasks = Task.objects.all() + form = TaskForm() + + if request.method =='POST': + form = TaskForm(request.POST) + if form.is_valid(): + form.save() + return redirect('/') + + context = {'tasks': tasks, 'form':form} + + return render(request, 'todo_app/index.html', context) + +def updateTask(request, pk): + task = Task.objects.get(id=pk) + form = TaskForm(instance=task) + + context = {'form': form} + + if request.method == 'POST': + form = TaskForm(request.POST, instance=task) + if form.is_valid(): + form.save() + return redirect('/') + return render(request, 'todo_app/update.html', context ) + +def deleteTask(request, pk): + item = Task.objects.get(id=pk) + + if request.method == 'POST': + item.delete() + return redirect('/') + + context = {'item': item} + + return render(request, 'todo_app/delete.html', context) \ No newline at end of file diff --git a/Code/eric/django_projects/todo/todo_proj/__init__.py b/Code/eric/django_projects/todo/todo_proj/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/eric/django_projects/todo/todo_proj/asgi.py b/Code/eric/django_projects/todo/todo_proj/asgi.py new file mode 100644 index 00000000..0a358a99 --- /dev/null +++ b/Code/eric/django_projects/todo/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/3.2/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/eric/django_projects/todo/todo_proj/settings.py b/Code/eric/django_projects/todo/todo_proj/settings.py new file mode 100644 index 00000000..26174604 --- /dev/null +++ b/Code/eric/django_projects/todo/todo_proj/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for todo_proj project. + +Generated by 'django-admin startproject' using Django 3.2.12. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-58)w7vmldg%y6l1-ewg)!fnj8wss!gsus@)aro93ue__4zw=b+' + +# 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', + + '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/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/New_York' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Code/eric/django_projects/todo/todo_proj/urls.py b/Code/eric/django_projects/todo/todo_proj/urls.py new file mode 100644 index 00000000..6cff3a66 --- /dev/null +++ b/Code/eric/django_projects/todo/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/3.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('todo_app.urls')) +] diff --git a/Code/eric/django_projects/todo/todo_proj/wsgi.py b/Code/eric/django_projects/todo/todo_proj/wsgi.py new file mode 100644 index 00000000..d87e4976 --- /dev/null +++ b/Code/eric/django_projects/todo/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/3.2/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/eric/html/labs/lab_5/index.html b/Code/eric/html/labs/lab_5/index.html new file mode 100644 index 00000000..b06fdb1c --- /dev/null +++ b/Code/eric/html/labs/lab_5/index.html @@ -0,0 +1,104 @@ + + + + + + + Super Caliente Burritos + + + +
+ +
+ + +
+
+ + + +
+
+
+

What kind of tortilla?

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

What kind of rice?

+ + + + + +
+
+
+

What kind of beans?

+ + + + + +
+
+
+

What kind of protein?

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

Would you like...

+ + + + + +
+
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/Code/eric/html/labs/lab_6/app.py b/Code/eric/html/labs/lab_6/app.py new file mode 100644 index 00000000..7afbdc5e --- /dev/null +++ b/Code/eric/html/labs/lab_6/app.py @@ -0,0 +1,51 @@ +from crypt import methods +from unittest import result +from flask import Flask, render_template, request + +app = Flask(__name__) + +# route items to the index +@app.route('/') +def index(): + return render_template('index.html') + +#route the actual application +@app.route('/converter', methods = ['POST']) +def convertor(): + result = request.form + + user = result['measure_in'] + + conversion_in = { + 'ft' : .3048, + 'mi' : 1609.34, + 'm' : 1, + 'km' : 1000 +} + +conversion_out = { + 'ft' : 1/.3048, + 'mi' : 1/1609.34, + 'm' : 1, + 'km' : 1/1000 +} + +#build input +distance=input("what is the distance? ") +distance=int(distance) + +unit_in=input("what are the input units? choose ft, mi, km: ") +unit_out=input("what are the output units? choose ft, mi, km: ") + +#enter sausage maker +if unit_in in conversion_in and unit_out in conversion_out: + converted_to_meters = conversion_in[unit_in] + distance_in_meters = converted_to_meters * distance + meters_out = conversion_out[unit_out] + final_conversion = meters_out * distance_in_meters + print(f"{distance}{unit_in} is {round(final_conversion,4)}{unit_out}") + +else: + print("unit not recognized") + + return render_template('results.html', user=user) \ No newline at end of file diff --git a/Code/eric/html/labs/lab_6/templates/index.html b/Code/eric/html/labs/lab_6/templates/index.html new file mode 100644 index 00000000..ee705387 --- /dev/null +++ b/Code/eric/html/labs/lab_6/templates/index.html @@ -0,0 +1,13 @@ + + + + + + + Unit Converter + + +

Unit Converter

+
+ + \ No newline at end of file diff --git a/Code/eric/html/labs/lab_6/templates/results.html b/Code/eric/html/labs/lab_6/templates/results.html new file mode 100644 index 00000000..e69de29b diff --git a/Code/eric/js/APIS/app.js b/Code/eric/js/APIS/app.js new file mode 100644 index 00000000..dcda3069 --- /dev/null +++ b/Code/eric/js/APIS/app.js @@ -0,0 +1,62 @@ +console.log("start of code") + +const shuffleBtn = document.querySelector("#shuffle-btn") +const dealBtn = document.querySelector("#deal-btn") +let deckID = null +let hands = { + dealer: [], + player: [] +} + +// getCards is a function. leave the () off so it is activated by the click +shuffleBtn.addEventListener("click", getCards) + +dealBtn.addEventListener("click", dealCards) + +// this returns a promise causing the app to run out of order and require the .then +// fetch("https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1") +// .then(function(data) { +// return data.json() +// } +// ).then(function(data){ +// console.log(data) +// }) + +// async forces the app to go line by line instead of spinning off other threads +async function getCards() { + // await tells the code to hold on until there is a return from the fetch + const response = await fetch("https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1") + const data = await response.json() + console.log(data) + deckID = data.deck_id +} + +async function dealCards(){ + // the `${}` acts like an f string in python + const url = `https://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 + showcards() + showcards(true) + // console.log(data) +} + +function showcards(dealer = false){ + const hand = dealer ? hands.dealer : hands.player + const selector = dealer ? "#dealer" : "#player" + const handContainer = document.querySelector(selector) + handContainer.innerHTML = "" + for (card of hand){ + const cardImg = document.createElement('img') + cardImg.src = card.image + handContainer.append(cardImg) + } +} + + + + +console.log("end of code") \ No newline at end of file diff --git a/Code/eric/js/APIS/index.html b/Code/eric/js/APIS/index.html new file mode 100644 index 00000000..bbb6a709 --- /dev/null +++ b/Code/eric/js/APIS/index.html @@ -0,0 +1,20 @@ + + + + + + + Cards + + + +
+ + + +
+
+ +
+ + \ No newline at end of file diff --git a/Code/eric/js/redo/app.js b/Code/eric/js/redo/app.js new file mode 100644 index 00000000..89a2bd8c --- /dev/null +++ b/Code/eric/js/redo/app.js @@ -0,0 +1,61 @@ +// JavaScript redo lab of ROT13 cypher + +// Accept input +let user_string = prompt("Please enter a message: ") + +// Make it all lower case +user_string = user_string.toLowerCase() + +// Dictionary +/* +let letter_values = { + y : 'a', + o : 'd', + d : 'o', + a : 'y' +} +*/ +let letter_values = { + 'a' : 'n', + 'b' : 'o', + 'c' : 'p', + 'd' : 'q', + 'e' : 'r', + 'f' : 's', + 'g' : 't', + 'h' : 'u', + 'i' : 'v', + 'j' : 'w', + 'k' : 'x', + 'l' : 'y', + 'm' : 'z', + 'n' : 'a', + 'o' : 'b', + 'p' : 'c', + 'q' : 'd', + 'r' : 'e', + 's' : 'f', + 't' : 'g', + 'u' : 'h', + 'v' : 'i', + 'w' : 'j', + 'x' : 'k', + 'y' : 'l', + 'z' : 'm' +} +// console.log(letter_values) +// set null variable +let coded_word = "" +// Meat Grinder +function rot13(input) { + for (letter of input){ + // console.log(letter, letter_values[letter]) + coded_word += letter_values[letter] + } + return coded_word +} + +let finished = rot13(user_string) +alert(finished) +// console.log(coded_word) +// console.log("string") \ No newline at end of file diff --git a/Code/eric/js/redo/index.html b/Code/eric/js/redo/index.html new file mode 100644 index 00000000..32a7f203 --- /dev/null +++ b/Code/eric/js/redo/index.html @@ -0,0 +1,14 @@ + + + + + + + ReDo + + + + + + + \ No newline at end of file diff --git a/Code/eric/js/todo_list/app.js b/Code/eric/js/todo_list/app.js new file mode 100644 index 00000000..f51a25d1 --- /dev/null +++ b/Code/eric/js/todo_list/app.js @@ -0,0 +1,50 @@ +// add items to a list +// be able to remove items +// mark the items as completed and have the text strikethrough + +// global variables +const inputTodo = document.querySelector('#input') +const inputAdd = document.querySelector('#add') +const inputList = document.querySelector('#list') + +inputAdd.addEventListener('click', addTask) + +// task function +function addTask(){ + const textTodo = inputTodo.value + const addedTask = document.createElement('li') + const buttonSpan = document.createElement('span') + buttonSpan.textContent = textTodo + addedTask.append(buttonSpan) + inputList.appendChild(addedTask) + inputTodo.value = '' + + // complete button with strikethrough + const completeButton = document.createElement('button') + completeButton.textContent = 'Complete' + addedTask.append(completeButton) + + // remove button that makes it disappear + const removeButton = document.createElement('button') + removeButton.textContent = 'Remove' + addedTask.append(removeButton) + removeButton.addEventListener('click', function(){ + inputList.removeChild(removeButton.parentElement) + }) + + completeButton.addEventListener('click', function(){ + const buttonParent = completeButton.parentElement + const buttonSpan = buttonParent.querySelector('span') + + // create a function to determine if the text is complete + if(buttonSpan.style.textDecoration === 'line-through'){ + buttonSpan.style.textDecoration = 'none' + } + + else{ + buttonSpan.style.textDecoration = 'line-through' + inputList.removeChild(buttonParent) + inputList.append(buttonParent) + } + }) +} \ No newline at end of file diff --git a/Code/eric/js/todo_list/index.html b/Code/eric/js/todo_list/index.html new file mode 100644 index 00000000..a338646e --- /dev/null +++ b/Code/eric/js/todo_list/index.html @@ -0,0 +1,20 @@ + + + + + + + To Do + + + + +

To Do List

+
+ + +
+
    + + + \ No newline at end of file diff --git a/Code/eric/js/vue_redo/index.html b/Code/eric/js/vue_redo/index.html new file mode 100644 index 00000000..505159f3 --- /dev/null +++ b/Code/eric/js/vue_redo/index.html @@ -0,0 +1,68 @@ + + + + + + + + Vue ReDo + + + + + +
    +

    Rock, Paper, Scissors

    +
    + + + +
    + +
    +

    Computer chose {{computerSelect}}. The winner is {{result}}

    +
    +
    + + + + + + \ No newline at end of file diff --git a/Code/eric/js/vue_redo/test.html b/Code/eric/js/vue_redo/test.html new file mode 100644 index 00000000..1131a2bc --- /dev/null +++ b/Code/eric/js/vue_redo/test.html @@ -0,0 +1,106 @@ + + \ No newline at end of file diff --git a/Code/eric/js/vue_todo/index.html b/Code/eric/js/vue_todo/index.html new file mode 100644 index 00000000..4a38cec7 --- /dev/null +++ b/Code/eric/js/vue_todo/index.html @@ -0,0 +1,102 @@ + + + + + + + Document + + + + + + + +
    +

    {{headerText}}

    + +
    +
    + + +
    + +
    +

    Incomplete

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

    Complete

    +
    + + + {{todo.id}} {{todo.text}} + +
    + + +
    +
    +
    + + +
    + +
    + + + + + + \ No newline at end of file