diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/__init__.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/__init__.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/admin.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/apps.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/apps.py new file mode 100644 index 0000000..06273c9 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class BookAppConfig(AppConfig): + name = 'book_app' diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/migrations/0001_initial.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/migrations/0001_initial.py new file mode 100644 index 0000000..c9cac84 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/migrations/0001_initial.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-15 21:39 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Author', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='Book', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('desc', models.TextField(null=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.AddField( + model_name='author', + name='books', + field=models.ManyToManyField(related_name='authors', to='book_app.Book'), + ), + ] diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/migrations/0002_author_notes.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/migrations/0002_author_notes.py new file mode 100644 index 0000000..de56495 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/migrations/0002_author_notes.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-15 21:47 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('book_app', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='author', + name='notes', + field=models.TextField(null=True), + ), + ] diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/migrations/__init__.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/models.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/models.py new file mode 100644 index 0000000..8c5bde6 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/models.py @@ -0,0 +1,24 @@ +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. +class Book(models.Model): + name = models.CharField(max_length=255) + desc = models.TextField(null = True) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(max_length=255) + def __unicode__(self): + return "id: " + str(self.id) + ", name: " + self.name + ", authors: " + str(self.authors) + ", desc: " + str(self.desc) + ", created_at:" + str(self.created_at) + ", updated_at: " + str(self.updated_at) + +class Author(models.Model): + first_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) + email = models.CharField(max_length=255) + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + notes = models.TextField(null = True) + books = models.ManyToManyField(Book, related_name = "authors") + + def __unicode__(self): + return "id: " + str(self.id) + ", first_name: " + self.first_name + ", last_name: " + self.last_name + ", email: " + self.email + ", books: " + str(self.books) + ", notes: " + str(self.notes) + ", created_at:" + str(self.created_at) + ", updated_at: " + str(self.updated_at) \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/tests.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/urls.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/urls.py new file mode 100644 index 0000000..42b9825 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url +from . import views # This line is new! + +urlpatterns = [ + url(r'^$', views.index), +] \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/views.py b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/views.py new file mode 100644 index 0000000..de08e44 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/apps/book_app/views.py @@ -0,0 +1,9 @@ +from django.shortcuts import render + +# Create your views here. +from django.shortcuts import render, redirect + +# Create your views here. +def index(request): + + return render(request, 'book_app/index.html') \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/db.sqlite3 b/justin_quiros/python_stack/django_projects/books_authors/main/db.sqlite3 new file mode 100644 index 0000000..0a78abe Binary files /dev/null and b/justin_quiros/python_stack/django_projects/books_authors/main/db.sqlite3 differ diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/main/__init__.py b/justin_quiros/python_stack/django_projects/books_authors/main/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/main/settings.py b/justin_quiros/python_stack/django_projects/books_authors/main/main/settings.py new file mode 100644 index 0000000..04b22ff --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/main/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for main project. + +Generated by 'django-admin startproject' using Django 1.10. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '#8qd4e@b*_66av=0nq%yl5@p#*%&8v^)*kh)m9!-)98bj8$!bu' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.book_app', + '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 = 'main.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 = 'main.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/main/urls.py b/justin_quiros/python_stack/django_projects/books_authors/main/main/urls.py new file mode 100644 index 0000000..0f070b7 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/main/urls.py @@ -0,0 +1,21 @@ +"""main URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.10/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url, include +from django.contrib import admin + +urlpatterns = [ + url(r'^', include('apps.book_app.urls')), +] diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/main/wsgi.py b/justin_quiros/python_stack/django_projects/books_authors/main/main/wsgi.py new file mode 100644 index 0000000..4d1e3f4 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/main/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for main 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/1.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") + +application = get_wsgi_application() diff --git a/justin_quiros/python_stack/django_projects/books_authors/main/manage.py b/justin_quiros/python_stack/django_projects/books_authors/main/manage.py new file mode 100755 index 0000000..ad5d3e7 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/books_authors/main/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + 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?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/__init__.py b/justin_quiros/python_stack/django_projects/courses/courses/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/__init__.py b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/admin.py b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/apps.py b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/apps.py new file mode 100644 index 0000000..a51a109 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class CourseReviewConfig(AppConfig): + name = 'course_review' diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/migrations/0001_initial.py b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/migrations/0001_initial.py new file mode 100644 index 0000000..14c5240 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-17 02:44 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Course', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('desc', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/migrations/__init__.py b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/models.py b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/models.py new file mode 100644 index 0000000..e0a4ddd --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/models.py @@ -0,0 +1,43 @@ +from __future__ import unicode_literals + +from django.db import models + +class CourseManager(models.Manager): + + def course_validation(self, form_data): + errors = {} + + + if len(form_data['name']) == 0: + errors['name'] = "Course name is required." + + if len(form_data['name']) < 5: + errors['name'] = "Course name must be atleast 5 characters." + + if len(form_data['desc']) < 15: + errors['desc'] = "Course description must be atleast 15 characters." + + + # if len(form_data['name']) == 0: + # errors.append('Course name is required.') + + # if len(form_data['name']) < 5: + # errors.append('Course name must be atleast 5 characters.') + + # if len(form_data['desc']) < 15: + # errors.append('Course description must be atleast 15 characters.') + + return errors + + + +class Course(models.Model): + name = models.CharField(max_length=255) + desc = models.CharField(max_length=255) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + objects = CourseManager() + + def __unicode__(self): + return "id: " + str(self.id) + ", name: " + self.name + ", desc: " + self.desc \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/templates/course_review/destroy.html b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/templates/course_review/destroy.html new file mode 100644 index 0000000..b5c49b9 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/templates/course_review/destroy.html @@ -0,0 +1,17 @@ + + + + {% load static %} + + Courses + + + + +

Delete a course

+

Are you sure you want to delete the following course?

+

Name: {{name}}

+

Description: {{desc}}

+ remove + + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/templates/course_review/index.html b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/templates/course_review/index.html new file mode 100644 index 0000000..70e048f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/templates/course_review/index.html @@ -0,0 +1,47 @@ + + + + {% load static %} + + Courses + + + + +

Add a new course

+ {% for message in messages %} + {{message}} + {% endfor %} +
+ {% csrf_token %} + + +
+ +
+ +
+
+

Courses

+ + + + + + + + + + + {% for course in courses %} + + + + + + + {% endfor %} + +
Course NameDescriptionDate AddedActions
{{course.name}}{{course.desc}}{{course.created_at}}remove
+ + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/tests.py b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/urls.py b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/urls.py new file mode 100644 index 0000000..e7461ef --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/urls.py @@ -0,0 +1,9 @@ +from django.conf.urls import url +from . import views # This line is new! + +urlpatterns = [ + url(r'^$', views.index), + url(r'courses/create', views.create), + url(r'courses/destroy/(?P\d+)', views.destroy), + url(r'courses/delete/(?P\d+)', views.delete) +] \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/views.py b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/views.py new file mode 100644 index 0000000..64c9441 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/apps/course_review/views.py @@ -0,0 +1,35 @@ +from django.shortcuts import render, redirect + +# Create your views here. +from django.shortcuts import render, redirect +from django.contrib import messages +from .models import Course + +# Create your views here. +def index(request): + context = { + "courses": Course.objects.all() + } + return render(request, 'course_review/index.html', context) + +def destroy(request, course_id): + context = { + "id": (Course.objects.get(id=course_id).id), + "name": (Course.objects.get(id=course_id).name), + "desc": (Course.objects.get(id=course_id).desc) + } + return render(request, 'course_review/destroy.html', context) + +def delete(request, id): + Course.objects.get(id=id).delete() + return redirect('/') + +def create(request): + errors = Course.objects.course_validation(request.POST) + if len(errors): + for tag, error in errors.iteritems(): + messages.error(request, error, extra_tags = tag) + return redirect('/') + else: + Course.objects.create(name=request.POST['name'], desc=request.POST['desc']) + return redirect('/') \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/courses/courses/courses/__init__.py b/justin_quiros/python_stack/django_projects/courses/courses/courses/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/courses/courses/courses/settings.py b/justin_quiros/python_stack/django_projects/courses/courses/courses/settings.py new file mode 100644 index 0000000..3b1e7b7 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/courses/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for courses project. + +Generated by 'django-admin startproject' using Django 1.10. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '60!$l^7vf+qkqzo(_8v*2z)fl=pewhyf$u7g(5*1d#kz_e_4*2' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.course_review', + '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 = 'courses.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 = 'courses.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/justin_quiros/python_stack/django_projects/courses/courses/courses/urls.py b/justin_quiros/python_stack/django_projects/courses/courses/courses/urls.py new file mode 100644 index 0000000..1fb3d86 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/courses/urls.py @@ -0,0 +1,21 @@ +"""courses URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.10/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url, include +from django.contrib import admin + +urlpatterns = [ + url(r'^', include('apps.course_review.urls')), +] diff --git a/justin_quiros/python_stack/django_projects/courses/courses/courses/wsgi.py b/justin_quiros/python_stack/django_projects/courses/courses/courses/wsgi.py new file mode 100644 index 0000000..9da3dff --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/courses/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for courses 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/1.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "courses.settings") + +application = get_wsgi_application() diff --git a/justin_quiros/python_stack/django_projects/courses/courses/db.sqlite3 b/justin_quiros/python_stack/django_projects/courses/courses/db.sqlite3 new file mode 100644 index 0000000..d585944 Binary files /dev/null and b/justin_quiros/python_stack/django_projects/courses/courses/db.sqlite3 differ diff --git a/justin_quiros/python_stack/django_projects/courses/courses/manage.py b/justin_quiros/python_stack/django_projects/courses/courses/manage.py new file mode 100755 index 0000000..7594c9c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/courses/courses/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "courses.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + 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?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/justin_quiros/python_stack/django_projects/django_app/main/db.sqlite3 b/justin_quiros/python_stack/django_projects/django_app/main/db.sqlite3 index 62401a1..aa8b67f 100644 Binary files a/justin_quiros/python_stack/django_projects/django_app/main/db.sqlite3 and b/justin_quiros/python_stack/django_projects/django_app/main/db.sqlite3 differ diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/__init__.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/__init__.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/admin.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/apps.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/apps.py new file mode 100644 index 0000000..bdc48d8 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class DojoAppConfig(AppConfig): + name = 'dojo_app' diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/migrations/0001_initial.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/migrations/0001_initial.py new file mode 100644 index 0000000..f03fa99 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/migrations/0001_initial.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-15 20:13 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Dojo', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('city', models.CharField(max_length=255)), + ('state', models.CharField(max_length=2)), + ], + ), + migrations.CreateModel( + name='Ninja', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('dojo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ninjas', to='dojo_app.Dojo')), + ], + ), + ] diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/migrations/0002_dojo_desc.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/migrations/0002_dojo_desc.py new file mode 100644 index 0000000..25bb40d --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/migrations/0002_dojo_desc.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-15 21:07 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dojo_app', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='dojo', + name='desc', + field=models.TextField(null=True), + ), + ] diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/migrations/__init__.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/models.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/models.py new file mode 100644 index 0000000..eb2e4e8 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/models.py @@ -0,0 +1,22 @@ +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. +class Dojo(models.Model): + name = models.CharField(max_length=255) + city = models.CharField(max_length=255) + state = models.CharField(max_length=2) + desc = models.TextField(null = True) + def __unicode__(self): + return "id: " + str(self.id) + ", name: " + self.name + ", city: " + self.city + ", state:" + self.state + ", desc: " + str(self.desc) + + +class Ninja(models.Model): + first_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) + + dojo = models.ForeignKey(Dojo, related_name = "ninjas") + + def __unicode__(self): + return "id: " + str(self.id) + ", first_name: " + self.first_name + ", last_name: " + self.last_name + ", dojo: " + str(self.dojo) \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/static/dojo_app/css/style.css b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/static/dojo_app/css/style.css new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/templates/dojo_app/index.html b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/templates/dojo_app/index.html new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/tests.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/urls.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/urls.py new file mode 100644 index 0000000..42b9825 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url +from . import views # This line is new! + +urlpatterns = [ + url(r'^$', views.index), +] \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/views.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/views.py new file mode 100644 index 0000000..4a876c4 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/apps/dojo_app/views.py @@ -0,0 +1,9 @@ +from django.shortcuts import render + +# Create your views here. +from django.shortcuts import render, redirect + +# Create your views here. +def index(request): + + return render(request, 'dojo_app/index.html') \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/db.sqlite3 b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/db.sqlite3 new file mode 100644 index 0000000..e6c93cc Binary files /dev/null and b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/db.sqlite3 differ diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/__init__.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/settings.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/settings.py new file mode 100644 index 0000000..2a60c98 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for main project. + +Generated by 'django-admin startproject' using Django 1.10. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'g+w46!s7h*@w^#qit672)&rabk@_g+2wx_5w6j@(ki@99&9vr!' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.dojo_app', + '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 = 'main.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 = 'main.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/urls.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/urls.py new file mode 100644 index 0000000..9b03604 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/urls.py @@ -0,0 +1,21 @@ +"""main URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.10/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url, include +from django.contrib import admin + +urlpatterns = [ + url(r'^', include('apps.dojo_app.urls')), +] diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/wsgi.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/wsgi.py new file mode 100644 index 0000000..4d1e3f4 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/main/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for main 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/1.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") + +application = get_wsgi_application() diff --git a/justin_quiros/python_stack/django_projects/dojo_ninjas/main/manage.py b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/manage.py new file mode 100755 index 0000000..ad5d3e7 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/dojo_ninjas/main/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + 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?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/apps/__init__.py b/justin_quiros/python_stack/django_projects/likes_books/main/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/__init__.py b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/admin.py b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/apps.py b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/apps.py new file mode 100644 index 0000000..06273c9 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class BookAppConfig(AppConfig): + name = 'book_app' diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/migrations/0001_initial.py b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/migrations/0001_initial.py new file mode 100644 index 0000000..bea1bf9 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/migrations/0001_initial.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-16 13:31 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Book', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('desc', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.EmailField(max_length=254, unique=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.AddField( + model_name='book', + name='liked_by', + field=models.ManyToManyField(related_name='liked_books', to='book_app.User'), + ), + migrations.AddField( + model_name='book', + name='uploader', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='uploaded_books', to='book_app.User'), + ), + ] diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/migrations/__init__.py b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/models.py b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/models.py new file mode 100644 index 0000000..f1e7ee6 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/models.py @@ -0,0 +1,18 @@ +from __future__ import unicode_literals + +from django.db import models + +class User(models.Model): + first_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) + email = models.EmailField(unique=True) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + +class Book(models.Model): + name = models.CharField(max_length=255) + desc = models.CharField(max_length=255) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + uploader = models.ForeignKey(User, related_name="uploaded_books") + liked_by = models.ManyToManyField(User, related_name="liked_books") \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/tests.py b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/urls.py b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/urls.py new file mode 100644 index 0000000..42b9825 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url +from . import views # This line is new! + +urlpatterns = [ + url(r'^$', views.index), +] \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/views.py b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/views.py new file mode 100644 index 0000000..de08e44 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/apps/book_app/views.py @@ -0,0 +1,9 @@ +from django.shortcuts import render + +# Create your views here. +from django.shortcuts import render, redirect + +# Create your views here. +def index(request): + + return render(request, 'book_app/index.html') \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/db.sqlite3 b/justin_quiros/python_stack/django_projects/likes_books/main/db.sqlite3 new file mode 100644 index 0000000..59fa800 Binary files /dev/null and b/justin_quiros/python_stack/django_projects/likes_books/main/db.sqlite3 differ diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/main/__init__.py b/justin_quiros/python_stack/django_projects/likes_books/main/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/main/settings.py b/justin_quiros/python_stack/django_projects/likes_books/main/main/settings.py new file mode 100644 index 0000000..d636d6c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/main/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for main project. + +Generated by 'django-admin startproject' using Django 1.10. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'a8f(v@p36*ohs&6w)2$in+4j%1i-hr+^7w@a-&3r!2$i8s3m_u' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.book_app', + '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 = 'main.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 = 'main.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/main/urls.py b/justin_quiros/python_stack/django_projects/likes_books/main/main/urls.py new file mode 100644 index 0000000..0f070b7 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/main/urls.py @@ -0,0 +1,21 @@ +"""main URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.10/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url, include +from django.contrib import admin + +urlpatterns = [ + url(r'^', include('apps.book_app.urls')), +] diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/main/wsgi.py b/justin_quiros/python_stack/django_projects/likes_books/main/main/wsgi.py new file mode 100644 index 0000000..4d1e3f4 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/main/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for main 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/1.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") + +application = get_wsgi_application() diff --git a/justin_quiros/python_stack/django_projects/likes_books/main/manage.py b/justin_quiros/python_stack/django_projects/likes_books/main/manage.py new file mode 100755 index 0000000..ad5d3e7 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/likes_books/main/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + 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?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/__init__.py b/justin_quiros/python_stack/django_projects/login_reg/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/__init__.py b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/admin.py b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/apps.py b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/apps.py new file mode 100644 index 0000000..39e95c6 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class LoginAppConfig(AppConfig): + name = 'login_app' diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/migrations/0001_initial.py b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/migrations/0001_initial.py new file mode 100644 index 0000000..fc8f6ff --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-17 19:42 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('password', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/migrations/__init__.py b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/models.py b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/models.py new file mode 100644 index 0000000..4a82f5c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/models.py @@ -0,0 +1,71 @@ +from __future__ import unicode_literals + +from django.db import models +import bcrypt +import re +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') + +class UserManager(models.Manager): + + def register_validation(self, form_data): + errors = [] + + if len(form_data['first_name']) == 0: + errors.append( "First name is required.") + if len(form_data['last_name']) == 0: + errors.append("Last name is required") + if len(form_data['email']) == 0 or not EMAIL_REGEX.match(form_data['email']): + errors.append("Email is invalid.") + if len(form_data['password']) < 8: + errors.append("Email must be atleast 8 characters.") + if form_data['password'] != form_data['conf_password']: + errors.append("Passwords did not match.") + + duplicate = User.objects.filter(email = form_data['email']) + if len(duplicate) == 1: + errors.append("This email is already registered.") + + return errors + + + def register(self, form_data): + pw = str(form_data['password']) + hashed_pw = bcrypt.hashpw(pw, bcrypt.gensalt()) + + user = User.objects.create( + first_name = form_data['first_name'], + last_name = form_data['last_name'], + email = form_data['email'], + password = hashed_pw + ) + return user + + def login_validation(self, form_data): + errors = [] + user = User.objects.filter(email=form_data['email']).first() + print user + if user: + pw = str(form_data['password']) + user_password = str(user.password) + if not bcrypt.checkpw(pw.encode(), user_password.encode()): + errors.append("Invalid password.") + else: + errors.append("Invalid email.") + return errors + + def login(self, form_data): + user = User.objects.filter(email=form_data['email']).first() + return user + + +class User(models.Model): + first_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) + email = models.CharField(max_length=255) + password = models.CharField(max_length=255) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + objects = UserManager() + + def __unicode__(self): + return "id: " + str(self.id) + ", first_name: " + self.first_name + ", last_name: " + self.last_name + ", email:" + self.email + ", password:" + self.password diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/static/login_app/css/style.css b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/static/login_app/css/style.css new file mode 100644 index 0000000..6babea9 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/static/login_app/css/style.css @@ -0,0 +1,21 @@ +*{ + margin: 0px; + padding: 0px; +} + +input{ + float: right; +} + +h1{ + margin-left: 10px; + margin-bottom: 20px; +} + +form{ + width: 215px; + margin-bottom: 50px; + margin-left: 10PX; + border: solid 2px black; + padding: 10px 5px 25px 5px; +} \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/templates/login_app/index.html b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/templates/login_app/index.html new file mode 100644 index 0000000..372c89f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/templates/login_app/index.html @@ -0,0 +1,54 @@ + + + + {% load static %} + + Login and Registration + + + + +

Registration

+ {% for error in errors %} + {{error}} + {% endfor %} +
+ {% csrf_token %} + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+

Login

+
+ {% csrf_token %} + + +
+
+ + +
+
+ +
+ + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/templates/login_app/success.html b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/templates/login_app/success.html new file mode 100644 index 0000000..9002f73 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/templates/login_app/success.html @@ -0,0 +1,15 @@ + + + + {% load static %} + + Login and Registration + + + + +

Success! Welcome, {{request.session.name}}.

+

Succesfully {{request.session.status}}

+ Logout + + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/tests.py b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/urls.py b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/urls.py new file mode 100644 index 0000000..c998298 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/urls.py @@ -0,0 +1,10 @@ +from django.conf.urls import url +from . import views # This line is new! + +urlpatterns = [ + url(r'^$', views.index), + url(r'^courses/register', views.register), + url(r'^courses/login', views.login), + url(r'^logout', views.logout), + url(r'^success', views.success), +] \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/views.py b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/views.py new file mode 100644 index 0000000..360b066 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/apps/login_app/views.py @@ -0,0 +1,44 @@ +from django.shortcuts import render, redirect +from django.contrib import messages +from .models import User +# Create your views here. +def index(request): + request.session['status'] = "" + if 'errors' not in request.session: + request.session['errors'] = [] + context = { + "errors": request.session['errors'] + } + return render(request, 'login_app/index.html', context) + +def register(request): + if request.method == "POST": + errors = User.objects.register_validation(request.POST) + if len(errors) != 0: + request.session['errors'] = errors + print errors + return redirect('/') + else: + user = User.objects.register(request.POST) + request.session['user_id'] = user.id + request.session['status'] = "registered." + request.session['name'] = user.first_name + return redirect('/success') + +def login(request): + errors = User.objects.login_validation(request.POST) + if len(errors) != 0: + request.session['errors'] = errors + return redirect('/') + else: + user = User.objects.login(request.POST) + request.session['name'] = user.first_name + request.session['status'] = "logged in." + return render(request, 'login_app/success.html') + +def success(request): + return render(request, 'login_app/success.html') + +def logout(request): + request.session.clear() + return redirect('/') \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/login_reg/db.sqlite3 b/justin_quiros/python_stack/django_projects/login_reg/db.sqlite3 new file mode 100644 index 0000000..c7c5932 Binary files /dev/null and b/justin_quiros/python_stack/django_projects/login_reg/db.sqlite3 differ diff --git a/justin_quiros/python_stack/django_projects/login_reg/login_reg/__init__.py b/justin_quiros/python_stack/django_projects/login_reg/login_reg/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/login_reg/login_reg/settings.py b/justin_quiros/python_stack/django_projects/login_reg/login_reg/settings.py new file mode 100644 index 0000000..1466885 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/login_reg/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for login_reg project. + +Generated by 'django-admin startproject' using Django 1.10. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '2aat!jf86qql0s@3!zqht&$r^@noe3mj$3kf7oby4=m1cuyj$l' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.login_app', + '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 = 'login_reg.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 = 'login_reg.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/justin_quiros/python_stack/django_projects/login_reg/login_reg/urls.py b/justin_quiros/python_stack/django_projects/login_reg/login_reg/urls.py new file mode 100644 index 0000000..95ed3f2 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/login_reg/urls.py @@ -0,0 +1,21 @@ +"""login_reg URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.10/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url, include +from django.contrib import admin + +urlpatterns = [ + url(r'^', include('apps.login_app.urls')), +] diff --git a/justin_quiros/python_stack/django_projects/login_reg/login_reg/wsgi.py b/justin_quiros/python_stack/django_projects/login_reg/login_reg/wsgi.py new file mode 100644 index 0000000..cf7f5b6 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/login_reg/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for login_reg 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/1.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "login_reg.settings") + +application = get_wsgi_application() diff --git a/justin_quiros/python_stack/django_projects/login_reg/manage.py b/justin_quiros/python_stack/django_projects/login_reg/manage.py new file mode 100755 index 0000000..c6255bd --- /dev/null +++ b/justin_quiros/python_stack/django_projects/login_reg/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "login_reg.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + 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?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/__init__.py b/justin_quiros/python_stack/django_projects/reviewer/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/__init__.py b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/admin.py b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/apps.py b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/apps.py new file mode 100644 index 0000000..3332ce0 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class ReviewAppConfig(AppConfig): + name = 'review_app' diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/migrations/0001_initial.py b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/migrations/0001_initial.py new file mode 100644 index 0000000..000924a --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-18 16:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('alias', models.CharField(max_length=255)), + ('email', models.CharField(max_length=255)), + ('password', models.CharField(max_length=255)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/migrations/0002_author_book_review.py b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/migrations/0002_author_book_review.py new file mode 100644 index 0000000..ff13d3f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/migrations/0002_author_book_review.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-18 20:35 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('review_app', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Author', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='Book', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=255)), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='books', to='review_app.Author')), + ], + ), + migrations.CreateModel( + name='Review', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('review', models.TextField()), + ('rating', models.IntegerField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to='review_app.Book')), + ('reviewer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews_left', to='review_app.User')), + ], + ), + ] diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/migrations/__init__.py b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/models.py b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/models.py new file mode 100644 index 0000000..f2cbe23 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/models.py @@ -0,0 +1,146 @@ +from __future__ import unicode_literals + +from django.db import models +import bcrypt +import re +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') + +class UserManager(models.Manager): + + def register_validation(self, form_data): + errors = [] + + if len(form_data['name']) == 0: + errors.append( "Name is required.") + if len(form_data['alias']) == 0: + errors.append("Alias is required") + if len(form_data['email']) == 0 or not EMAIL_REGEX.match(form_data['email']): + errors.append("Email is invalid.") + if len(form_data['password']) < 8: + errors.append("Email must be atleast 8 characters.") + if form_data['password'] != form_data['conf_password']: + errors.append("Passwords did not match.") + + duplicate = User.objects.filter(email = form_data['email']) + if len(duplicate) == 1: + errors.append("This email is already registered.") + + return errors + + + + def register(self, form_data): + pw = str(form_data['password']) + hashed_pw = bcrypt.hashpw(pw, bcrypt.gensalt()) + + user = User.objects.create( + name = form_data['name'], + alias = form_data['alias'], + email = form_data['email'], + password = hashed_pw + ) + return user + + def login_validation(self, form_data): + errors = [] + user = User.objects.filter(email=form_data['email']).first() + print user + if user: + pw = str(form_data['password']) + user_password = str(user.password) + if not bcrypt.checkpw(pw.encode(), user_password.encode()): + errors.append("Invalid password.") + else: + errors.append("Invalid email.") + return errors + + + def login(self, form_data): + user = User.objects.filter(email=form_data['email']).first() + return user + + + + + + +class User(models.Model): + name = models.CharField(max_length=255) + alias = models.CharField(max_length=255) + email = models.CharField(max_length=255) + password = models.CharField(max_length=255) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + objects = UserManager() + + +class Author(models.Model): + name = models.CharField(max_length=255) + +class Book(models.Model): + title = models.CharField(max_length=255) + author = models.ForeignKey(Author, related_name="books") + + + + + + + +class ReviewManager(models.Manager): + def review_validation(self, form_data): + errors = [] + + if len(form_data['title']) < 1 or len(form_data['review']) < 1: + errors.append('Title/Review fields are required') + if not "author" in form_data and len(form_data['new_author']) < 3: + errors.append('Author names must be atleast 3 letters.') + + if "author" in form_data and len(form_data['new_author']) > 0 and len(form_data['new_author']) < 3: + errors.append('Author names must be atleast 3 letters.') + if not int(form_data['rating']) > 0 or not int(form_data['rating']) <= 5: + errors.append('invalid rating') + return errors + + def create_review(self, form_data, user_id): + + # retrive or create author + the_author = None + if len(form_data['new_author']) < 1: + the_author = Author.objects.get(id=int(form_data['author'])) + else: + the_author = Author.objects.create(name=form_data['new_author']) + + # retirive or create book + the_book = None + if not Book.objects.filter(title=form_data['title']): + the_book = Book.objects.create( + title=form_data['title'], author=the_author + ) + else: + the_book = Book.objects.get(title=form_data['title']) + + # returns a Review object + return self.create( + review = form_data['review'], + rating = form_data['rating'], + book = the_book, + reviewer = User.objects.get(id=user_id) + ) + + def recent_and_not(self): + + # returns a tuple with the zeroeth index containing query for 3 most recent reviews, and the first index + # containing the rest + + return (self.all().order_by('-created_at')[:3], self.all().order_by('-created_at')[3:]) + +class Review(models.Model): + review = models.TextField() + rating = models.IntegerField() + book = models.ForeignKey(Book, related_name="reviews") + reviewer = models.ForeignKey(User, related_name="reviews_left") + created_at = models.DateTimeField(auto_now_add=True) + objects = ReviewManager() + def __str__(self): + return "Book: {}".format(self.book.title) \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/static/review_app/css/style.css b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/static/review_app/css/style.css new file mode 100644 index 0000000..1fe37db --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/static/review_app/css/style.css @@ -0,0 +1,3 @@ +.side{ + overflow: scroll; +} \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/add.html b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/add.html new file mode 100644 index 0000000..d77c92d --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/add.html @@ -0,0 +1,47 @@ + + + + {% load static %} + + Add Book and Review + + + + +

Add a New Book and a Review

+
+ {% for error in errors %} + {{error}} + {% endfor %} +

Register

+
+ {% csrf_token %} + + +
+
+ + Choose from the list: + +
+ Or add a new author: + + + + + + +
+
+ + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/books.html b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/books.html new file mode 100644 index 0000000..9578582 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/books.html @@ -0,0 +1,37 @@ + + + + {% load static %} + + Books Home + + + + +

Welcome, {{request.session.name}}

+
+ Add Book and Review +
+ Logout + +
+

Recent Book Reviews:

+ {% for review in recent %} +
+

{{ review.book.title }}

+

Rating: {{ review.rating }}

+

{{ review.reviewer.name}} says: {{ review.review }}

+

Posted on: {{ review.created_at }}

+
+ {% endfor %} +
+

Other Books with Reviews:

+ {% for review in more %} + + {% endfor %} +
+
+ + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/index.html b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/index.html new file mode 100644 index 0000000..e475463 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/index.html @@ -0,0 +1,59 @@ + + + + {% load static %} + + Welcome + + + + +

Welcome!

+
+ {% for error in errors %} + {{error}} + {% endfor %} +

Register

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

*Password should be at least 8 characters

+
+ + +
+
+ +
+
+
+ + + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/review.html b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/review.html new file mode 100644 index 0000000..832d355 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/review.html @@ -0,0 +1,49 @@ + + + + {% load static %} + + Add Book and Review + + + + +
+

Home | Logout

+

{{book.title}}

+

{{book.author.name}}

+
+

Reviews:

+
+ {% for review in book.reviews.all %} +

Rating: {{review.rating}}

+

{{review.reviewer.name}} says: {{review.review}}

+

Posted on: {{review.created_at}}

+ {% if request.session.user_id == review.reviewer_id %} + Delete this Review + {% endif %} +
+ {% endfor %} + +
+
+ {% csrf_token %} +
+ + +
+
+ + +
+ +
+
+ + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/user.html b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/user.html new file mode 100644 index 0000000..b4f4fcf --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/templates/review_app/user.html @@ -0,0 +1,22 @@ + + + + {% load static %} + + User Reviews + + + + +

Home | Add book and review | Logout

+

User Alias: {{user.alias}}

+

Name: {{user.name}}

+

Email: {{user.email}}

+

Total Reviews: {{user.reviews_left.all.count}}

+
+

Posted Reviews on the Folowing Books

+ {% for book in unique_book_reviews %} +

{{book.title}}

+ {% endfor %} + + diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/tests.py b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/urls.py b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/urls.py new file mode 100644 index 0000000..5cd0bac --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/urls.py @@ -0,0 +1,17 @@ +from django.conf.urls import url +from . import views # This line is new! + +urlpatterns = [ + url(r'^$', views.index), + url(r'^login$', views.login), + url(r'^register$', views.register), + url(r'^books$', views.books), + url(r'^create', views.create), + url(r'books/(?P\d+)$', views.review), + url(r'^books/add$', views.add), + url(r'^books/(?P\d+)/add', views.add_review), + url(r'^user/(?P\d+)', views.user), + url(r'^delete/(?P\d+)', views.delete), + url(r'^logout$', views.logout), +] + diff --git a/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/views.py b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/views.py new file mode 100644 index 0000000..4a135f3 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/apps/review_app/views.py @@ -0,0 +1,110 @@ +from django.shortcuts import render, redirect +from django.contrib import messages +from .models import * +# Create your views here. +def index(request): + request.session['status'] = "" + if 'errors' not in request.session: + request.session['errors'] = [] + context = { + "errors": request.session['errors'] + } + return render(request, 'review_app/index.html', context) + +def register(request): + if request.method == "POST": + errors = User.objects.register_validation(request.POST) + if len(errors) != 0: + request.session['errors'] = errors + print errors + return redirect('/') + else: + user = User.objects.register(request.POST) + request.session['user_id'] = user.id + request.session['status'] = "registered." + request.session['name'] = user.name + return redirect('/books') + +def login(request): + errors = User.objects.login_validation(request.POST) + if len(errors) != 0: + request.session['errors'] = errors + return redirect('/') + else: + user = User.objects.login(request.POST) + request.session['name'] = user.name + request.session['user_id'] = user.id + request.session['status'] = "logged in." + return redirect('/books') + +def books(request): + context = { + 'recent': Review.objects.recent_and_not()[0], + 'more': Review.objects.recent_and_not()[1] + } + return render(request, 'review_app/books.html', context) + +def add(request): + context = { + "authors": Author.objects.all(), + "errors": request.session['errors'] + } + return render(request, 'review_app/add.html', context) + +def add_review(request, book_id): + book = Book.objects.get(id=book_id) + new_review = { + "title": book.title, + "author": book.author.id, + "rating": request.POST['rating'], + "review": request.POST['review'], + "new_author": '' + } + + errors = Review.objects.review_validation(new_review) + if errors: + for e in errors: + messages.error(request, e) + else: + Review.objects.create_review(new_review, request.session['user_id']) + return redirect('/books/{}'.format(book_id)) + +def create(request): + errors = Review.objects.review_validation(request.POST) + + if len(errors) != 0: + request.session['errors'] = errors + return redirect('/books/add') + else: + book_id = Review.objects.create_review(request.POST, request.session['user_id']).book.id + return redirect('/books/{}'.format(book_id)) + +def review(request, book_id): + context = { + "book": Book.objects.get(id=book_id) + } + return render(request, 'review_app/review.html', context) + +def user(request, user_id): + + user = User.objects.get(id=user_id) + unique_ids = user.reviews_left.all().values("book").distinct() + unique_books = [] + + for book in unique_ids: + unique_books.append(Book.objects.get(id=book['book'])) + + context = { + 'user': user, + 'unique_book_reviews': unique_books + } + return render(request, 'review_app/user.html', context) + +def delete(request, review_id): + book_id = Review.objects.get(id=review_id).book_id + Review.objects.get(id=review_id).delete() + return redirect('/books/{}'.format(book_id)) + +def logout(request): + request.session.clear() + return redirect('/') \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/reviewer/db.sqlite3 b/justin_quiros/python_stack/django_projects/reviewer/db.sqlite3 new file mode 100644 index 0000000..167a4c0 Binary files /dev/null and b/justin_quiros/python_stack/django_projects/reviewer/db.sqlite3 differ diff --git a/justin_quiros/python_stack/django_projects/reviewer/manage.py b/justin_quiros/python_stack/django_projects/reviewer/manage.py new file mode 100755 index 0000000..db4b49b --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "reviewer.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + 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?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/justin_quiros/python_stack/django_projects/reviewer/reviewer/__init__.py b/justin_quiros/python_stack/django_projects/reviewer/reviewer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/reviewer/reviewer/settings.py b/justin_quiros/python_stack/django_projects/reviewer/reviewer/settings.py new file mode 100644 index 0000000..190bffa --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/reviewer/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for reviewer project. + +Generated by 'django-admin startproject' using Django 1.11.6. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.11/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'b=0yiw6s_2f@f9cr7p7@6xi2+5(0!-6fqc=01+a6eser7ks)+d' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.review_app', + '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 = 'reviewer.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 = 'reviewer.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.11/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/1.11/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.11/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/justin_quiros/python_stack/django_projects/reviewer/reviewer/urls.py b/justin_quiros/python_stack/django_projects/reviewer/reviewer/urls.py new file mode 100644 index 0000000..7f72ffa --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/reviewer/urls.py @@ -0,0 +1,21 @@ +"""reviewer URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.11/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url, include +from django.contrib import admin + +urlpatterns = [ + url(r'^', include('apps.review_app.urls')), +] diff --git a/justin_quiros/python_stack/django_projects/reviewer/reviewer/wsgi.py b/justin_quiros/python_stack/django_projects/reviewer/reviewer/wsgi.py new file mode 100644 index 0000000..0c3b548 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/reviewer/reviewer/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for reviewer 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/1.11/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "reviewer.settings") + +application = get_wsgi_application() diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/__init__.py b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/__init__.py b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/admin.py b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/apps.py b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/apps.py new file mode 100644 index 0000000..a56dd04 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class RestAppConfig(AppConfig): + name = 'rest_app' diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/migrations/0001_initial.py b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/migrations/0001_initial.py new file mode 100644 index 0000000..58e2301 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/migrations/0001_initial.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-16 18:16 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email', models.EmailField(max_length=254, unique=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/migrations/__init__.py b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/models.py b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/models.py new file mode 100644 index 0000000..e0e9eee --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/models.py @@ -0,0 +1,12 @@ +from __future__ import unicode_literals + +from django.db import models + +class User(models.Model): + first_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) + email = models.EmailField(unique=True) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + def __unicode__(self): + return "id: " + str(self.id) + ", first_name: " + self.first_name + ", last_name " + self.last_name + ", email " + self.email \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/static/rest_app/css/style.css b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/static/rest_app/css/style.css new file mode 100644 index 0000000..2dd646d --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/static/rest_app/css/style.css @@ -0,0 +1,9 @@ +*{ + margin: 0px; + padding: 0px; +} + +.box{ + height: 500px; + width: 500px; +} \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/edit.html b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/edit.html new file mode 100644 index 0000000..ec839ce --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/edit.html @@ -0,0 +1,28 @@ + + + + {% load static %} + + Users Index + + + + +

Edit User {{id}}

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

Show | Go Back

+ + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/index.html b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/index.html new file mode 100644 index 0000000..4aadc8e --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/index.html @@ -0,0 +1,43 @@ + + + + {% load static %} + + Users Index + + + +

Users

+
+ + + + + + + + + + + + {% for user in users %} + + + + + + + + {% endfor %} + +
idFull NameEmailCreated AtActions
{{user.id}}{{user.first_name}} {{user.last_name}}{{user.email}}{{user.created_at}} + Show + Edit + Delete +
+
+
+ Add a new user + + + diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/new.html b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/new.html new file mode 100644 index 0000000..fd19ca4 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/new.html @@ -0,0 +1,29 @@ + + + + {% load static %} + + Users Index + + + + +

Add a new user

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

Go Back

+ + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/user.html b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/user.html new file mode 100644 index 0000000..4df6280 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/templates/rest_app/user.html @@ -0,0 +1,18 @@ + + + + {% load static %} + + Users Index + + + + +

User {{user.id}}

+

Full Name: {{user.first_name}} {{user.last_name}}

+

Email: {{user.email}}

+

Created at: {{user.created_at}}

+
+

Edit | Delete

+ + diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/tests.py b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/urls.py b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/urls.py new file mode 100644 index 0000000..53f3735 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/urls.py @@ -0,0 +1,13 @@ +from django.conf.urls import url +from . import views # This line is new! + +urlpatterns = [ + url(r'^$', views.index), + url(r'users$', views.index), + url(r'users/(?P\d+)$', views.show), + url(r'users/new', views.new), + url(r'create', views.create), + url(r'update/(?P\d+)', views.update), + url(r'users/(?P\d+)/edit', views.edit), + url(r'users/(?P\d+)/destroy', views.destroy) +] \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/views.py b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/views.py new file mode 100644 index 0000000..7c2a447 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/apps/rest_app/views.py @@ -0,0 +1,54 @@ +from django.shortcuts import render, redirect + +# Create your views here. +from django.shortcuts import render, redirect +from .models import User +from time import localtime, strftime + +# Create your views here. +def index(request): + context = { + "users": User.objects.all() + } + return render(request, 'rest_app/index.html', context) + +def show(request, user_id): + context = { + "user": (User.objects.get(id=user_id)) + } + + return render(request, 'rest_app/user.html', context) + +def new(request): + return render(request, 'rest_app/new.html') + +def edit(request, user_id): + context = { + "id": (User.objects.get(id=user_id).id), + "first_name": (User.objects.get(id=user_id).first_name), + "last_name": (User.objects.get(id=user_id).last_name), + "email": (User.objects.get(id=user_id).email) + } + return render(request, 'rest_app/edit.html', context) + +def create(request): + User.objects.create(first_name=request.POST['first_name'], last_name=request.POST['last_name'], email=request.POST['email']) + return redirect('/') + +def destroy(request, user_id): + User.objects.get(id=user_id).delete() + return redirect('/') + +def update(request, user_id): + + x = User.objects.get(id=user_id) + x.first_name = request.POST['first_name'] + x.last_name = request.POST['last_name'] + x.email = request.POST['email'] + x.save() + + return redirect('/') + + + + diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/db.sqlite3 b/justin_quiros/python_stack/django_projects/semi_rest/main/db.sqlite3 new file mode 100644 index 0000000..0156743 Binary files /dev/null and b/justin_quiros/python_stack/django_projects/semi_rest/main/db.sqlite3 differ diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/main/__init__.py b/justin_quiros/python_stack/django_projects/semi_rest/main/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/main/settings.py b/justin_quiros/python_stack/django_projects/semi_rest/main/main/settings.py new file mode 100644 index 0000000..8f240dd --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/main/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for main project. + +Generated by 'django-admin startproject' using Django 1.10. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '+su$+$)6d_whsvxlr!xjwi7z3c#niqetupwsjffyks+ftli$*5' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.rest_app', + '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 = 'main.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 = 'main.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/main/urls.py b/justin_quiros/python_stack/django_projects/semi_rest/main/main/urls.py new file mode 100644 index 0000000..2b90edf --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/main/urls.py @@ -0,0 +1,21 @@ +"""main URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.10/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url, include +from django.contrib import admin + +urlpatterns = [ + url(r'^', include('apps.rest_app.urls')), +] diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/main/wsgi.py b/justin_quiros/python_stack/django_projects/semi_rest/main/main/wsgi.py new file mode 100644 index 0000000..4d1e3f4 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/main/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for main 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/1.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") + +application = get_wsgi_application() diff --git a/justin_quiros/python_stack/django_projects/semi_rest/main/manage.py b/justin_quiros/python_stack/django_projects/semi_rest/main/manage.py new file mode 100755 index 0000000..ad5d3e7 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/semi_rest/main/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + 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?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/static/word_app/css/style.css b/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/static/word_app/css/style.css index f7e729b..d8efc48 100644 --- a/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/static/word_app/css/style.css +++ b/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/static/word_app/css/style.css @@ -45,4 +45,5 @@ button{ .big{ font-size: 30px; -} \ No newline at end of file +} + \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/templates/word_app/index.html b/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/templates/word_app/index.html index 8ac28d4..43c3010 100644 --- a/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/templates/word_app/index.html +++ b/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/templates/word_app/index.html @@ -36,7 +36,7 @@ {% csrf_token %} - {% for i in request.session.word %} + {% for i in request.session.word %}

{{i.word}} {{i.display}}

{% endfor %} diff --git a/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/views.py b/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/views.py index befca28..f3ce375 100644 --- a/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/views.py +++ b/justin_quiros/python_stack/django_projects/session_words/main/apps/word_app/views.py @@ -28,7 +28,6 @@ def process(request): return redirect('/display') - def display(request): return redirect('/') diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/__init__.py b/justin_quiros/python_stack/django_projects/users/main/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/__init__.py b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/admin.py b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/apps.py b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/apps.py new file mode 100644 index 0000000..660e43e --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class UserAppConfig(AppConfig): + name = 'user_app' diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/migrations/0001_initial.py b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/migrations/0001_initial.py new file mode 100644 index 0000000..222f3a6 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-11-15 19:12 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=255)), + ('last_name', models.CharField(max_length=255)), + ('email_address', models.CharField(max_length=255)), + ('age', models.IntegerField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now_add=True)), + ], + ), + ] diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/migrations/__init__.py b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/models.py b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/models.py new file mode 100644 index 0000000..20fbefd --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/models.py @@ -0,0 +1,15 @@ +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. +class User(models.Model): + first_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) + email_address = models.CharField(max_length=255) + age = models.IntegerField() + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now_add = True) + + def __unicode__(self): + return "id: " + str(self.id) + ", first_name: " + self.first_name + ", last_name: " + self.last_name \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/static/user_app/css/style.css b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/static/user_app/css/style.css new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/templates/user_app/index.html b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/templates/user_app/index.html new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/tests.py b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/urls.py b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/urls.py new file mode 100644 index 0000000..42b9825 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url +from . import views # This line is new! + +urlpatterns = [ + url(r'^$', views.index), +] \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/users/main/apps/user_app/views.py b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/views.py new file mode 100644 index 0000000..b46365b --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/apps/user_app/views.py @@ -0,0 +1,6 @@ +from django.shortcuts import render, redirect + +# Create your views here. +def index(request): + + return render(request, 'user_app/index.html') \ No newline at end of file diff --git a/justin_quiros/python_stack/django_projects/users/main/db.sqlite3 b/justin_quiros/python_stack/django_projects/users/main/db.sqlite3 new file mode 100644 index 0000000..ce4b4c2 Binary files /dev/null and b/justin_quiros/python_stack/django_projects/users/main/db.sqlite3 differ diff --git a/justin_quiros/python_stack/django_projects/users/main/main/__init__.py b/justin_quiros/python_stack/django_projects/users/main/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/justin_quiros/python_stack/django_projects/users/main/main/settings.py b/justin_quiros/python_stack/django_projects/users/main/main/settings.py new file mode 100644 index 0000000..67af856 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/main/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for main project. + +Generated by 'django-admin startproject' using Django 1.10. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'gdk30mdbjc%-*5sj!@nn1o7e8#u8te4*lspv5534)gn7%!%sao' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.user_app', + '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 = 'main.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 = 'main.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/justin_quiros/python_stack/django_projects/users/main/main/urls.py b/justin_quiros/python_stack/django_projects/users/main/main/urls.py new file mode 100644 index 0000000..27fc861 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/main/urls.py @@ -0,0 +1,21 @@ +"""main URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.10/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url, include +from django.contrib import admin + +urlpatterns = [ + url(r'^', include('apps.user_app.urls')), +] diff --git a/justin_quiros/python_stack/django_projects/users/main/main/wsgi.py b/justin_quiros/python_stack/django_projects/users/main/main/wsgi.py new file mode 100644 index 0000000..4d1e3f4 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/main/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for main 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/1.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") + +application = get_wsgi_application() diff --git a/justin_quiros/python_stack/django_projects/users/main/manage.py b/justin_quiros/python_stack/django_projects/users/main/manage.py new file mode 100755 index 0000000..ad5d3e7 --- /dev/null +++ b/justin_quiros/python_stack/django_projects/users/main/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + 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?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/justin_quiros/python_stack/django_projects/word_generator/main/apps/word_gen/views.py b/justin_quiros/python_stack/django_projects/word_generator/main/apps/word_gen/views.py index 04f9771..1953a2e 100644 --- a/justin_quiros/python_stack/django_projects/word_generator/main/apps/word_gen/views.py +++ b/justin_quiros/python_stack/django_projects/word_generator/main/apps/word_gen/views.py @@ -4,7 +4,7 @@ def index(request): - if request.session['attempt'] == None: + if request.session.get('attempt') == None: request.session['attempt'] = 1 else: request.session['attempt'] += 1 diff --git a/justin_quiros/python_stack/django_projects/word_generator/main/db.sqlite3 b/justin_quiros/python_stack/django_projects/word_generator/main/db.sqlite3 index 2bcd036..5072853 100644 Binary files a/justin_quiros/python_stack/django_projects/word_generator/main/db.sqlite3 and b/justin_quiros/python_stack/django_projects/word_generator/main/db.sqlite3 differ