Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
### Python Files ###
*.pyc

### Environments ###
djangoenv
djangoEnv
DjangoEnv
flaskenv
flaskEnv
FlaskEnv
venv
denv
env

### Workspace Files ###
*.idea
*.vscode
*.sublime-workspace

### System Files ###
.DS_Store
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
Desktop.ini
$RECYCLE.BIN/
$RECYCLE.BIN/

### Compressed Files ###
*.zip
*.7z
*.rar
*.gzip
*.gz
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions jessica_hart/Django/session_words/apps/main_app/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
7 changes: 7 additions & 0 deletions jessica_hart/Django/session_words/apps/main_app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import unicode_literals

from django.apps import AppConfig


class MainAppConfig(AppConfig):
name = 'main_app'
Empty file.
5 changes: 5 additions & 0 deletions jessica_hart/Django/session_words/apps/main_app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import unicode_literals

from django.db import models

# Create your models here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Class for big fonts */
.big_font {
font-size: 25px;
}

/* Classes that match the color radio button values */
.red {
color: red;
}

.green {
color: green;
}

.blue {
color: blue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Session Words</title>
<!-- Required tag to load in static files -->
{% load static %}
<!-- Stylesheet required for applying classes, note the static path -->
<link rel="stylesheet" href="{% static 'main_app/style.css' %}">
</head>
<body>
<h1>Add a new word</h1>
<!-- Form must go to route with the method that adds words -->
<form action="/session_words/add_word" method="POST">
<!-- Token required for all Django forms -->
{% csrf_token %}
<input type="text" name="word">
<label>Choose color</label>
<!-- Note the name AND value on radio buttons -->
<input type="radio" name="color" value="red"> <label>Red</label>
<input type="radio" name="color" value="green"> <label>Green</label>
<input type="radio" name="color" value="blue"> <label>Blue</label>
<input type="checkbox" name="big_font"> show in BIG fonts!
<button type="submit">Add to Session</button>
</form>
<a href="/session_words/clear">Clear Session</a>
<ul>
<!-- Loop through words in request.session['words'] list -->
{% for word in request.session.words %}
<!-- Insert color and size values as classes and display the word -->
<li>
<span class="{{ word.color }} {{ word.size }}">{{ word.word }}</span> - added on {{ word.created_at }}
</li>
{% endfor %}
</ul>
</body>
</html>
3 changes: 3 additions & 0 deletions jessica_hart/Django/session_words/apps/main_app/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions jessica_hart/Django/session_words/apps/main_app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index),
url(r'^add_word$', views.add_word),
url(r'^clear$', views.clear)
]
46 changes: 46 additions & 0 deletions jessica_hart/Django/session_words/apps/main_app/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from django.shortcuts import render, HttpResponse, redirect
# Import required to use datetime
from datetime import datetime

def index(request):
# If no word list is in session, create empty array to append them into
if 'words' not in request.session:
request.session['words'] = []

return render(request, "main_app/index.html")

def add_word(request):
# Set size to empty unless checkbox was selected
size = ''
if 'big_font' in request.POST:
size = 'big_font'

# Set color to empty unless a radio button was selected
color = ''
if 'color' in request.POST:
color = request.POST['color']

# Gets the current time and formats it into a string
# See http://strftime.org/ or https://www.foragoodstrftime.com/ for more info
# Note the datetime import at top
date = datetime.now().strftime("%I:%M:%S%p, %B %e, %Y")

# Collect data on word and enter into dictionary
word = {
'word': request.POST['word'],
'color': color,
'size': size,
'created_at': date
}

# Can't append word into request.session directly
temp = request.session['words']
temp.append(word)
request.session['words'] = temp

return redirect(index)

def clear(request):
# Clear the session of the entire word list
del request.session['words']
return redirect(index)
Binary file added jessica_hart/Django/session_words/db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions jessica_hart/Django/session_words/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "session_words.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)
Empty file.
121 changes: 121 additions & 0 deletions jessica_hart/Django/session_words/session_words/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"""
Django settings for session_words 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 = 'hoa@46(y9xwwimts(lc(o#+31m-^$kwn#@yzkqj(=u@e5pk=%n'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'apps.main_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 = 'session_words.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 = 'session_words.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/'
7 changes: 7 additions & 0 deletions jessica_hart/Django/session_words/session_words/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
# Common name in routes can be entered here
# All routes in main_app will now start with "session_words/" (completely optional)
url(r'^session_words/', include('apps.main_app.urls'))
]
16 changes: 16 additions & 0 deletions jessica_hart/Django/session_words/session_words/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for session_words 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", "session_words.settings")

application = get_wsgi_application()