From 84a42a9e378973c6c731b9131615ac0e2c9f69ea Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Wed, 21 Dec 2022 10:46:27 -0800
Subject: [PATCH 01/77] add josh django lab 01 progress to code
---
.../josh_lab01/grocery_list/__init__.py | 0
.../Django/josh_lab01/grocery_list/admin.py | 3 +
.../Django/josh_lab01/grocery_list/apps.py | 6 +
.../grocery_list/migrations/0001_initial.py | 24 ++++
.../grocery_list/migrations/__init__.py | 0
.../Django/josh_lab01/grocery_list/models.py | 8 ++
.../Django/josh_lab01/grocery_list/tests.py | 3 +
.../Django/josh_lab01/grocery_list/urls.py | 7 +
.../Django/josh_lab01/grocery_list/views.py | 6 +
.../Django/josh_lab01/josh_lab01/__init__.py | 0
.../josh/Django/josh_lab01/josh_lab01/asgi.py | 16 +++
.../Django/josh_lab01/josh_lab01/settings.py | 124 ++++++++++++++++++
.../josh/Django/josh_lab01/josh_lab01/urls.py | 22 ++++
.../josh/Django/josh_lab01/josh_lab01/wsgi.py | 16 +++
code/josh/Django/josh_lab01/manage.py | 22 ++++
15 files changed, 257 insertions(+)
create mode 100644 code/josh/Django/josh_lab01/grocery_list/__init__.py
create mode 100644 code/josh/Django/josh_lab01/grocery_list/admin.py
create mode 100644 code/josh/Django/josh_lab01/grocery_list/apps.py
create mode 100644 code/josh/Django/josh_lab01/grocery_list/migrations/0001_initial.py
create mode 100644 code/josh/Django/josh_lab01/grocery_list/migrations/__init__.py
create mode 100644 code/josh/Django/josh_lab01/grocery_list/models.py
create mode 100644 code/josh/Django/josh_lab01/grocery_list/tests.py
create mode 100644 code/josh/Django/josh_lab01/grocery_list/urls.py
create mode 100644 code/josh/Django/josh_lab01/grocery_list/views.py
create mode 100644 code/josh/Django/josh_lab01/josh_lab01/__init__.py
create mode 100644 code/josh/Django/josh_lab01/josh_lab01/asgi.py
create mode 100644 code/josh/Django/josh_lab01/josh_lab01/settings.py
create mode 100644 code/josh/Django/josh_lab01/josh_lab01/urls.py
create mode 100644 code/josh/Django/josh_lab01/josh_lab01/wsgi.py
create mode 100644 code/josh/Django/josh_lab01/manage.py
diff --git a/code/josh/Django/josh_lab01/grocery_list/__init__.py b/code/josh/Django/josh_lab01/grocery_list/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/code/josh/Django/josh_lab01/grocery_list/admin.py b/code/josh/Django/josh_lab01/grocery_list/admin.py
new file mode 100644
index 00000000..8c38f3f3
--- /dev/null
+++ b/code/josh/Django/josh_lab01/grocery_list/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/code/josh/Django/josh_lab01/grocery_list/apps.py b/code/josh/Django/josh_lab01/grocery_list/apps.py
new file mode 100644
index 00000000..0af6fbb4
--- /dev/null
+++ b/code/josh/Django/josh_lab01/grocery_list/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class GroceryListConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
+ name = 'grocery_list'
diff --git a/code/josh/Django/josh_lab01/grocery_list/migrations/0001_initial.py b/code/josh/Django/josh_lab01/grocery_list/migrations/0001_initial.py
new file mode 100644
index 00000000..146809b8
--- /dev/null
+++ b/code/josh/Django/josh_lab01/grocery_list/migrations/0001_initial.py
@@ -0,0 +1,24 @@
+# Generated by Django 4.1.4 on 2022-12-21 18:40
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='GroceryItem',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('text_description', models.CharField(max_length=200)),
+ ('created_date', models.DateTimeField(verbose_name='created date')),
+ ('completed_date', models.DateTimeField(verbose_name='completed date')),
+ ('completed', models.BooleanField()),
+ ],
+ ),
+ ]
diff --git a/code/josh/Django/josh_lab01/grocery_list/migrations/__init__.py b/code/josh/Django/josh_lab01/grocery_list/migrations/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/code/josh/Django/josh_lab01/grocery_list/models.py b/code/josh/Django/josh_lab01/grocery_list/models.py
new file mode 100644
index 00000000..4e38e47d
--- /dev/null
+++ b/code/josh/Django/josh_lab01/grocery_list/models.py
@@ -0,0 +1,8 @@
+from django.db import models
+
+
+class GroceryItem(models.Model):
+ text_description = models.CharField(max_length=200)
+ created_date = models.DateTimeField('created date')
+ completed_date = models.DateTimeField('completed date')
+ completed = models.BooleanField()
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab01/grocery_list/tests.py b/code/josh/Django/josh_lab01/grocery_list/tests.py
new file mode 100644
index 00000000..7ce503c2
--- /dev/null
+++ b/code/josh/Django/josh_lab01/grocery_list/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/code/josh/Django/josh_lab01/grocery_list/urls.py b/code/josh/Django/josh_lab01/grocery_list/urls.py
new file mode 100644
index 00000000..3ef24d97
--- /dev/null
+++ b/code/josh/Django/josh_lab01/grocery_list/urls.py
@@ -0,0 +1,7 @@
+from django.urls import path
+
+from . import views
+
+urlpatterns = [
+ path('', views.index, name='index'),
+]
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab01/grocery_list/views.py b/code/josh/Django/josh_lab01/grocery_list/views.py
new file mode 100644
index 00000000..a51834f4
--- /dev/null
+++ b/code/josh/Django/josh_lab01/grocery_list/views.py
@@ -0,0 +1,6 @@
+from django.shortcuts import render
+from django.http import HttpResponse
+
+
+def index(request):
+ return HttpResponse("Hello World! You're at the grocery_list index.")
diff --git a/code/josh/Django/josh_lab01/josh_lab01/__init__.py b/code/josh/Django/josh_lab01/josh_lab01/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/code/josh/Django/josh_lab01/josh_lab01/asgi.py b/code/josh/Django/josh_lab01/josh_lab01/asgi.py
new file mode 100644
index 00000000..1ff8320c
--- /dev/null
+++ b/code/josh/Django/josh_lab01/josh_lab01/asgi.py
@@ -0,0 +1,16 @@
+"""
+ASGI config for josh_lab01 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.1/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'josh_lab01.settings')
+
+application = get_asgi_application()
diff --git a/code/josh/Django/josh_lab01/josh_lab01/settings.py b/code/josh/Django/josh_lab01/josh_lab01/settings.py
new file mode 100644
index 00000000..4ba5c1c3
--- /dev/null
+++ b/code/josh/Django/josh_lab01/josh_lab01/settings.py
@@ -0,0 +1,124 @@
+"""
+Django settings for josh_lab01 project.
+
+Generated by 'django-admin startproject' using Django 4.1.4.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/4.1/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/4.1/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.1/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'django-insecure--pt9g52qef4rs3k(zf0=0^qy^fi3@ro&otxem9%09yssx0$&mp'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = [
+ 'grocery_list.apps.GroceryListConfig',
+ '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 = 'josh_lab01.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 = 'josh_lab01.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': BASE_DIR / 'db.sqlite3',
+ }
+}
+
+
+# Password validation
+# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+ {
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+ },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/4.1/topics/i18n/
+
+LANGUAGE_CODE = 'en-us'
+
+TIME_ZONE = 'America/Los_Angeles'
+
+USE_I18N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/4.1/howto/static-files/
+
+STATIC_URL = 'static/'
+
+# Default primary key field type
+# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
+
+DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
diff --git a/code/josh/Django/josh_lab01/josh_lab01/urls.py b/code/josh/Django/josh_lab01/josh_lab01/urls.py
new file mode 100644
index 00000000..7e3e7abd
--- /dev/null
+++ b/code/josh/Django/josh_lab01/josh_lab01/urls.py
@@ -0,0 +1,22 @@
+"""josh_lab01 URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+ https://docs.djangoproject.com/en/4.1/topics/http/urls/
+Examples:
+Function views
+ 1. Add an import: from my_app import views
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
+Class-based views
+ 1. Add an import: from other_app.views import Home
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
+Including another URLconf
+ 1. Import the include() function: from django.urls import include, path
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
+"""
+from django.contrib import admin
+from django.urls import include, path
+
+urlpatterns = [
+ path('grocery_list/', include('grocery_list.urls')),
+ path('admin/', admin.site.urls),
+]
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab01/josh_lab01/wsgi.py b/code/josh/Django/josh_lab01/josh_lab01/wsgi.py
new file mode 100644
index 00000000..26d47a17
--- /dev/null
+++ b/code/josh/Django/josh_lab01/josh_lab01/wsgi.py
@@ -0,0 +1,16 @@
+"""
+WSGI config for josh_lab01 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.1/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'josh_lab01.settings')
+
+application = get_wsgi_application()
diff --git a/code/josh/Django/josh_lab01/manage.py b/code/josh/Django/josh_lab01/manage.py
new file mode 100644
index 00000000..ddf68253
--- /dev/null
+++ b/code/josh/Django/josh_lab01/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', 'josh_lab01.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()
From d2feb882d17035fbd0582b59f6924d29118090de Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Wed, 21 Dec 2022 15:31:37 -0800
Subject: [PATCH 02/77] added superuser and registered model
---
code/josh/Django/josh_lab01/grocery_list/admin.py | 2 +-
code/josh/Django/josh_lab01/grocery_list/models.py | 11 ++++++++++-
.../templates/grocery_list/groceries.html | 0
code/josh/Django/josh_lab01/grocery_list/urls.py | 1 +
code/josh/Django/josh_lab01/grocery_list/views.py | 2 ++
5 files changed, 14 insertions(+), 2 deletions(-)
create mode 100644 code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/groceries.html
diff --git a/code/josh/Django/josh_lab01/grocery_list/admin.py b/code/josh/Django/josh_lab01/grocery_list/admin.py
index 8c38f3f3..9b1adefd 100644
--- a/code/josh/Django/josh_lab01/grocery_list/admin.py
+++ b/code/josh/Django/josh_lab01/grocery_list/admin.py
@@ -1,3 +1,3 @@
from django.contrib import admin
-# Register your models here.
+from . models import GroceryItem
diff --git a/code/josh/Django/josh_lab01/grocery_list/models.py b/code/josh/Django/josh_lab01/grocery_list/models.py
index 4e38e47d..1abb602f 100644
--- a/code/josh/Django/josh_lab01/grocery_list/models.py
+++ b/code/josh/Django/josh_lab01/grocery_list/models.py
@@ -1,8 +1,17 @@
+import datetime
+
from django.db import models
+from django.utils import timezone
class GroceryItem(models.Model):
text_description = models.CharField(max_length=200)
created_date = models.DateTimeField('created date')
completed_date = models.DateTimeField('completed date')
- completed = models.BooleanField()
\ No newline at end of file
+ completed = models.BooleanField()
+
+ def __str__(self):
+ return self.grocery_list
+
+ def was_published_recently(self):
+ return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/groceries.html b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/groceries.html
new file mode 100644
index 00000000..e69de29b
diff --git a/code/josh/Django/josh_lab01/grocery_list/urls.py b/code/josh/Django/josh_lab01/grocery_list/urls.py
index 3ef24d97..5294ac20 100644
--- a/code/josh/Django/josh_lab01/grocery_list/urls.py
+++ b/code/josh/Django/josh_lab01/grocery_list/urls.py
@@ -2,6 +2,7 @@
from . import views
+app_name = 'grocery_list'
urlpatterns = [
path('', views.index, name='index'),
]
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab01/grocery_list/views.py b/code/josh/Django/josh_lab01/grocery_list/views.py
index a51834f4..53d6703d 100644
--- a/code/josh/Django/josh_lab01/grocery_list/views.py
+++ b/code/josh/Django/josh_lab01/grocery_list/views.py
@@ -4,3 +4,5 @@
def index(request):
return HttpResponse("Hello World! You're at the grocery_list index.")
+
+
From 86f1fc5a926e713fc6d7d6d061d69fedd1e1cc0d Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Wed, 21 Dec 2022 15:34:51 -0800
Subject: [PATCH 03/77] completed registering model
---
code/josh/Django/josh_lab01/grocery_list/admin.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/code/josh/Django/josh_lab01/grocery_list/admin.py b/code/josh/Django/josh_lab01/grocery_list/admin.py
index 9b1adefd..756059c4 100644
--- a/code/josh/Django/josh_lab01/grocery_list/admin.py
+++ b/code/josh/Django/josh_lab01/grocery_list/admin.py
@@ -1,3 +1,5 @@
from django.contrib import admin
from . models import GroceryItem
+
+admin.site.register(GroceryItem)
From 0acf83561effc1b261cf95f3b679cd139bb2d745 Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Wed, 21 Dec 2022 16:26:54 -0800
Subject: [PATCH 04/77] add josh django lab 01 progress to code
---
code/josh/Django/josh_lab01/grocery_list/admin.py | 1 -
code/josh/Django/josh_lab01/grocery_list/models.py | 10 ++--------
code/josh/Django/josh_lab01/grocery_list/views.py | 11 ++++++-----
3 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/code/josh/Django/josh_lab01/grocery_list/admin.py b/code/josh/Django/josh_lab01/grocery_list/admin.py
index 756059c4..2d99bcda 100644
--- a/code/josh/Django/josh_lab01/grocery_list/admin.py
+++ b/code/josh/Django/josh_lab01/grocery_list/admin.py
@@ -1,5 +1,4 @@
from django.contrib import admin
-
from . models import GroceryItem
admin.site.register(GroceryItem)
diff --git a/code/josh/Django/josh_lab01/grocery_list/models.py b/code/josh/Django/josh_lab01/grocery_list/models.py
index 1abb602f..1480bedd 100644
--- a/code/josh/Django/josh_lab01/grocery_list/models.py
+++ b/code/josh/Django/josh_lab01/grocery_list/models.py
@@ -1,17 +1,11 @@
-import datetime
-
from django.db import models
-from django.utils import timezone
class GroceryItem(models.Model):
text_description = models.CharField(max_length=200)
- created_date = models.DateTimeField('created date')
+ created_date = models.DateTimeField('created date', auto_now_add=True)
completed_date = models.DateTimeField('completed date')
completed = models.BooleanField()
def __str__(self):
- return self.grocery_list
-
- def was_published_recently(self):
- return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
\ No newline at end of file
+ return self.grocery_list
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab01/grocery_list/views.py b/code/josh/Django/josh_lab01/grocery_list/views.py
index 53d6703d..f6dbe289 100644
--- a/code/josh/Django/josh_lab01/grocery_list/views.py
+++ b/code/josh/Django/josh_lab01/grocery_list/views.py
@@ -1,8 +1,9 @@
-from django.shortcuts import render
-from django.http import HttpResponse
+from django.shortcuts import render, get_object_or_404
+from django.http import HttpResponse, Http404, HttpResponseRedirect
+from django.template import loader
+from django.urls import reverse
+from . models import GroceryItem
def index(request):
- return HttpResponse("Hello World! You're at the grocery_list index.")
-
-
+ return HttpResponse("Hello World! You're at the grocery_list index.")
\ No newline at end of file
From fb73bc89a842770d4f47fcfd05944bf67523922c Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Thu, 22 Dec 2022 11:19:35 -0800
Subject: [PATCH 05/77] add josh django lab 1 progress to code
---
.../Django/josh_lab01/grocery_list/models.py | 2 +-
.../templates/grocery_list/groceries.html | 0
.../templates/grocery_list/index.html | 22 +++++++++++++++++++
.../Django/josh_lab01/grocery_list/views.py | 15 ++++++++++++-
4 files changed, 37 insertions(+), 2 deletions(-)
delete mode 100644 code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/groceries.html
create mode 100644 code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
diff --git a/code/josh/Django/josh_lab01/grocery_list/models.py b/code/josh/Django/josh_lab01/grocery_list/models.py
index 1480bedd..57852517 100644
--- a/code/josh/Django/josh_lab01/grocery_list/models.py
+++ b/code/josh/Django/josh_lab01/grocery_list/models.py
@@ -8,4 +8,4 @@ class GroceryItem(models.Model):
completed = models.BooleanField()
def __str__(self):
- return self.grocery_list
\ No newline at end of file
+ return self.text_description
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/groceries.html b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/groceries.html
deleted file mode 100644
index e69de29b..00000000
diff --git a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
new file mode 100644
index 00000000..53bafc5f
--- /dev/null
+++ b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+ Grocery List
+
+
+ {% for item in grocery_list %}
+
+ - {{ item.text_description }}
+
+ {% endfor %}
+
+
+
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab01/grocery_list/views.py b/code/josh/Django/josh_lab01/grocery_list/views.py
index f6dbe289..a24d1ca4 100644
--- a/code/josh/Django/josh_lab01/grocery_list/views.py
+++ b/code/josh/Django/josh_lab01/grocery_list/views.py
@@ -2,8 +2,21 @@
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.template import loader
from django.urls import reverse
+from datetime import datetime
from . models import GroceryItem
def index(request):
- return HttpResponse("Hello World! You're at the grocery_list index.")
\ No newline at end of file
+ if request.method == 'POST':
+ form_data = request.POST
+ grocery_object = GroceryItem.objects.create(
+ text_description=form_data['text_description'],
+ created_date=datetime.now(),
+ completed_date=datetime.now(),
+ completed=False)
+ return HttpResponseRedirect(reverse('grocery_list:index'))
+
+ else:
+ grocery_list = GroceryItem.objects.all()
+ context = {'grocery_list': grocery_list}
+ return render(request, 'grocery_list/index.html', context)
\ No newline at end of file
From 0f796946a0846d28037006c7b931ecf1e66543a2 Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Thu, 22 Dec 2022 12:28:52 -0800
Subject: [PATCH 06/77] add josh django lab 1 progress to code
---
.../templates/grocery_list/index.html | 26 +++++++++++++------
.../Django/josh_lab01/grocery_list/views.py | 9 ++++---
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
index 53bafc5f..f82105ba 100644
--- a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
+++ b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
@@ -6,16 +6,26 @@
Grocery List
-
- {% for item in grocery_list %}
-
- - {{ item.text_description }}
-
- {% endfor %}
+
+ Grocery List
+
diff --git a/code/josh/Django/josh_lab01/grocery_list/views.py b/code/josh/Django/josh_lab01/grocery_list/views.py
index a24d1ca4..832e07c3 100644
--- a/code/josh/Django/josh_lab01/grocery_list/views.py
+++ b/code/josh/Django/josh_lab01/grocery_list/views.py
@@ -10,10 +10,11 @@ def index(request):
if request.method == 'POST':
form_data = request.POST
grocery_object = GroceryItem.objects.create(
- text_description=form_data['text_description'],
- created_date=datetime.now(),
- completed_date=datetime.now(),
- completed=False)
+ text_description=form_data['text_description'],
+ created_date=datetime.now(),
+ completed_date=datetime.now(),
+ completed=False
+ )
return HttpResponseRedirect(reverse('grocery_list:index'))
else:
From bc2735306f6c4ffeb6ac196277cd05c7fb567bd7 Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Thu, 22 Dec 2022 16:30:54 -0800
Subject: [PATCH 07/77] add josh django lab 1 progress to code
---
code/josh/Django/josh_lab01/grocery_list/models.py | 2 +-
.../grocery_list/templates/grocery_list/index.html | 4 ++--
code/josh/Django/josh_lab01/grocery_list/urls.py | 2 ++
code/josh/Django/josh_lab01/grocery_list/views.py | 9 ++++++++-
4 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/code/josh/Django/josh_lab01/grocery_list/models.py b/code/josh/Django/josh_lab01/grocery_list/models.py
index 57852517..21cabf61 100644
--- a/code/josh/Django/josh_lab01/grocery_list/models.py
+++ b/code/josh/Django/josh_lab01/grocery_list/models.py
@@ -2,7 +2,7 @@
class GroceryItem(models.Model):
- text_description = models.CharField(max_length=200)
+ text_description = models.CharField(max_length=50)
created_date = models.DateTimeField('created date', auto_now_add=True)
completed_date = models.DateTimeField('completed date')
completed = models.BooleanField()
diff --git a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
index f82105ba..ddf9c045 100644
--- a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
+++ b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
@@ -6,7 +6,7 @@
Grocery List
-
+
Grocery List
@@ -17,7 +17,7 @@ Grocery List
{% for item in grocery_list %}
| {{ item.text_description }} |
- {{ item.completed }} |
+ |
delete |
{% endfor %}
diff --git a/code/josh/Django/josh_lab01/grocery_list/urls.py b/code/josh/Django/josh_lab01/grocery_list/urls.py
index 5294ac20..a18c83c2 100644
--- a/code/josh/Django/josh_lab01/grocery_list/urls.py
+++ b/code/josh/Django/josh_lab01/grocery_list/urls.py
@@ -5,4 +5,6 @@
app_name = 'grocery_list'
urlpatterns = [
path('', views.index, name='index'),
+ # path('delete/', views.delete, name='delete')
+ path('delete/', views.delete, name='delete'),
]
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab01/grocery_list/views.py b/code/josh/Django/josh_lab01/grocery_list/views.py
index 832e07c3..c87c7716 100644
--- a/code/josh/Django/josh_lab01/grocery_list/views.py
+++ b/code/josh/Django/josh_lab01/grocery_list/views.py
@@ -15,9 +15,16 @@ def index(request):
completed_date=datetime.now(),
completed=False
)
+ # how do I delete a list item?
+ # del_grocery_object = GroceryItem.objects.delete(text_description=form_data['text_description'])
return HttpResponseRedirect(reverse('grocery_list:index'))
else:
grocery_list = GroceryItem.objects.all()
context = {'grocery_list': grocery_list}
- return render(request, 'grocery_list/index.html', context)
\ No newline at end of file
+ return render(request, 'grocery_list/index.html', context)
+
+def delete(request):
+ if request.method == 'POST':
+ form_data = request.POST
+ completed=True
\ No newline at end of file
From ba3abc7318a928e6f4bd5cd8dfa50251bb39834f Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Mon, 26 Dec 2022 13:19:07 -0800
Subject: [PATCH 08/77] started conditional for complete/incomplete button in
html
---
.../grocery_list/templates/grocery_list/index.html | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
index ddf9c045..d9367f77 100644
--- a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
+++ b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
@@ -17,7 +17,12 @@ Grocery List
{% for item in grocery_list %}
| {{ item.text_description }} |
+
+ {% if item.completed == False %}
|
+ {% else %}
+ |
+ {% endif %}
delete |
{% endfor %}
From 1519346ee779dd39729bbdbd34f0c24aaba954f2 Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Tue, 27 Dec 2022 10:57:50 -0800
Subject: [PATCH 09/77] finished conditional for complete/incomplete button in
html
---
.../templates/grocery_list/index.html | 6 +++---
.../Django/josh_lab01/grocery_list/urls.py | 2 +-
.../Django/josh_lab01/grocery_list/views.py | 18 +++++++++++++-----
3 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
index d9367f77..324d2848 100644
--- a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
+++ b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
@@ -19,11 +19,11 @@ Grocery List
{{ item.text_description }} |
{% if item.completed == False %}
- |
+ |
{% else %}
- |
+ |
{% endif %}
- delete |
+ delete |
{% endfor %}
diff --git a/code/josh/Django/josh_lab01/grocery_list/urls.py b/code/josh/Django/josh_lab01/grocery_list/urls.py
index a18c83c2..a38aca7b 100644
--- a/code/josh/Django/josh_lab01/grocery_list/urls.py
+++ b/code/josh/Django/josh_lab01/grocery_list/urls.py
@@ -5,6 +5,6 @@
app_name = 'grocery_list'
urlpatterns = [
path('', views.index, name='index'),
- # path('delete/', views.delete, name='delete')
+ path('complete/', views.complete, name='complete'),
path('delete/', views.delete, name='delete'),
]
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab01/grocery_list/views.py b/code/josh/Django/josh_lab01/grocery_list/views.py
index c87c7716..f8c082e9 100644
--- a/code/josh/Django/josh_lab01/grocery_list/views.py
+++ b/code/josh/Django/josh_lab01/grocery_list/views.py
@@ -22,9 +22,17 @@ def index(request):
else:
grocery_list = GroceryItem.objects.all()
context = {'grocery_list': grocery_list}
- return render(request, 'grocery_list/index.html', context)
+ return render(request, 'grocery_list/index.html', context)
-def delete(request):
- if request.method == 'POST':
- form_data = request.POST
- completed=True
\ No newline at end of file
+def complete(request, id):
+ grocery_item = GroceryItem.objects.get(id=id)
+ if grocery_item.completed == False:
+ grocery_item.completed = True
+ else:
+ grocery_item.completed = False
+ grocery_item.save()
+ return HttpResponseRedirect(reverse('grocery_list:index'))
+
+def delete(request, id):
+ grocery_item = GroceryItem.objects.delete(id=id)
+ return HttpResponseRedirect(reverse('grocery_list:index'))
\ No newline at end of file
From 8dc5a666f77cd104e68e61201e5a426252b3ea2a Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Tue, 27 Dec 2022 11:52:12 -0800
Subject: [PATCH 10/77] added delete item capability
---
.../grocery_list/templates/grocery_list/index.html | 1 -
code/josh/Django/josh_lab01/grocery_list/views.py | 5 ++---
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
index 324d2848..b42dc598 100644
--- a/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
+++ b/code/josh/Django/josh_lab01/grocery_list/templates/grocery_list/index.html
@@ -17,7 +17,6 @@ Grocery List
{% for item in grocery_list %}
| {{ item.text_description }} |
-
{% if item.completed == False %}
|
{% else %}
diff --git a/code/josh/Django/josh_lab01/grocery_list/views.py b/code/josh/Django/josh_lab01/grocery_list/views.py
index f8c082e9..1bbe630c 100644
--- a/code/josh/Django/josh_lab01/grocery_list/views.py
+++ b/code/josh/Django/josh_lab01/grocery_list/views.py
@@ -15,8 +15,6 @@ def index(request):
completed_date=datetime.now(),
completed=False
)
- # how do I delete a list item?
- # del_grocery_object = GroceryItem.objects.delete(text_description=form_data['text_description'])
return HttpResponseRedirect(reverse('grocery_list:index'))
else:
@@ -34,5 +32,6 @@ def complete(request, id):
return HttpResponseRedirect(reverse('grocery_list:index'))
def delete(request, id):
- grocery_item = GroceryItem.objects.delete(id=id)
+ grocery_item = GroceryItem.objects.get(id=id)
+ grocery_item.delete()
return HttpResponseRedirect(reverse('grocery_list:index'))
\ No newline at end of file
From 529effd295297924a5a3f034be9471c0e445e6f1 Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Tue, 27 Dec 2022 12:31:07 -0800
Subject: [PATCH 11/77] created lab 2 project and url shortener app
---
.../Django/josh_lab02/josh_lab02/__init__.py | 0
.../josh/Django/josh_lab02/josh_lab02/asgi.py | 16 +++
.../Django/josh_lab02/josh_lab02/settings.py | 124 ++++++++++++++++++
.../josh/Django/josh_lab02/josh_lab02/urls.py | 22 ++++
.../josh/Django/josh_lab02/josh_lab02/wsgi.py | 16 +++
code/josh/Django/josh_lab02/manage.py | 22 ++++
.../josh_lab02/url_shortener/__init__.py | 0
.../Django/josh_lab02/url_shortener/admin.py | 4 +
.../Django/josh_lab02/url_shortener/apps.py | 6 +
.../url_shortener/migrations/__init__.py | 0
.../Django/josh_lab02/url_shortener/models.py | 8 ++
.../templates/url_shortener/index.html | 0
.../Django/josh_lab02/url_shortener/tests.py | 3 +
.../Django/josh_lab02/url_shortener/urls.py | 8 ++
.../Django/josh_lab02/url_shortener/views.py | 5 +
15 files changed, 234 insertions(+)
create mode 100644 code/josh/Django/josh_lab02/josh_lab02/__init__.py
create mode 100644 code/josh/Django/josh_lab02/josh_lab02/asgi.py
create mode 100644 code/josh/Django/josh_lab02/josh_lab02/settings.py
create mode 100644 code/josh/Django/josh_lab02/josh_lab02/urls.py
create mode 100644 code/josh/Django/josh_lab02/josh_lab02/wsgi.py
create mode 100644 code/josh/Django/josh_lab02/manage.py
create mode 100644 code/josh/Django/josh_lab02/url_shortener/__init__.py
create mode 100644 code/josh/Django/josh_lab02/url_shortener/admin.py
create mode 100644 code/josh/Django/josh_lab02/url_shortener/apps.py
create mode 100644 code/josh/Django/josh_lab02/url_shortener/migrations/__init__.py
create mode 100644 code/josh/Django/josh_lab02/url_shortener/models.py
create mode 100644 code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
create mode 100644 code/josh/Django/josh_lab02/url_shortener/tests.py
create mode 100644 code/josh/Django/josh_lab02/url_shortener/urls.py
create mode 100644 code/josh/Django/josh_lab02/url_shortener/views.py
diff --git a/code/josh/Django/josh_lab02/josh_lab02/__init__.py b/code/josh/Django/josh_lab02/josh_lab02/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/code/josh/Django/josh_lab02/josh_lab02/asgi.py b/code/josh/Django/josh_lab02/josh_lab02/asgi.py
new file mode 100644
index 00000000..97ebc9db
--- /dev/null
+++ b/code/josh/Django/josh_lab02/josh_lab02/asgi.py
@@ -0,0 +1,16 @@
+"""
+ASGI config for josh_lab02 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.1/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'josh_lab02.settings')
+
+application = get_asgi_application()
diff --git a/code/josh/Django/josh_lab02/josh_lab02/settings.py b/code/josh/Django/josh_lab02/josh_lab02/settings.py
new file mode 100644
index 00000000..6e4bee99
--- /dev/null
+++ b/code/josh/Django/josh_lab02/josh_lab02/settings.py
@@ -0,0 +1,124 @@
+"""
+Django settings for josh_lab02 project.
+
+Generated by 'django-admin startproject' using Django 4.1.4.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/4.1/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/4.1/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.1/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'django-insecure-z5wv*j!h*qv-omi_^)s6id+eu&$5@^i(s_gc-y3*98e=9!s@!^'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = [
+ 'url_shortener.apps.UrlShortenerConfig'
+ '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 = 'josh_lab02.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 = 'josh_lab02.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': BASE_DIR / 'db.sqlite3',
+ }
+}
+
+
+# Password validation
+# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+ {
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+ },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/4.1/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.1/howto/static-files/
+
+STATIC_URL = 'static/'
+
+# Default primary key field type
+# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
+
+DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
diff --git a/code/josh/Django/josh_lab02/josh_lab02/urls.py b/code/josh/Django/josh_lab02/josh_lab02/urls.py
new file mode 100644
index 00000000..ce973753
--- /dev/null
+++ b/code/josh/Django/josh_lab02/josh_lab02/urls.py
@@ -0,0 +1,22 @@
+"""josh_lab02 URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+ https://docs.djangoproject.com/en/4.1/topics/http/urls/
+Examples:
+Function views
+ 1. Add an import: from my_app import views
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
+Class-based views
+ 1. Add an import: from other_app.views import Home
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
+Including another URLconf
+ 1. Import the include() function: from django.urls import include, path
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
+"""
+from django.contrib import admin
+from django.urls import include, path
+
+urlpatterns = [
+ path('url_shortener/', include('url_shortener.urls')),
+ path('admin/', admin.site.urls),
+]
diff --git a/code/josh/Django/josh_lab02/josh_lab02/wsgi.py b/code/josh/Django/josh_lab02/josh_lab02/wsgi.py
new file mode 100644
index 00000000..b1aba64f
--- /dev/null
+++ b/code/josh/Django/josh_lab02/josh_lab02/wsgi.py
@@ -0,0 +1,16 @@
+"""
+WSGI config for josh_lab02 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.1/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'josh_lab02.settings')
+
+application = get_wsgi_application()
diff --git a/code/josh/Django/josh_lab02/manage.py b/code/josh/Django/josh_lab02/manage.py
new file mode 100644
index 00000000..68e14990
--- /dev/null
+++ b/code/josh/Django/josh_lab02/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', 'josh_lab02.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/josh/Django/josh_lab02/url_shortener/__init__.py b/code/josh/Django/josh_lab02/url_shortener/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/code/josh/Django/josh_lab02/url_shortener/admin.py b/code/josh/Django/josh_lab02/url_shortener/admin.py
new file mode 100644
index 00000000..aefbe40f
--- /dev/null
+++ b/code/josh/Django/josh_lab02/url_shortener/admin.py
@@ -0,0 +1,4 @@
+from django.contrib import admin
+from . models import UrlShortener
+
+admin.site.register(UrlShortener)
diff --git a/code/josh/Django/josh_lab02/url_shortener/apps.py b/code/josh/Django/josh_lab02/url_shortener/apps.py
new file mode 100644
index 00000000..f3e477d6
--- /dev/null
+++ b/code/josh/Django/josh_lab02/url_shortener/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class UrlShortenerConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
+ name = 'url_shortener'
diff --git a/code/josh/Django/josh_lab02/url_shortener/migrations/__init__.py b/code/josh/Django/josh_lab02/url_shortener/migrations/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/code/josh/Django/josh_lab02/url_shortener/models.py b/code/josh/Django/josh_lab02/url_shortener/models.py
new file mode 100644
index 00000000..c138b1d6
--- /dev/null
+++ b/code/josh/Django/josh_lab02/url_shortener/models.py
@@ -0,0 +1,8 @@
+from django.db import models
+
+class UrlShortener(models.Model):
+ long_url = models.CharField(max_length=200)
+ short_code = models.CharField(max_length=200)
+
+ def __str__(self):
+ return self.long_url
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html b/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
new file mode 100644
index 00000000..e69de29b
diff --git a/code/josh/Django/josh_lab02/url_shortener/tests.py b/code/josh/Django/josh_lab02/url_shortener/tests.py
new file mode 100644
index 00000000..7ce503c2
--- /dev/null
+++ b/code/josh/Django/josh_lab02/url_shortener/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/code/josh/Django/josh_lab02/url_shortener/urls.py b/code/josh/Django/josh_lab02/url_shortener/urls.py
new file mode 100644
index 00000000..45b89614
--- /dev/null
+++ b/code/josh/Django/josh_lab02/url_shortener/urls.py
@@ -0,0 +1,8 @@
+from django.urls import path
+
+from . import views
+
+app_name = 'url_shortener'
+urlpatterns = [
+ path('', views.index, name='index'),
+]
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab02/url_shortener/views.py b/code/josh/Django/josh_lab02/url_shortener/views.py
new file mode 100644
index 00000000..414836e1
--- /dev/null
+++ b/code/josh/Django/josh_lab02/url_shortener/views.py
@@ -0,0 +1,5 @@
+from django.shortcuts import render
+from django.http import HttpResponse
+
+def index(request):
+ return HttpResponse("Hello, world")
\ No newline at end of file
From f1c3d9e20a7688dc9a23334c5bbc7d6c2ebc809c Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Tue, 27 Dec 2022 13:41:19 -0800
Subject: [PATCH 12/77] made migrations
---
.../Django/josh_lab02/josh_lab02/settings.py | 2 +-
.../url_shortener/migrations/0001_initial.py | 22 +++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
create mode 100644 code/josh/Django/josh_lab02/url_shortener/migrations/0001_initial.py
diff --git a/code/josh/Django/josh_lab02/josh_lab02/settings.py b/code/josh/Django/josh_lab02/josh_lab02/settings.py
index 6e4bee99..77fda85c 100644
--- a/code/josh/Django/josh_lab02/josh_lab02/settings.py
+++ b/code/josh/Django/josh_lab02/josh_lab02/settings.py
@@ -31,7 +31,7 @@
# Application definition
INSTALLED_APPS = [
- 'url_shortener.apps.UrlShortenerConfig'
+ 'url_shortener.apps.UrlShortenerConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
diff --git a/code/josh/Django/josh_lab02/url_shortener/migrations/0001_initial.py b/code/josh/Django/josh_lab02/url_shortener/migrations/0001_initial.py
new file mode 100644
index 00000000..c9c1bff1
--- /dev/null
+++ b/code/josh/Django/josh_lab02/url_shortener/migrations/0001_initial.py
@@ -0,0 +1,22 @@
+# Generated by Django 4.1.4 on 2022-12-27 21:37
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='UrlShortener',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('long_url', models.CharField(max_length=200)),
+ ('short_code', models.CharField(max_length=200)),
+ ],
+ ),
+ ]
From 84621c94c595cb7c4a313ceffe8aedb4da7aacfb Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Tue, 27 Dec 2022 14:20:43 -0800
Subject: [PATCH 13/77] created views in progress
---
.../templates/url_shortener/index.html | 12 ++++++
.../Django/josh_lab02/url_shortener/urls.py | 1 +
.../Django/josh_lab02/url_shortener/views.py | 43 +++++++++++++++++--
3 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html b/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
index e69de29b..52ab953e 100644
--- a/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
+++ b/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+ Django Lab 02
+
+
+
+
+
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab02/url_shortener/urls.py b/code/josh/Django/josh_lab02/url_shortener/urls.py
index 45b89614..a655981c 100644
--- a/code/josh/Django/josh_lab02/url_shortener/urls.py
+++ b/code/josh/Django/josh_lab02/url_shortener/urls.py
@@ -4,5 +4,6 @@
app_name = 'url_shortener'
urlpatterns = [
+ path('redirect/', views.redirect, name='redirect')
path('', views.index, name='index'),
]
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab02/url_shortener/views.py b/code/josh/Django/josh_lab02/url_shortener/views.py
index 414836e1..e9cebce7 100644
--- a/code/josh/Django/josh_lab02/url_shortener/views.py
+++ b/code/josh/Django/josh_lab02/url_shortener/views.py
@@ -1,5 +1,42 @@
+import random
+import string
from django.shortcuts import render
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseRedirect
+from django.urls import reverse
+from . models import UrlShortener
-def index(request):
- return HttpResponse("Hello, world")
\ No newline at end of file
+def index(request):
+ if request.method == 'POST':
+ form_data = request.POST
+ url = UrlShortener.objects.create(
+ long_url=form_data['long_url'],
+ short_code=form_data['short_url']
+ )
+ return HttpResponseRedirect(reverse('url_shortener:index'))
+
+ else:
+ url = UrlShortener.objects.all()
+ context = {'url_shortener': url}
+ return render(request, 'url_shortener/index.html', context)
+
+def redirect(request):
+ url = UrlShortener.objects.get(id=id)
+ # Create variables to hold the string methods containing letters, digits, and symbols.
+ letters = string.ascii_letters
+ digits = string.digits
+ symbols = string.punctuation
+ # Concatenate "letters," "digits," and "symbols" variables to draw random values from a single string.
+ all_characters = letters + digits + symbols
+ # Create an empty list to store values for password
+ password = []
+ # Create a while loop that runs enough times to select enough values from the "all_characters" variable for the new password.
+ while len(password) < 10:
+ # Add values to the "password" list at random from the "all_characters" variable.
+ password.append(random.choice(all_characters))
+
+ # Create a new variable "password_join" to join all the items in the password list using an empty string.
+ password_join = "".join(password)
+ # Display the new password using an f-string with a message to the user and the new
+ # password.
+ print(password_join)
+ return HttpResponseRedirect(reverse('url_shortener:index'))
\ No newline at end of file
From 6e1bb1cb9e89d0db9b8f06dff2bb248dd471a767 Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Tue, 27 Dec 2022 15:11:49 -0800
Subject: [PATCH 14/77] started html and finished index view
---
.../templates/url_shortener/index.html | 12 +++++--
.../Django/josh_lab02/url_shortener/urls.py | 2 +-
.../Django/josh_lab02/url_shortener/views.py | 32 ++++++-------------
3 files changed, 21 insertions(+), 25 deletions(-)
diff --git a/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html b/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
index 52ab953e..cbb462e2 100644
--- a/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
+++ b/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
@@ -4,9 +4,17 @@
- Django Lab 02
+ URL Shortener: Django Lab 02
-
+
+ {% for item in url_shortener %}
+ {{ item.long_url }} {{ item.short_code }}
+ {% endfor %}
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab02/url_shortener/urls.py b/code/josh/Django/josh_lab02/url_shortener/urls.py
index a655981c..1d873858 100644
--- a/code/josh/Django/josh_lab02/url_shortener/urls.py
+++ b/code/josh/Django/josh_lab02/url_shortener/urls.py
@@ -4,6 +4,6 @@
app_name = 'url_shortener'
urlpatterns = [
- path('redirect/', views.redirect, name='redirect')
+ path('redirect/', views.redirect, name='redirect'),
path('', views.index, name='index'),
]
\ No newline at end of file
diff --git a/code/josh/Django/josh_lab02/url_shortener/views.py b/code/josh/Django/josh_lab02/url_shortener/views.py
index e9cebce7..1db2c100 100644
--- a/code/josh/Django/josh_lab02/url_shortener/views.py
+++ b/code/josh/Django/josh_lab02/url_shortener/views.py
@@ -1,5 +1,5 @@
import random
-import string
+from string import ascii_letters as letters, digits as digits
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse
@@ -8,9 +8,15 @@
def index(request):
if request.method == 'POST':
form_data = request.POST
+ all_characters = letters + digits
+ code = []
+ while len(code) < 10:
+ code.append(random.choice(all_characters))
+ code_join = "".join(code)
+ print(code_join)
url = UrlShortener.objects.create(
long_url=form_data['long_url'],
- short_code=form_data['short_url']
+ short_code = code_join
)
return HttpResponseRedirect(reverse('url_shortener:index'))
@@ -19,24 +25,6 @@ def index(request):
context = {'url_shortener': url}
return render(request, 'url_shortener/index.html', context)
-def redirect(request):
+def redirect(request, id):
url = UrlShortener.objects.get(id=id)
- # Create variables to hold the string methods containing letters, digits, and symbols.
- letters = string.ascii_letters
- digits = string.digits
- symbols = string.punctuation
- # Concatenate "letters," "digits," and "symbols" variables to draw random values from a single string.
- all_characters = letters + digits + symbols
- # Create an empty list to store values for password
- password = []
- # Create a while loop that runs enough times to select enough values from the "all_characters" variable for the new password.
- while len(password) < 10:
- # Add values to the "password" list at random from the "all_characters" variable.
- password.append(random.choice(all_characters))
-
- # Create a new variable "password_join" to join all the items in the password list using an empty string.
- password_join = "".join(password)
- # Display the new password using an f-string with a message to the user and the new
- # password.
- print(password_join)
- return HttpResponseRedirect(reverse('url_shortener:index'))
\ No newline at end of file
+ return HttpResponseRedirect(reverse('url_shortener:redirect'))
\ No newline at end of file
From e08e4516571f64d0618b8ba77e8030af411ad86b Mon Sep 17 00:00:00 2001
From: Josh <24633211+JFC1@users.noreply.github.com>
Date: Tue, 27 Dec 2022 16:28:28 -0800
Subject: [PATCH 15/77] completed url shortener redirect
---
.../url_shortener/templates/url_shortener/index.html | 2 +-
code/josh/Django/josh_lab02/url_shortener/views.py | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html b/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
index cbb462e2..bf598340 100644
--- a/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
+++ b/code/josh/Django/josh_lab02/url_shortener/templates/url_shortener/index.html
@@ -14,7 +14,7 @@
{% for item in url_shortener %}
- {{ item.long_url }} {{ item.short_code }}
+ {{ item.long_url }} {{ item.short_code }}
{% endfor %}