diff --git a/Code/Michael/Python/5-palindrome_checker.py b/Code/Michael/Python/5-palindrome_checker.py index 913b1ace..7f29ecb5 100644 --- a/Code/Michael/Python/5-palindrome_checker.py +++ b/Code/Michael/Python/5-palindrome_checker.py @@ -43,4 +43,6 @@ def check_palindrome(list_of_strings)->list: case unknown_command: print (f"\nUnknown command '{unknown_command}' Please enter Palindrome or Anagram or Quit.") valid_command = False + + print("\nGoodbye. Thank you for using this program.") \ No newline at end of file diff --git a/Code/Michael/Python/email_test.py b/Code/Michael/Python/email_test.py new file mode 100644 index 00000000..7f6c5b1d --- /dev/null +++ b/Code/Michael/Python/email_test.py @@ -0,0 +1,26 @@ +from smtplib import SMTP +from email.message import EmailMessage + + +def email_alert(to, subject="Alert", body="Alert!"): + msg = EmailMessage() + msg.set_content(body) + msg["Subject"] = subject + msg["To"] = to + + user = "mrnotifi@gmail.com" + msg["From"] = user + password = "nixqgstknzqcfqig" + port = int(587) + + with SMTP("smtp.gmail.com", port) as server: + server.starttls() + server.login(user, password) + + server.send_message(msg) + + +if __name__ == "__main__": + + print("test") + email_alert("broetjem@gmail.com", "hey", "hello world") diff --git a/Code/Michael/django/lab01/lab01project/.gitignore b/Code/Michael/django/lab01/lab01project/.gitignore new file mode 100644 index 00000000..b176143d --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/.gitignore @@ -0,0 +1,152 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ \ No newline at end of file diff --git a/Code/Michael/django/lab01/lab01project/README.md b/Code/Michael/django/lab01/lab01project/README.md new file mode 100644 index 00000000..ca358897 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/README.md @@ -0,0 +1,8 @@ +# Personal Assistant + +## Install + +- pip3 install -r requirements.txt +- python3 manage.py migrate +- Optional: python3 manage.py createsuperuser +- python3 manage.py runserver diff --git a/Code/Michael/django/lab01/lab01project/assistant/__init__.py b/Code/Michael/django/lab01/lab01project/assistant/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/Michael/django/lab01/lab01project/assistant/admin.py b/Code/Michael/django/lab01/lab01project/assistant/admin.py new file mode 100644 index 00000000..0dacfa2a --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/admin.py @@ -0,0 +1,7 @@ +from django.contrib import admin + +# Register your models here. +from .models import * + +admin.site.register(Priority) +admin.site.register(TodoItem) diff --git a/Code/Michael/django/lab01/lab01project/assistant/apps.py b/Code/Michael/django/lab01/lab01project/assistant/apps.py new file mode 100644 index 00000000..00c54201 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AssistantConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "assistant" diff --git a/Code/Michael/django/lab01/lab01project/assistant/migrations/0001_initial.py b/Code/Michael/django/lab01/lab01project/assistant/migrations/0001_initial.py new file mode 100644 index 00000000..26fbc154 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/migrations/0001_initial.py @@ -0,0 +1,62 @@ +# Generated by Django 3.2.10 on 2022-03-06 17:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Priority", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "name", + models.CharField( + choices=[ + ("High", "High"), + ("Medium", "Medium"), + ("Low", "Low"), + ], + default="Medium", + max_length=6, + ), + ), + ], + options={ + "ordering": ["-name"], + }, + ), + migrations.CreateModel( + name="TodoItem", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=250)), + ("description", models.TextField()), + ("completed", models.DateTimeField(blank=True, null=True)), + ], + options={ + "ordering": ["-priority"], + }, + ), + ] diff --git a/Code/Michael/django/lab01/lab01project/assistant/migrations/0002_initial.py b/Code/Michael/django/lab01/lab01project/assistant/migrations/0002_initial.py new file mode 100644 index 00000000..fc0b4c88 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/migrations/0002_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.10 on 2022-03-06 17:32 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ("assistant", "0001_initial"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name="todoitem", + name="owner", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL + ), + ), + migrations.AddField( + model_name="todoitem", + name="priority", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="assistant.priority" + ), + ), + ] diff --git a/Code/Michael/django/lab01/lab01project/assistant/migrations/0003_alter_priority_name.py b/Code/Michael/django/lab01/lab01project/assistant/migrations/0003_alter_priority_name.py new file mode 100644 index 00000000..5dbae452 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/migrations/0003_alter_priority_name.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.10 on 2022-03-06 17:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("assistant", "0002_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="priority", + name="name", + field=models.CharField( + choices=[(1, "High"), (2, "Medium"), (3, "Low")], + default=2, + max_length=6, + ), + ), + ] diff --git a/Code/Michael/django/lab01/lab01project/assistant/migrations/0004_alter_priority_name.py b/Code/Michael/django/lab01/lab01project/assistant/migrations/0004_alter_priority_name.py new file mode 100644 index 00000000..391d509b --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/migrations/0004_alter_priority_name.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.10 on 2022-03-06 17:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("assistant", "0003_alter_priority_name"), + ] + + operations = [ + migrations.AlterField( + model_name="priority", + name="name", + field=models.CharField( + choices=[("High", 1), ("Medium", 2), ("Low", 3)], + default="Medium", + max_length=6, + ), + ), + ] diff --git a/Code/Michael/django/lab01/lab01project/assistant/migrations/0005_alter_priority_name.py b/Code/Michael/django/lab01/lab01project/assistant/migrations/0005_alter_priority_name.py new file mode 100644 index 00000000..e07242fb --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/migrations/0005_alter_priority_name.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.10 on 2022-03-06 17:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("assistant", "0004_alter_priority_name"), + ] + + operations = [ + migrations.AlterField( + model_name="priority", + name="name", + field=models.CharField( + choices=[(1, "High"), ("Medium", 2), ("Low", 3)], + default="Medium", + max_length=6, + ), + ), + ] diff --git a/Code/Michael/django/lab01/lab01project/assistant/migrations/0006_alter_priority_name.py b/Code/Michael/django/lab01/lab01project/assistant/migrations/0006_alter_priority_name.py new file mode 100644 index 00000000..6b7eacf2 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/migrations/0006_alter_priority_name.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.10 on 2022-03-06 17:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("assistant", "0005_alter_priority_name"), + ] + + operations = [ + migrations.AlterField( + model_name="priority", + name="name", + field=models.CharField( + choices=[(1, 1), (2, 2), (3, 3)], default="Medium", max_length=6 + ), + ), + ] diff --git a/Code/Michael/django/lab01/lab01project/assistant/migrations/0007_auto_20220306_1000.py b/Code/Michael/django/lab01/lab01project/assistant/migrations/0007_auto_20220306_1000.py new file mode 100644 index 00000000..5d1c44e7 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/migrations/0007_auto_20220306_1000.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.10 on 2022-03-06 18:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("assistant", "0006_alter_priority_name"), + ] + + operations = [ + migrations.AlterModelOptions( + name="priority", + options={"ordering": ["-name"], "verbose_name_plural": "Priorities"}, + ), + migrations.AlterField( + model_name="priority", + name="name", + field=models.IntegerField(choices=[(1, "Low"), (2, "Medium"), (3, "High")]), + ), + ] diff --git a/Code/Michael/django/lab01/lab01project/assistant/migrations/0008_alter_priority_options_alter_priority_name.py b/Code/Michael/django/lab01/lab01project/assistant/migrations/0008_alter_priority_options_alter_priority_name.py new file mode 100644 index 00000000..39c129c9 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/migrations/0008_alter_priority_options_alter_priority_name.py @@ -0,0 +1,22 @@ +# Generated by Django 4.0 on 2022-03-07 01:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('assistant', '0007_auto_20220306_1000'), + ] + + operations = [ + migrations.AlterModelOptions( + name='priority', + options={'ordering': ['name'], 'verbose_name_plural': 'Priorities'}, + ), + migrations.AlterField( + model_name='priority', + name='name', + field=models.IntegerField(choices=[(0, 'Completed'), (1, 'Low'), (2, 'Medium'), (3, 'High')], default=2), + ), + ] diff --git a/Code/Michael/django/lab01/lab01project/assistant/migrations/__init__.py b/Code/Michael/django/lab01/lab01project/assistant/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/Michael/django/lab01/lab01project/assistant/models.py b/Code/Michael/django/lab01/lab01project/assistant/models.py new file mode 100644 index 00000000..d0f7d970 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/models.py @@ -0,0 +1,41 @@ +from django.db import models +from users.models import CustomUser + + +class Priority(models.Model): + + PRIORITY_CHOICES = [ + (0, "Completed"), + (1, "Low"), + (2, "Medium"), + (3, "High"), + ] + name = models.IntegerField(choices=PRIORITY_CHOICES, default=2) + + def __str__(self): + if self.name == 1: + return "Low" + elif self.name == 2: + return "Medium" + elif self.name == 3: + return "High" + elif self.name == 0: + return "Completed" + + class Meta: + verbose_name_plural = "Priorities" + ordering = ["name"] + + +class TodoItem(models.Model): + name = models.CharField(max_length=250) + description = models.TextField() + priority = models.ForeignKey("Priority", on_delete=models.CASCADE) + owner = models.ForeignKey(CustomUser, on_delete=models.CASCADE) + completed = models.DateTimeField(null=True, blank=True) + + def __str__(self): + return self.name + + class Meta: + ordering = ["-priority"] diff --git a/Code/Michael/django/lab01/lab01project/assistant/tests.py b/Code/Michael/django/lab01/lab01project/assistant/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/Michael/django/lab01/lab01project/assistant/urls.py b/Code/Michael/django/lab01/lab01project/assistant/urls.py new file mode 100644 index 00000000..3dd95d6e --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from . import views + +app_name = "assistant" +urlpatterns = [ + path("index/", views.index, name="index"), # TODO: Change to landing page + path("new/", views.create_task, name="create_task"), + path("", views.view_all_tasks, name="view_all_tasks"), + path("delete//", views.delete_task, name="delete_task"), + path("complete//", views.complete_task, name="complete_task"), +] diff --git a/Code/Michael/django/lab01/lab01project/assistant/views.py b/Code/Michael/django/lab01/lab01project/assistant/views.py new file mode 100644 index 00000000..92203e85 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/assistant/views.py @@ -0,0 +1,58 @@ +from datetime import datetime +from random import randint +from django.shortcuts import render, get_object_or_404, reverse +from django.http import HttpResponseRedirect +from .models import * +from django.contrib.auth.decorators import login_required + + +# Index page +def index(request): + return HttpResponseRedirect(reverse("assistant:view_all_tasks")) + + +# Creates a task +@login_required +def create_task(request): + if request.method == "POST": + try: + Priority.objects.get(name=int(request.POST["priority"])) + except: + Priority.objects.create(name=int(request.POST["priority"])) + TodoItem( + name=request.POST["name"], + description=request.POST["description"], + owner=request.user, + priority=Priority.objects.get(name=int(request.POST["priority"])), + ).save() + return HttpResponseRedirect(reverse("assistant:view_all_tasks")) + else: + return render(request, "assistant/create_task.html") + + +# Deletes a task +@login_required +def delete_task(request, task_id): + get_object_or_404(TodoItem, pk=task_id).delete() + return HttpResponseRedirect(reverse("assistant:view_all_tasks")) + + +# Shows all tasks +@login_required +def view_all_tasks(request): + tasks = TodoItem.objects.all() + return render(request, "assistant/task_list.html", {"tasks": tasks}) + + +# Completes a task +@login_required +def complete_task(request, task_id): + try: + Priority.objects.get(name=0) + except: + Priority.objects.create(name=0) + task = get_object_or_404(TodoItem, pk=task_id) + task.completed = datetime.now() + task.priority = Priority.objects.get(name=0) + task.save() + return HttpResponseRedirect(reverse("assistant:view_all_tasks")) diff --git a/Code/Michael/django/lab01/lab01project/manage.py b/Code/Michael/django/lab01/lab01project/manage.py new file mode 100644 index 00000000..385f01bd --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/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", "personalassistant.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/Michael/django/lab01/lab01project/personalassistant.sqlite b/Code/Michael/django/lab01/lab01project/personalassistant.sqlite new file mode 100644 index 00000000..e87b233a Binary files /dev/null and b/Code/Michael/django/lab01/lab01project/personalassistant.sqlite differ diff --git a/Code/Michael/django/lab01/lab01project/personalassistant/__init__.py b/Code/Michael/django/lab01/lab01project/personalassistant/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/Michael/django/lab01/lab01project/personalassistant/asgi.py b/Code/Michael/django/lab01/lab01project/personalassistant/asgi.py new file mode 100644 index 00000000..83e32069 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/personalassistant/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for personalassistant 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", "personalassistant.settings") + +application = get_asgi_application() diff --git a/Code/Michael/django/lab01/lab01project/personalassistant/settings.py b/Code/Michael/django/lab01/lab01project/personalassistant/settings.py new file mode 100644 index 00000000..9dabe58f --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/personalassistant/settings.py @@ -0,0 +1,128 @@ +""" +Django settings for personalassistant project. + +Generated by 'django-admin startproject' using Django 4.0. + +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-+3)ix-qjqtkqc=4sqw$9%tc4klv-gfu9cl-vje#=dmhxux9g4%" + +# 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", + "users", + "assistant", +] + +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 = "personalassistant.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": ["templates"], + "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 = "personalassistant.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": "personalassistant.sqlite", + } +} + +# 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/" +STATICFILES_DIRS = [str(BASE_DIR.joinpath("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" + +AUTH_USER_MODEL = "users.CustomUser" + +LOGIN_URL = "/users/login/" diff --git a/Code/Michael/django/lab01/lab01project/personalassistant/urls.py b/Code/Michael/django/lab01/lab01project/personalassistant/urls.py new file mode 100644 index 00000000..be22452b --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/personalassistant/urls.py @@ -0,0 +1,23 @@ +"""personalassistant 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 include, path + +urlpatterns = [ + path("admin/", admin.site.urls), + path("users/", include("users.urls")), + path("", include("assistant.urls")), +] diff --git a/Code/Michael/django/lab01/lab01project/personalassistant/wsgi.py b/Code/Michael/django/lab01/lab01project/personalassistant/wsgi.py new file mode 100644 index 00000000..54eeddcb --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/personalassistant/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for personalassistant 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", "personalassistant.settings") + +application = get_wsgi_application() diff --git a/Code/Michael/django/lab01/lab01project/requirements.txt b/Code/Michael/django/lab01/lab01project/requirements.txt new file mode 100644 index 00000000..c0382900 Binary files /dev/null and b/Code/Michael/django/lab01/lab01project/requirements.txt differ diff --git a/Code/Michael/django/lab01/lab01project/static/css/reset.css b/Code/Michael/django/lab01/lab01project/static/css/reset.css new file mode 100644 index 00000000..c75ebbca --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/static/css/reset.css @@ -0,0 +1,173 @@ +/* +html5doctor.com Reset Stylesheet +v1.6.1 +Last Updated: 2010-09-17 +Author: Richard Clark - http://richclarkdesign.com +Twitter: @rich_clark +*/ + +html, +body, +div, +span, +object, +iframe, +h1, +h2, +h3, +h4, +h5, +h6, +p, +blockquote, +pre, +abbr, +address, +cite, +code, +del, +dfn, +em, +img, +ins, +kbd, +q, +samp, +small, +strong, +sub, +sup, +var, +b, +i, +dl, +dt, +dd, +ol, +ul, +li, +fieldset, +form, +label, +legend, +table, +caption, +tbody, +tfoot, +thead, +tr, +th, +td, +article, +aside, +canvas, +details, +figcaption, +figure, +footer, +header, +hgroup, +menu, +nav, +section, +summary, +time, +mark, +audio, +video { + margin: 0; + padding: 0; + border: 0; + outline: 0; + font-size: 100%; + vertical-align: baseline; + background: transparent; +} + +body { + line-height: 1; +} + +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +menu, +nav, +section { + display: block; +} + +nav ul { + list-style: none; +} + +blockquote, +q { + quotes: none; +} + +blockquote:before, +blockquote:after, +q:before, +q:after { + content: ""; + content: none; +} + +a { + margin: 0; + padding: 0; + font-size: 100%; + vertical-align: baseline; + background: transparent; +} + +/* change colours to suit your needs */ +ins { + background-color: #ff9; + color: #000; + text-decoration: none; +} + +/* change colours to suit your needs */ +mark { + background-color: #ff9; + color: #000; + font-style: italic; + font-weight: bold; +} + +del { + text-decoration: line-through; +} + +abbr[title], +dfn[title] { + border-bottom: 1px dotted; + cursor: help; +} + +table { + border-collapse: collapse; + border-spacing: 0; +} + +/* change border colour to suit your needs */ +hr { + display: block; + height: 1px; + border: 0; + border-top: 1px solid #cccccc; + margin: 1em 0; + padding: 0; +} + +input, +select { + vertical-align: middle; +} diff --git a/Code/Michael/django/lab01/lab01project/static/js/main.js b/Code/Michael/django/lab01/lab01project/static/js/main.js new file mode 100644 index 00000000..c7830dc0 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/static/js/main.js @@ -0,0 +1,7 @@ +// Toggle display of id edit-form when edit edit-button is clicked +$(document).ready(function () { + $("#edit-form").toggle(); + $("#edit-button").click(function () { + $("#edit-form").toggle(); + }); +}); diff --git a/Code/Michael/django/lab01/lab01project/templates/assistant/create_task.html b/Code/Michael/django/lab01/lab01project/templates/assistant/create_task.html new file mode 100644 index 00000000..32921aad --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/templates/assistant/create_task.html @@ -0,0 +1,41 @@ +{% extends 'base.html' %} {% block content %} {% load static %} + +
+
+
+ {% csrf_token %} +
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ +{% endblock %} diff --git a/Code/Michael/django/lab01/lab01project/templates/assistant/index.html b/Code/Michael/django/lab01/lab01project/templates/assistant/index.html new file mode 100644 index 00000000..70bad81c --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/templates/assistant/index.html @@ -0,0 +1,4 @@ +{% extends 'base.html' %} {% block content %} {% load static %} +

Todo Today

+

Hello Moto World!

+{% endblock %} diff --git a/Code/Michael/django/lab01/lab01project/templates/assistant/task_list.html b/Code/Michael/django/lab01/lab01project/templates/assistant/task_list.html new file mode 100644 index 00000000..d001e0b5 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/templates/assistant/task_list.html @@ -0,0 +1,51 @@ +{% extends 'base.html' %} {% block content %} {% load static %} +
+
+ + + + + + + + + + + + + {% for task in tasks %} + {% if task.completed %} + + {% elif task.priority == "High" %} + + {% elif task.priority == "Medium" %} + + {% elif task.priority == "Low" %} + + {% else %} + + {% endif %} + + + + + + + + {% endfor %} + +
#NameDescriptionPriorityOwnerActions
{{ task.id }}{{ task.name }}{{ task.description }}{{ task.priority }}{{ task.owner }} + {% if not task.completed %} + Completed + {% else %} + Completed + {% endif %} + Delete +
+ +
+
+{% endblock %} diff --git a/Code/Michael/django/lab01/lab01project/templates/base.html b/Code/Michael/django/lab01/lab01project/templates/base.html new file mode 100644 index 00000000..c806724a --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/templates/base.html @@ -0,0 +1,49 @@ +{% load static %} + + + + + + + Personal Assistant + + + + + + +
+ +
+ {% block navbar %} {% include 'partials/_navbar.html' %} + + {% endblock %} +
+ + +
+
+
{% block content %}{% endblock %}
+
+
+ +
+ {% block footer %} {% include 'partials/_footer.html' %} + + {% endblock %} +
+
+ + + + + diff --git a/Code/Michael/django/lab01/lab01project/templates/partials/_footer.html b/Code/Michael/django/lab01/lab01project/templates/partials/_footer.html new file mode 100644 index 00000000..6604a867 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/templates/partials/_footer.html @@ -0,0 +1,7 @@ +{% load static %} +
+
+ © 2020 Personal Assistant + +
+
diff --git a/Code/Michael/django/lab01/lab01project/templates/partials/_navbar.html b/Code/Michael/django/lab01/lab01project/templates/partials/_navbar.html new file mode 100644 index 00000000..58d4f049 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/templates/partials/_navbar.html @@ -0,0 +1,69 @@ +{% load static %} +
+ +
diff --git a/Code/Michael/django/lab01/lab01project/templates/users/account.html b/Code/Michael/django/lab01/lab01project/templates/users/account.html new file mode 100644 index 00000000..703d5e1a --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/templates/users/account.html @@ -0,0 +1,37 @@ +{% extends 'base.html' %}{% block content %}{% load static %} + +

Account

+ +{% if error%} +

{{error}}

+{% endif%} {% csrf_token %} + +

Username: {{user.username}}

+

Email: {{user.email}}

+

First Name: {{user.first_name}}

+

Last Name: {{user.last_name}}

+ + + + +
+ {% csrf_token %} + + + + + + +
+ +{% endblock content %} diff --git a/Code/Michael/django/lab01/lab01project/templates/users/login.html b/Code/Michael/django/lab01/lab01project/templates/users/login.html new file mode 100644 index 00000000..f3e93f83 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/templates/users/login.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} {% block content %} {% load static %} +

Log in

+ +
+ + {% if error%} +

{{error}}

+ {% endif%} {% csrf_token %} + + + + + + + +
+ +{% endblock content %} diff --git a/Code/Michael/django/lab01/lab01project/templates/users/register.html b/Code/Michael/django/lab01/lab01project/templates/users/register.html new file mode 100644 index 00000000..e00e91f2 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/templates/users/register.html @@ -0,0 +1,16 @@ +{% extends 'base.html' %} {% block content %} {% load static %} +

Register

+ +
+ {% csrf_token %} + + + + + + + + +
+ +{% endblock content %} diff --git a/Code/Michael/django/lab01/lab01project/users/__init__.py b/Code/Michael/django/lab01/lab01project/users/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/Michael/django/lab01/lab01project/users/admin.py b/Code/Michael/django/lab01/lab01project/users/admin.py new file mode 100644 index 00000000..7fe4a5c0 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/users/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from django.contrib.auth.admin import UserAdmin +from .models import CustomUser + +# Register your models here. +admin.site.register(CustomUser, UserAdmin) diff --git a/Code/Michael/django/lab01/lab01project/users/apps.py b/Code/Michael/django/lab01/lab01project/users/apps.py new file mode 100644 index 00000000..88f7b179 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/users/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "users" diff --git a/Code/Michael/django/lab01/lab01project/users/migrations/0001_initial.py b/Code/Michael/django/lab01/lab01project/users/migrations/0001_initial.py new file mode 100644 index 00000000..db75b6b3 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/users/migrations/0001_initial.py @@ -0,0 +1,132 @@ +# Generated by Django 3.2.10 on 2022-03-06 17:32 + +import django.contrib.auth.models +import django.contrib.auth.validators +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ("auth", "0012_alter_user_first_name_max_length"), + ] + + operations = [ + migrations.CreateModel( + name="CustomUser", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("password", models.CharField(max_length=128, verbose_name="password")), + ( + "last_login", + models.DateTimeField( + blank=True, null=True, verbose_name="last login" + ), + ), + ( + "is_superuser", + models.BooleanField( + default=False, + help_text="Designates that this user has all permissions without explicitly assigning them.", + verbose_name="superuser status", + ), + ), + ( + "username", + models.CharField( + error_messages={ + "unique": "A user with that username already exists." + }, + help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.", + max_length=150, + unique=True, + validators=[ + django.contrib.auth.validators.UnicodeUsernameValidator() + ], + verbose_name="username", + ), + ), + ( + "first_name", + models.CharField( + blank=True, max_length=150, verbose_name="first name" + ), + ), + ( + "last_name", + models.CharField( + blank=True, max_length=150, verbose_name="last name" + ), + ), + ( + "email", + models.EmailField( + blank=True, max_length=254, verbose_name="email address" + ), + ), + ( + "is_staff", + models.BooleanField( + default=False, + help_text="Designates whether the user can log into this admin site.", + verbose_name="staff status", + ), + ), + ( + "is_active", + models.BooleanField( + default=True, + help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.", + verbose_name="active", + ), + ), + ( + "date_joined", + models.DateTimeField( + default=django.utils.timezone.now, verbose_name="date joined" + ), + ), + ( + "groups", + models.ManyToManyField( + blank=True, + help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.", + related_name="user_set", + related_query_name="user", + to="auth.Group", + verbose_name="groups", + ), + ), + ( + "user_permissions", + models.ManyToManyField( + blank=True, + help_text="Specific permissions for this user.", + related_name="user_set", + related_query_name="user", + to="auth.Permission", + verbose_name="user permissions", + ), + ), + ], + options={ + "verbose_name": "user", + "verbose_name_plural": "users", + "abstract": False, + }, + managers=[ + ("objects", django.contrib.auth.models.UserManager()), + ], + ), + ] diff --git a/Code/Michael/django/lab01/lab01project/users/migrations/__init__.py b/Code/Michael/django/lab01/lab01project/users/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/Michael/django/lab01/lab01project/users/models.py b/Code/Michael/django/lab01/lab01project/users/models.py new file mode 100644 index 00000000..c4b04105 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/users/models.py @@ -0,0 +1,13 @@ +from django.contrib.auth.models import AbstractUser + +# Create your models here. +class CustomUser(AbstractUser): + """ + Custom user model + """ + + pass + + +def __str__(self): + return self.username diff --git a/Code/Michael/django/lab01/lab01project/users/tests.py b/Code/Michael/django/lab01/lab01project/users/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/users/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/Michael/django/lab01/lab01project/users/urls.py b/Code/Michael/django/lab01/lab01project/users/urls.py new file mode 100644 index 00000000..51f1164e --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/users/urls.py @@ -0,0 +1,12 @@ +from django.urls import path + +from . import views + +app_name = "users" +urlpatterns = [ + path("register/", views.register, name="register"), + path("login/", views.login, name="login"), + path("logout/", views.logout, name="logout"), + path("account/", views.account, name="account"), + # path('account/', views.edit_user, name='edit_user'), +] diff --git a/Code/Michael/django/lab01/lab01project/users/views.py b/Code/Michael/django/lab01/lab01project/users/views.py new file mode 100644 index 00000000..c84782ec --- /dev/null +++ b/Code/Michael/django/lab01/lab01project/users/views.py @@ -0,0 +1,70 @@ +from django.shortcuts import render, reverse +from django.http import HttpResponseRedirect +from django.contrib.auth import ( + authenticate, + login as django_login, + logout as django_logout, +) +from users.models import CustomUser + + +def register(request): + if request.method == "GET": + return render(request, "users/register.html") + + elif request.method == "POST": + form = request.POST + + username = form["username"] + password = form["password"] + + new_user = CustomUser.objects.create_user( + username=username, + password=password, + ) + + django_login(request, new_user) + return HttpResponseRedirect(reverse("assistant:index")) + + +def login(request): + if request.method == "GET": + return render(request, "users/login.html") + + elif request.method == "POST": + form = request.POST + + username = form["username"] + password = form["password"] + + user = authenticate(request, username=username, password=password) + + if user is None: + return render( + request, "users/login.html", {"error": "Invalid Username or Password!"} + ) + + django_login(request, user) + return HttpResponseRedirect(reverse("assistant:index")) + + +def logout(request): + django_logout(request) + return HttpResponseRedirect(reverse("assistant:index")) + + +def account(request): + if request.method == "GET": + return render(request, "users/account.html") + elif request.method == "POST": + form = request.POST + + username = form["username"] + password = form["password"] + + user = CustomUser.objects.get(username=username) + user.set_password(password) + user.save() + + django_login(request, user) + return render(request, "users/account.html")