diff --git a/code/Ronnie/daniel_example/.gitignore b/code/Ronnie/daniel_example/.gitignore new file mode 100644 index 00000000..969097fd --- /dev/null +++ b/code/Ronnie/daniel_example/.gitignore @@ -0,0 +1,138 @@ +# Django # +*.log +*.pot +*.pyc +**/__pycache__ +db.sqlite3 +media + + +# Backup files # +*.bak + +# If you are using PyCharm # +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# File-based project format +*.iws + +# IntelliJ +out/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Python # +*.py[cod] +*$py.class + +# Distribution / packaging +.Python build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +.pytest_cache/ +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Sublime Text # +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache +*.sublime-workspace +*.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files Package +Control.last-run +Control.ca-list +Control.ca-bundle +Control.system-ca-bundle +GitHub.sublime-settings + +# Visual Studio Code # +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history \ No newline at end of file diff --git a/code/Ronnie/docker_django_vue/backend/api/migrations/__init__.py b/code/Ronnie/daniel_example/CapstoneProject/__init__.py similarity index 100% rename from code/Ronnie/docker_django_vue/backend/api/migrations/__init__.py rename to code/Ronnie/daniel_example/CapstoneProject/__init__.py diff --git a/code/Ronnie/daniel_example/CapstoneProject/asgi.py b/code/Ronnie/daniel_example/CapstoneProject/asgi.py new file mode 100644 index 00000000..3edd8092 --- /dev/null +++ b/code/Ronnie/daniel_example/CapstoneProject/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for CapstoneProject 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', 'CapstoneProject.settings') + +application = get_asgi_application() diff --git a/code/Ronnie/daniel_example/CapstoneProject/settings.py b/code/Ronnie/daniel_example/CapstoneProject/settings.py new file mode 100644 index 00000000..bc4e8211 --- /dev/null +++ b/code/Ronnie/daniel_example/CapstoneProject/settings.py @@ -0,0 +1,132 @@ +""" +Django settings for CapstoneProject project. + +Generated by 'django-admin startproject' using Django 4.1. + +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-dsn2)dj-i@vvtr^hmo7kf$-ghi-2$bse&$t+-cef$e(i@nf*h4' + +# 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', + 'NuggetServer', +] + +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 = 'CapstoneProject.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [BASE_DIR / "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 = 'CapstoneProject.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 = 'EST' + +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' + +LOGIN_REDIRECT_URL = "/homepage/" + +# LOGIN_REDIRECT_URL = 'NuggetServer:login' +LOGOUT_REDIRECT_URL = 'NuggetServer:logout' +LOGIN_URL = 'login' + +STATICFILES_DIRS = [str(BASE_DIR.joinpath("static"))] diff --git a/code/Ronnie/daniel_example/CapstoneProject/urls.py b/code/Ronnie/daniel_example/CapstoneProject/urls.py new file mode 100644 index 00000000..204cb7d2 --- /dev/null +++ b/code/Ronnie/daniel_example/CapstoneProject/urls.py @@ -0,0 +1,12 @@ +from django.contrib import admin +from django.urls import path, include +from django.contrib.auth import views as auth_views + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('NuggetServer.urls')), + path('accounts/', include("django.contrib.auth.urls")), + path("login/", auth_views.LoginView.as_view(template_name = "login.html"), name='login'), + path("logout/", auth_views.LogoutView.as_view(), name='logout'), +] + diff --git a/code/Ronnie/daniel_example/CapstoneProject/wsgi.py b/code/Ronnie/daniel_example/CapstoneProject/wsgi.py new file mode 100644 index 00000000..9ea3c830 --- /dev/null +++ b/code/Ronnie/daniel_example/CapstoneProject/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for CapstoneProject 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', 'CapstoneProject.settings') + +application = get_wsgi_application() diff --git a/code/Ronnie/daniel_example/NuggetServer/__init__.py b/code/Ronnie/daniel_example/NuggetServer/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/code/Ronnie/daniel_example/NuggetServer/admin.py b/code/Ronnie/daniel_example/NuggetServer/admin.py new file mode 100644 index 00000000..4fa2e529 --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from .models import MyModel + +admin.site.register(MyModel) \ No newline at end of file diff --git a/code/Ronnie/daniel_example/NuggetServer/apps.py b/code/Ronnie/daniel_example/NuggetServer/apps.py new file mode 100644 index 00000000..eb8cc3f4 --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class NuggetserverConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'NuggetServer' diff --git a/code/Ronnie/daniel_example/NuggetServer/forms.py b/code/Ronnie/daniel_example/NuggetServer/forms.py new file mode 100644 index 00000000..f65fbf57 --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/forms.py @@ -0,0 +1,20 @@ +from django import forms +from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.models import User + + +# Create your forms here. + +class NewUserForm(UserCreationForm): + email = forms.EmailField(required=True) + + class Meta: + model = User + fields = ("username", "email", "password1", "password2") + + def save(self, commit=True): + user = super(NewUserForm, self).save(commit=False) + user.email = self.cleaned_data['email'] + if commit: + user.save() + return user \ No newline at end of file diff --git a/code/Ronnie/daniel_example/NuggetServer/models.py b/code/Ronnie/daniel_example/NuggetServer/models.py new file mode 100644 index 00000000..b22ab648 --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/models.py @@ -0,0 +1,7 @@ +from django.db import models + +class MyModel(models.Model): + myfield = models.CharField(max_length=200) + + def __str__(self): + return self.myfield \ No newline at end of file diff --git a/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/header.html b/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/header.html new file mode 100644 index 00000000..2506d6f9 --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/header.html @@ -0,0 +1,20 @@ + + + + + + + + + + + Title + + + + {% block content %} + + {% endblock %} + + + \ No newline at end of file diff --git a/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/index.html b/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/index.html new file mode 100644 index 00000000..3a7755ff --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/index.html @@ -0,0 +1,10 @@ + + + + + + + +

index

+ + \ No newline at end of file diff --git a/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/mytemplate.html b/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/mytemplate.html new file mode 100644 index 00000000..1df16dd8 --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/mytemplate.html @@ -0,0 +1,19 @@ + + + + + + + +
+ {% csrf_token %} + + +
+ + + \ No newline at end of file diff --git a/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/register.html b/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/register.html new file mode 100644 index 00000000..d3707648 --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/templates/NuggetServer/register.html @@ -0,0 +1,16 @@ +{% extends "NuggetServer/header.html" %} + +{% block content %} + + +
+

Register

+
+ {% csrf_token %} + {{ register_form }} + +
+

If you already have an account, login instead.

+
+ +{% endblock %} \ No newline at end of file diff --git a/code/Ronnie/daniel_example/NuggetServer/tests.py b/code/Ronnie/daniel_example/NuggetServer/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/code/Ronnie/daniel_example/NuggetServer/urls.py b/code/Ronnie/daniel_example/NuggetServer/urls.py new file mode 100644 index 00000000..9863c18d --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/urls.py @@ -0,0 +1,10 @@ +from django.urls import path +from . import views + +app_name = 'NuggetServer' +urlpatterns = [ + path('register/', views.register_request, name="register"), + path('home/', views.myhomepage, name='homepage'), + path('flash/', views.mycreate, name='FlashWifiNugget'), + path('database/', views.mycreate, name='MACDatabase'), +] \ No newline at end of file diff --git a/code/Ronnie/daniel_example/NuggetServer/views.py b/code/Ronnie/daniel_example/NuggetServer/views.py new file mode 100644 index 00000000..f09711a8 --- /dev/null +++ b/code/Ronnie/daniel_example/NuggetServer/views.py @@ -0,0 +1,51 @@ +from django.shortcuts import render, redirect +from .forms import NewUserForm +from django.contrib.auth import authenticate, login, logout +from django.contrib import messages +from django.http import HttpResponseRedirect, HttpResponse +from .models import MyModel +from django.contrib.auth.decorators import login_required +from django.contrib.auth.models import User + + +def register_request(request): + if request.method == "POST": + form = NewUserForm(request.POST) + if form.is_valid(): + user = form.save() + login(request, user) + messages.success(request, "Registration successful." ) + return redirect("NuggetServer:homepage") + messages.error(request, "Unsuccessful registration. Invalid information.") + else: + form = NewUserForm() + return render(request, template_name="NuggetServer/register.html", context={"register_form":form}) + + + + + + +@login_required +def myhomepage(request): + return render(request, "NuggetServer/index.html") + +# def myflash(request): +# print("flash") + +# def mydatabase(request): +# print("database") + + +def myview(request): + myinstances = MyModel.objects.all() + context = { + 'myinstances': myinstances + } + return render(request, 'NuggetServer/mytemplate.html', context) + +def mycreate(request): + myfield = request.POST['myfield'] + mymodel = MyModel(myfield=myfield) + mymodel.save() + return HttpResponseRedirect(reverse('NuggetServer:myview')) \ No newline at end of file diff --git a/code/Ronnie/daniel_example/manage.py b/code/Ronnie/daniel_example/manage.py new file mode 100755 index 00000000..e402ae00 --- /dev/null +++ b/code/Ronnie/daniel_example/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', 'CapstoneProject.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/Ronnie/daniel_example/static/catfaces.jpg b/code/Ronnie/daniel_example/static/catfaces.jpg new file mode 100644 index 00000000..b1433803 Binary files /dev/null and b/code/Ronnie/daniel_example/static/catfaces.jpg differ diff --git a/code/Ronnie/daniel_example/templates/registration/login.html b/code/Ronnie/daniel_example/templates/registration/login.html new file mode 100644 index 00000000..f6fad76f --- /dev/null +++ b/code/Ronnie/daniel_example/templates/registration/login.html @@ -0,0 +1,17 @@ + + + + + + + + +

Log In

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ + + \ No newline at end of file diff --git a/code/Ronnie/docker_django_vue/.dockerignore b/code/Ronnie/docker_django_vue/.dockerignore new file mode 100644 index 00000000..05a4a449 --- /dev/null +++ b/code/Ronnie/docker_django_vue/.dockerignore @@ -0,0 +1 @@ +*/node_modules \ No newline at end of file diff --git a/code/Ronnie/docker_django_vue/backend/api/admin.py b/code/Ronnie/docker_django_vue/backend/api/admin.py index 8c38f3f3..27b5ea6e 100644 --- a/code/Ronnie/docker_django_vue/backend/api/admin.py +++ b/code/Ronnie/docker_django_vue/backend/api/admin.py @@ -1,3 +1,5 @@ from django.contrib import admin +from .models import ToDo # Register your models here. +admin.site.register(ToDo) \ No newline at end of file diff --git a/code/Ronnie/docker_django_vue/backend/api/models.py b/code/Ronnie/docker_django_vue/backend/api/models.py index 71a83623..12aeff72 100644 --- a/code/Ronnie/docker_django_vue/backend/api/models.py +++ b/code/Ronnie/docker_django_vue/backend/api/models.py @@ -1,3 +1,9 @@ from django.db import models # Create your models here. +class ToDo(models.Model): + title = models.CharField(max_length=200) + status = models.BooleanField(default=False) + + def __str__(self): + return self.title \ No newline at end of file diff --git a/code/Ronnie/docker_django_vue/backend/api/serializers.py b/code/Ronnie/docker_django_vue/backend/api/serializers.py new file mode 100644 index 00000000..fc2fb3bc --- /dev/null +++ b/code/Ronnie/docker_django_vue/backend/api/serializers.py @@ -0,0 +1,7 @@ +from rest_framework import serializers +from .models import ToDo + +class ToDoSerializer(serializers.ModelSerializer): + class Meta: + fields = ('title', 'status') + model = ToDo \ No newline at end of file diff --git a/code/Ronnie/docker_django_vue/backend/api/urls.py b/code/Ronnie/docker_django_vue/backend/api/urls.py new file mode 100644 index 00000000..39c19410 --- /dev/null +++ b/code/Ronnie/docker_django_vue/backend/api/urls.py @@ -0,0 +1,10 @@ +from rest_framework.routers import DefaultRouter +from django.urls import path +from .views import ToDoViewSet + +router = DefaultRouter() +router.register('todo', ToDoViewSet, basename='ToDo') + +urlpatterns = router.urls + [ + +] \ No newline at end of file diff --git a/code/Ronnie/docker_django_vue/backend/api/views.py b/code/Ronnie/docker_django_vue/backend/api/views.py index 91ea44a2..1a3d5518 100644 --- a/code/Ronnie/docker_django_vue/backend/api/views.py +++ b/code/Ronnie/docker_django_vue/backend/api/views.py @@ -1,3 +1,9 @@ -from django.shortcuts import render - +from rest_framework import viewsets +from .models import ToDo +from .serializers import ToDoSerializer # Create your views here. +class ToDoViewSet(viewsets.ModelViewSet): + queryset = ToDo.objects.all() + serializer_class = ToDoSerializer + # Api methods + http_method_names = ["get", "post", "head", "delete", "put"] \ No newline at end of file diff --git a/code/Ronnie/docker_django_vue/backend/project/settings.py b/code/Ronnie/docker_django_vue/backend/project/settings.py index 9907dede..63198b06 100644 --- a/code/Ronnie/docker_django_vue/backend/project/settings.py +++ b/code/Ronnie/docker_django_vue/backend/project/settings.py @@ -9,7 +9,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.1/ref/settings/ """ - +import os from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -37,9 +37,14 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'rest_framework', + 'corsheaders', + 'api', ] MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.common.CommonMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -54,7 +59,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -121,3 +126,11 @@ # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.AllowAny', + ] +} + +CORS_ORIGIN_ALLOW_ALL = True \ No newline at end of file diff --git a/code/Ronnie/docker_django_vue/backend/project/urls.py b/code/Ronnie/docker_django_vue/backend/project/urls.py index 6ebb218c..a31b93c8 100644 --- a/code/Ronnie/docker_django_vue/backend/project/urls.py +++ b/code/Ronnie/docker_django_vue/backend/project/urls.py @@ -14,8 +14,11 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include +from django.views.generic import TemplateView urlpatterns = [ path('admin/', admin.site.urls), + path('api/', include('api.urls')), + path('', TemplateView.as_view(template_name='index.html'), name='index'), ] diff --git a/code/Ronnie/docker_django_vue/backend/requirements.txt b/code/Ronnie/docker_django_vue/backend/requirements.txt index c2e4835f..ae70e869 100644 --- a/code/Ronnie/docker_django_vue/backend/requirements.txt +++ b/code/Ronnie/docker_django_vue/backend/requirements.txt @@ -1,4 +1,12 @@ +asgiref==3.5.2 +certifi==2022.9.14 +charset-normalizer==2.1.1 Django==4.1 +django-cors-headers==3.13.0 djangorestframework==3.14.0 +idna==3.4 Pillow==9.2.0 +pytz==2022.2.1 requests==2.28.1 +sqlparse==0.4.2 +urllib3==1.26.12 diff --git a/code/Ronnie/docker_django_vue/backend/templates/index.html b/code/Ronnie/docker_django_vue/backend/templates/index.html new file mode 100644 index 00000000..dfda8700 --- /dev/null +++ b/code/Ronnie/docker_django_vue/backend/templates/index.html @@ -0,0 +1,70 @@ + + + + + + + + + ToDo Items + + +
+
+ +
+ +
+ + + +