diff --git a/richardN/PYoop/animals/animals.py b/richardN/PYoop/animals/animals.py new file mode 100644 index 0000000..8cded5b --- /dev/null +++ b/richardN/PYoop/animals/animals.py @@ -0,0 +1,47 @@ +class Animal(object): + def __init__(self, name): + self.health = 100 + self.name = name + + def walk(self): + self.health -= 1 + return self + + def run(self): + self.health -= 5 + return self + + def displayHealth(self): + print 'My name is: ' + self.name + print 'I have: ' + str(self.health) + ' health' + +animal = Animal('meow') +animal.walk().walk().walk().run().run().displayHealth() + +class Dog(Animal): + def __init__(self,name): + super(Dog, self).__init__(name) + self.health = 150 + + def pet(self): + self.health += 5 + return self + +dog = Dog('stella') +dog.walk().walk().walk().run().run().pet().displayHealth() + +class Dragon(Animal): + def __init__(self, name): + super(Dragon, self).__init__(name) + self.health = 170 + + def fly(self): + self.health -= 10 + return self + + def displayHealth(self): + print "a dragon" + super(Dragon, self).displayHealth() + +dragon = Dragon('toothless') +dragon.fly().displayHealth() diff --git a/richardN/PYoop/math/dojoMath.py b/richardN/PYoop/math/dojoMath.py new file mode 100644 index 0000000..7336362 --- /dev/null +++ b/richardN/PYoop/math/dojoMath.py @@ -0,0 +1,20 @@ +class math(object): + def __init__(self): + self.result=0 + def add(self, *nums): + for num in nums: + if type(num) == list or type(num) == tuple: + for k in num: + self.result += k + else: + self.result += num + return self + def subtract(self, *nums): + for num in nums: + if type(num) == list or type(num) == tuple: + for k in num: + self.result -= k + else: + self.result -= num + return self + print math().add([1],3,7).add([5, 8, 7, 2], [2, 4.3, 1.25]).subtract(2, [2,3], [1.1, 2.3]).result diff --git a/richardN/django/blogs_app_ass/apps/__init__.py b/richardN/django/blogs_app_ass/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/blogs_app_ass/apps/blogs_app/__init__.py b/richardN/django/blogs_app_ass/apps/blogs_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/blogs_app_ass/apps/blogs_app/admin.py b/richardN/django/blogs_app_ass/apps/blogs_app/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/richardN/django/blogs_app_ass/apps/blogs_app/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/richardN/django/blogs_app_ass/apps/blogs_app/apps.py b/richardN/django/blogs_app_ass/apps/blogs_app/apps.py new file mode 100644 index 0000000..779e01b --- /dev/null +++ b/richardN/django/blogs_app_ass/apps/blogs_app/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class BlogsAppConfig(AppConfig): + name = 'blogs_app' diff --git a/richardN/django/blogs_app_ass/apps/blogs_app/migrations/__init__.py b/richardN/django/blogs_app_ass/apps/blogs_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/blogs_app_ass/apps/blogs_app/models.py b/richardN/django/blogs_app_ass/apps/blogs_app/models.py new file mode 100644 index 0000000..1dfab76 --- /dev/null +++ b/richardN/django/blogs_app_ass/apps/blogs_app/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/richardN/django/blogs_app_ass/apps/blogs_app/templates/blogs_app/index.html b/richardN/django/blogs_app_ass/apps/blogs_app/templates/blogs_app/index.html new file mode 100644 index 0000000..f663bf2 --- /dev/null +++ b/richardN/django/blogs_app_ass/apps/blogs_app/templates/blogs_app/index.html @@ -0,0 +1,10 @@ +

placeholder to later display all the list of blogs

+ + + \ No newline at end of file diff --git a/richardN/django/blogs_app_ass/apps/blogs_app/tests.py b/richardN/django/blogs_app_ass/apps/blogs_app/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/richardN/django/blogs_app_ass/apps/blogs_app/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/richardN/django/blogs_app_ass/apps/blogs_app/urls.py b/richardN/django/blogs_app_ass/apps/blogs_app/urls.py new file mode 100644 index 0000000..1106c40 --- /dev/null +++ b/richardN/django/blogs_app_ass/apps/blogs_app/urls.py @@ -0,0 +1,11 @@ +from django.conf.urls import url +from . import views + +urlpatterns = [ + url(r'^$', views.index), + url(r'^new$', views.new), + url(r'^create$', views.create), + url(r'^(?P\d+)$', views.show), + url(r'^(?P\d+)/edit$', views.edit), + url(r'^(?P\d+)/delete$', views.destroy) +] \ No newline at end of file diff --git a/richardN/django/blogs_app_ass/apps/blogs_app/views.py b/richardN/django/blogs_app_ass/apps/blogs_app/views.py new file mode 100644 index 0000000..5b9622a --- /dev/null +++ b/richardN/django/blogs_app_ass/apps/blogs_app/views.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render, HttpResponse, redirect +# Create your views here. +def environment(**options): + env = Environment(**options) + env.globals.update({ + 'static': staticfiles_storage.url, + 'url': reverse, + }) + return env + +def index(request): + response = "placeholder to later display all the list of blogs" + return HttpResponse(response) + +def new(request): + response = "placeholder to display a new form to create a new blog" + return HttpResponse(response) + +def create(request): + # if request.method == "POST": + # print "*"*50 + # print request.POST + # print request.POST['name'] + # print request.POST['desc'] + # request.session['name'] = request.POST['name'] + # request.session['counter'] = 100 + # print "*"*50 + return redirect("/") + +def show(request, num): + response = "placeholder to display blog {}".format(num) + return HttpResponse(response) + +def edit(request, num): + response = "placeholder to edit blog {}".format(num) + return HttpResponse(response) + +def destroy(request, num): + return redirect('/') \ No newline at end of file diff --git a/richardN/django/blogs_app_ass/blogs_app_ass/__init__.py b/richardN/django/blogs_app_ass/blogs_app_ass/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/blogs_app_ass/blogs_app_ass/settings.py b/richardN/django/blogs_app_ass/blogs_app_ass/settings.py new file mode 100644 index 0000000..b1a4c20 --- /dev/null +++ b/richardN/django/blogs_app_ass/blogs_app_ass/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for blogs_app_ass project. + +Generated by 'django-admin startproject' using Django 1.11.7. + +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 = 'agist&j8g7kwf(@jlm*s^ia)b%l3z(z7^#iv(_+#!y&!fjb%($' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.blogs_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 = 'blogs_app_ass.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 = 'blogs_app_ass.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/richardN/django/blogs_app_ass/blogs_app_ass/urls.py b/richardN/django/blogs_app_ass/blogs_app_ass/urls.py new file mode 100644 index 0000000..e2242b8 --- /dev/null +++ b/richardN/django/blogs_app_ass/blogs_app_ass/urls.py @@ -0,0 +1,21 @@ +"""blogs_app_ass 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.blogs_app.urls')), +] diff --git a/richardN/django/blogs_app_ass/blogs_app_ass/wsgi.py b/richardN/django/blogs_app_ass/blogs_app_ass/wsgi.py new file mode 100644 index 0000000..93f319a --- /dev/null +++ b/richardN/django/blogs_app_ass/blogs_app_ass/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for blogs_app_ass 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", "blogs_app_ass.settings") + +application = get_wsgi_application() diff --git a/richardN/django/blogs_app_ass/db.sqlite3 b/richardN/django/blogs_app_ass/db.sqlite3 new file mode 100644 index 0000000..e3d7819 Binary files /dev/null and b/richardN/django/blogs_app_ass/db.sqlite3 differ diff --git a/richardN/django/blogs_app_ass/manage.py b/richardN/django/blogs_app_ass/manage.py new file mode 100644 index 0000000..c6b854d --- /dev/null +++ b/richardN/django/blogs_app_ass/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blogs_app_ass.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/richardN/django/courses/apps/__init__.py b/richardN/django/courses/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/courses/apps/courses_app/__init__.py b/richardN/django/courses/apps/courses_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/courses/apps/courses_app/admin.py b/richardN/django/courses/apps/courses_app/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/richardN/django/courses/apps/courses_app/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/richardN/django/courses/apps/courses_app/apps.py b/richardN/django/courses/apps/courses_app/apps.py new file mode 100644 index 0000000..610c60e --- /dev/null +++ b/richardN/django/courses/apps/courses_app/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class CourcesAppConfig(AppConfig): + name = 'cources_app' diff --git a/richardN/django/courses/apps/courses_app/migrations/__init__.py b/richardN/django/courses/apps/courses_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/courses/apps/courses_app/models.py b/richardN/django/courses/apps/courses_app/models.py new file mode 100644 index 0000000..1dfab76 --- /dev/null +++ b/richardN/django/courses/apps/courses_app/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/richardN/django/courses/apps/courses_app/templates/courses_app/index.html b/richardN/django/courses/apps/courses_app/templates/courses_app/index.html new file mode 100644 index 0000000..56c28e2 --- /dev/null +++ b/richardN/django/courses/apps/courses_app/templates/courses_app/index.html @@ -0,0 +1,32 @@ + + + + + Surveys + + +
+ {% csrf_token %} +

Your Name:

+ +

Dojo Location:

+ +

Favorite Language:

+ +
+
+ +
+ + diff --git a/richardN/django/courses/apps/courses_app/templates/courses_app/results.html b/richardN/django/courses/apps/courses_app/templates/courses_app/results.html new file mode 100644 index 0000000..fd7f0d4 --- /dev/null +++ b/richardN/django/courses/apps/courses_app/templates/courses_app/results.html @@ -0,0 +1,13 @@ + + + + + Result + + +

Submitted Information

+

Name: {{request.session.name}}

+

Location: {{request.session.location}}

+

Language: {{request.session.language}}

+ + \ No newline at end of file diff --git a/richardN/django/courses/apps/courses_app/tests.py b/richardN/django/courses/apps/courses_app/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/richardN/django/courses/apps/courses_app/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/richardN/django/courses/apps/courses_app/urls.py b/richardN/django/courses/apps/courses_app/urls.py new file mode 100644 index 0000000..d4d7047 --- /dev/null +++ b/richardN/django/courses/apps/courses_app/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url +from . import views +urlpatterns = [ + url(r'^$', views.index), + url(r'^courses/process$', views.process), + url(r'^results', views.result), +] \ No newline at end of file diff --git a/richardN/django/courses/apps/courses_app/views.py b/richardN/django/courses/apps/courses_app/views.py new file mode 100644 index 0000000..3728ce7 --- /dev/null +++ b/richardN/django/courses/apps/courses_app/views.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render, redirect + +# Create your views here. +def index(request): + return render(request, 'courses_app/index.html') + +def process(request): + if request.method == 'POST': + form_data = request.POST + request.session['name'] = form_data['name'] + request.session['location'] = form_data['location'] + request.session['language'] = form_data['language'] + + return redirect('/results') + +def result(request): + return render(request, 'courses_app/results.html') \ No newline at end of file diff --git a/richardN/django/courses/courses/__init__.py b/richardN/django/courses/courses/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/courses/courses/settings.py b/richardN/django/courses/courses/settings.py new file mode 100644 index 0000000..f26ccb6 --- /dev/null +++ b/richardN/django/courses/courses/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for courses project. + +Generated by 'django-admin startproject' using Django 1.11.7. + +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 = '(q*6puo-_9*5#2k4@&&4&#*3q&yjm8m0uk9%dem)c$4=x$jkiv' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.courses_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 = '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.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/richardN/django/courses/courses/urls.py b/richardN/django/courses/courses/urls.py new file mode 100644 index 0000000..ec1e0c5 --- /dev/null +++ b/richardN/django/courses/courses/urls.py @@ -0,0 +1,22 @@ +"""courses 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.courses_app.urls')), + url(r'^admin/', admin.site.urls), +] diff --git a/richardN/django/courses/courses/wsgi.py b/richardN/django/courses/courses/wsgi.py new file mode 100644 index 0000000..d29b7c7 --- /dev/null +++ b/richardN/django/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.11/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/richardN/django/courses/db.sqlite3 b/richardN/django/courses/db.sqlite3 new file mode 100644 index 0000000..561349d Binary files /dev/null and b/richardN/django/courses/db.sqlite3 differ diff --git a/richardN/django/courses/manage.py b/richardN/django/courses/manage.py new file mode 100644 index 0000000..7594c9c --- /dev/null +++ b/richardN/django/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/richardN/django/main/apps/__init__.py b/richardN/django/main/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/main/apps/blogs_app/__init__.py b/richardN/django/main/apps/blogs_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/main/apps/blogs_app/admin.py b/richardN/django/main/apps/blogs_app/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/richardN/django/main/apps/blogs_app/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/richardN/django/main/apps/blogs_app/apps.py b/richardN/django/main/apps/blogs_app/apps.py new file mode 100644 index 0000000..779e01b --- /dev/null +++ b/richardN/django/main/apps/blogs_app/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class BlogsAppConfig(AppConfig): + name = 'blogs_app' diff --git a/richardN/django/main/apps/blogs_app/migrations/__init__.py b/richardN/django/main/apps/blogs_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/main/apps/blogs_app/models.py b/richardN/django/main/apps/blogs_app/models.py new file mode 100644 index 0000000..f937be2 --- /dev/null +++ b/richardN/django/main/apps/blogs_app/models.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import HttpResponse, redirect + +def index(request): + return HttpResponse("placeholder to later display all the list of blogs") + +def new(request): + return HttpResponse("placeholder to display a new form to create a new blog") + +def create(request): + return redirect('/') + +def show(request, blog_id): + print blog_id + return HttpResponse("placeholder to display blog {}".format(blog_id)) + +def edit(request, blog_id): + return HttpResponse("placeholder to edit blog {}".format(blog_id)) + +def delete(request, blog_id): + return redirect('/') \ No newline at end of file diff --git a/richardN/django/main/apps/blogs_app/tests.py b/richardN/django/main/apps/blogs_app/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/richardN/django/main/apps/blogs_app/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/richardN/django/main/apps/blogs_app/urls.py b/richardN/django/main/apps/blogs_app/urls.py new file mode 100644 index 0000000..ec613f9 --- /dev/null +++ b/richardN/django/main/apps/blogs_app/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls import url +from . import views +urlpatterns = [ + url(r'^$',views.index) +] diff --git a/richardN/django/main/apps/blogs_app/views.py b/richardN/django/main/apps/blogs_app/views.py new file mode 100644 index 0000000..0b5c746 --- /dev/null +++ b/richardN/django/main/apps/blogs_app/views.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render + +# Create your views here. +from django.shortcuts import render, HttpResponse, redirect + +def index(request): + response = "FML GET TO WORK OR FAIL" + return HttpResponse(response) diff --git a/richardN/django/main/apps/first_app/__init__.py b/richardN/django/main/apps/first_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/main/apps/first_app/admin.py b/richardN/django/main/apps/first_app/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/richardN/django/main/apps/first_app/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/richardN/django/main/apps/first_app/apps.py b/richardN/django/main/apps/first_app/apps.py new file mode 100644 index 0000000..70b2f8d --- /dev/null +++ b/richardN/django/main/apps/first_app/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class FirstAppConfig(AppConfig): + name = 'first_app' diff --git a/richardN/django/main/apps/first_app/migrations/__init__.py b/richardN/django/main/apps/first_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/main/apps/first_app/models.py b/richardN/django/main/apps/first_app/models.py new file mode 100644 index 0000000..1dfab76 --- /dev/null +++ b/richardN/django/main/apps/first_app/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/richardN/django/main/apps/first_app/tests.py b/richardN/django/main/apps/first_app/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/richardN/django/main/apps/first_app/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/richardN/django/main/apps/first_app/urls.py b/richardN/django/main/apps/first_app/urls.py new file mode 100644 index 0000000..ec613f9 --- /dev/null +++ b/richardN/django/main/apps/first_app/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls import url +from . import views +urlpatterns = [ + url(r'^$',views.index) +] diff --git a/richardN/django/main/apps/first_app/views.py b/richardN/django/main/apps/first_app/views.py new file mode 100644 index 0000000..adffb9e --- /dev/null +++ b/richardN/django/main/apps/first_app/views.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render + +# Create your views here. +from django.shortcuts import render, HttpResponse, redirect + +def index(request): + response = "Oh where oh where can my baby be?" + return HttpResponse(response) diff --git a/richardN/django/main/db.sqlite3 b/richardN/django/main/db.sqlite3 new file mode 100644 index 0000000..e3d7819 Binary files /dev/null and b/richardN/django/main/db.sqlite3 differ diff --git a/richardN/django/main/main/__init__.py b/richardN/django/main/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/main/main/settings.py b/richardN/django/main/main/settings.py new file mode 100644 index 0000000..7ecf185 --- /dev/null +++ b/richardN/django/main/main/settings.py @@ -0,0 +1,122 @@ +""" +Django settings for main project. + +Generated by 'django-admin startproject' using Django 1.11.7. + +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 = 'f6whr6cb9=!xh-j)28b=eb$idrb5x^kw4p@i2#58+$aj4w096q' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.blogs_app', + 'apps.first_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.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/richardN/django/main/main/urls.py b/richardN/django/main/main/urls.py new file mode 100644 index 0000000..789b033 --- /dev/null +++ b/richardN/django/main/main/urls.py @@ -0,0 +1,23 @@ +"""main 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.blogs_app.urls')), + url(r'^',include('apps.first_app.urls')), + url(r'^admin/', admin.site.urls), +] diff --git a/richardN/django/main/main/wsgi.py b/richardN/django/main/main/wsgi.py new file mode 100644 index 0000000..424f219 --- /dev/null +++ b/richardN/django/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.11/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/richardN/django/main/manage.py b/richardN/django/main/manage.py new file mode 100644 index 0000000..ad5d3e7 --- /dev/null +++ b/richardN/django/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/richardN/django/main/templates/page1.html b/richardN/django/main/templates/page1.html new file mode 100644 index 0000000..35c4ff1 --- /dev/null +++ b/richardN/django/main/templates/page1.html @@ -0,0 +1,17 @@ + + + + + page1 + + +

home

+
+ Name: + Location: + FavLang: + Comment: + + Continue + + diff --git a/richardN/django/main/templates/page2.html b/richardN/django/main/templates/page2.html new file mode 100644 index 0000000..ff07ca3 --- /dev/null +++ b/richardN/django/main/templates/page2.html @@ -0,0 +1,19 @@ + + + + + home + + +

page 2

+ + "Home" + + {{form.Name}} + {{form.Location}} + {{form.FavLang}} + {{form.Comment}} + +
+ + diff --git a/richardN/django/randomWg/apps/__init__.py b/richardN/django/randomWg/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/randomWg/apps/randomWg_app/__init__.py b/richardN/django/randomWg/apps/randomWg_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/randomWg/apps/randomWg_app/admin.py b/richardN/django/randomWg/apps/randomWg_app/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/richardN/django/randomWg/apps/randomWg_app/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/richardN/django/randomWg/apps/randomWg_app/apps.py b/richardN/django/randomWg/apps/randomWg_app/apps.py new file mode 100644 index 0000000..a8ba34f --- /dev/null +++ b/richardN/django/randomWg/apps/randomWg_app/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class RandomwgAppConfig(AppConfig): + name = 'randomWg_app' diff --git a/richardN/django/randomWg/apps/randomWg_app/migrations/__init__.py b/richardN/django/randomWg/apps/randomWg_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/randomWg/apps/randomWg_app/models.py b/richardN/django/randomWg/apps/randomWg_app/models.py new file mode 100644 index 0000000..1dfab76 --- /dev/null +++ b/richardN/django/randomWg/apps/randomWg_app/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/richardN/django/randomWg/apps/randomWg_app/templates/randomWg_app/index.html b/richardN/django/randomWg/apps/randomWg_app/templates/randomWg_app/index.html new file mode 100644 index 0000000..5aa3628 --- /dev/null +++ b/richardN/django/randomWg/apps/randomWg_app/templates/randomWg_app/index.html @@ -0,0 +1,21 @@ + + + + + + + Display Time + + +

Random attempt #{{request.session.count}}

+

{{random}}

+
+ {% csrf_token %} + +
+
+ {% csrf_token %} + +
+ + \ No newline at end of file diff --git a/richardN/django/randomWg/apps/randomWg_app/tests.py b/richardN/django/randomWg/apps/randomWg_app/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/richardN/django/randomWg/apps/randomWg_app/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/richardN/django/randomWg/apps/randomWg_app/urls.py b/richardN/django/randomWg/apps/randomWg_app/urls.py new file mode 100644 index 0000000..a987c12 --- /dev/null +++ b/richardN/django/randomWg/apps/randomWg_app/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url +from . import views + +urlpatterns = [ + url(r'^$', views.index), + url(r'reset$', views.reset), +] \ No newline at end of file diff --git a/richardN/django/randomWg/apps/randomWg_app/views.py b/richardN/django/randomWg/apps/randomWg_app/views.py new file mode 100644 index 0000000..a85bacb --- /dev/null +++ b/richardN/django/randomWg/apps/randomWg_app/views.py @@ -0,0 +1,17 @@ +from django.shortcuts import render, HttpResponse, redirect +from django.utils.crypto import get_random_string + +def index(request): + if 'count' not in request.session: + request.session['count'] = 0 + else: + request.session['count'] += 1 + + content = { + 'random': get_random_string(length=14) + } + return render(request, 'randomWg_app/index.html', content) + +def reset(request): + del request.session['count'] + return redirect(index) \ No newline at end of file diff --git a/richardN/django/randomWg/db.sqlite3 b/richardN/django/randomWg/db.sqlite3 new file mode 100644 index 0000000..adf6f61 Binary files /dev/null and b/richardN/django/randomWg/db.sqlite3 differ diff --git a/richardN/django/randomWg/manage.py b/richardN/django/randomWg/manage.py new file mode 100644 index 0000000..baa19f8 --- /dev/null +++ b/richardN/django/randomWg/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "randomWg.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/richardN/django/randomWg/randomWg/__init__.py b/richardN/django/randomWg/randomWg/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/randomWg/randomWg/settings.py b/richardN/django/randomWg/randomWg/settings.py new file mode 100644 index 0000000..a7b1da9 --- /dev/null +++ b/richardN/django/randomWg/randomWg/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for randomWg project. + +Generated by 'django-admin startproject' using Django 1.11.7. + +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 = '3ih2hc31eb=jbfcwtp*o_+quf3y+4!qsk(o0_ju#^l*h2(9m1h' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.randomWg_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 = 'randomWg.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 = 'randomWg.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/richardN/django/randomWg/randomWg/urls.py b/richardN/django/randomWg/randomWg/urls.py new file mode 100644 index 0000000..7595cf9 --- /dev/null +++ b/richardN/django/randomWg/randomWg/urls.py @@ -0,0 +1,22 @@ +"""randomWg 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.randomWg_app.urls')), + url(r'^admin/', admin.site.urls), +] diff --git a/richardN/django/randomWg/randomWg/wsgi.py b/richardN/django/randomWg/randomWg/wsgi.py new file mode 100644 index 0000000..27fb582 --- /dev/null +++ b/richardN/django/randomWg/randomWg/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for randomWg 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", "randomWg.settings") + +application = get_wsgi_application() diff --git a/richardN/django/session_words/apps/__init__.py b/richardN/django/session_words/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/session_words/apps/session_app/__init__.py b/richardN/django/session_words/apps/session_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/session_words/apps/session_app/admin.py b/richardN/django/session_words/apps/session_app/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/richardN/django/session_words/apps/session_app/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/richardN/django/session_words/apps/session_app/apps.py b/richardN/django/session_words/apps/session_app/apps.py new file mode 100644 index 0000000..58b75c3 --- /dev/null +++ b/richardN/django/session_words/apps/session_app/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class SessionAppConfig(AppConfig): + name = 'session_app' diff --git a/richardN/django/session_words/apps/session_app/migrations/__init__.py b/richardN/django/session_words/apps/session_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/session_words/apps/session_app/models.py b/richardN/django/session_words/apps/session_app/models.py new file mode 100644 index 0000000..1dfab76 --- /dev/null +++ b/richardN/django/session_words/apps/session_app/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/richardN/django/session_words/apps/session_app/static/session_app/css/style.css b/richardN/django/session_words/apps/session_app/static/session_app/css/style.css new file mode 100644 index 0000000..50bd674 --- /dev/null +++ b/richardN/django/session_words/apps/session_app/static/session_app/css/style.css @@ -0,0 +1,12 @@ +.red { + color: red; + } + .blue { + color: blue; + } + .green { + color: green; + } + .bigfont { + font-size: 40px; + } \ No newline at end of file diff --git a/richardN/django/session_words/apps/session_app/templates/session_app/index.html b/richardN/django/session_words/apps/session_app/templates/session_app/index.html new file mode 100644 index 0000000..769c488 --- /dev/null +++ b/richardN/django/session_words/apps/session_app/templates/session_app/index.html @@ -0,0 +1,48 @@ + + + + + Index + {% load static %} + + + +
+ {% csrf_token %} +

Add a word

+ +

Choose color:

+ Red + + | Green + + | Blue + +
+
+ + Show in BIG fonts! +
+ +
+
+ +
+ {% csrf_token %} + + +
+ + + + + + {% for word in request.session.words %} + + + + + {% endfor %} +
WordTime Added
{{word.word}}{{word.time}}
+ + \ No newline at end of file diff --git a/richardN/django/session_words/apps/session_app/tests.py b/richardN/django/session_words/apps/session_app/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/richardN/django/session_words/apps/session_app/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/richardN/django/session_words/apps/session_app/urls.py b/richardN/django/session_words/apps/session_app/urls.py new file mode 100644 index 0000000..bb5f643 --- /dev/null +++ b/richardN/django/session_words/apps/session_app/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url +from . import views # This line is new! +urlpatterns = [ + url(r'^$', views.index), + url(r'^add$', views.add), + url(r'^clear', views.clear), +] \ No newline at end of file diff --git a/richardN/django/session_words/apps/session_app/views.py b/richardN/django/session_words/apps/session_app/views.py new file mode 100644 index 0000000..40a1923 --- /dev/null +++ b/richardN/django/session_words/apps/session_app/views.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render, redirect, HttpResponse +from time import gmtime, strftime +# Create your views here. + +def index(request): + return render(request, 'session_app/index.html') + +def add(request): + if request.method == 'POST': + form_data = request.POST + + word = { + 'time': strftime("%Y-%m-%d %H:%M %p", gmtime()), + 'word': form_data['word'], + 'color': form_data['color'], + 'bigfont': 'bigfont' if 'bigfont' in form_data else 'smallfont' + } + if 'words' not in request.session: + request.session['words'] = [] + request.session['words'] += [word] + + return redirect('/') + +def clear(request): + request.session.clear() + return redirect('/') \ No newline at end of file diff --git a/richardN/django/session_words/db.sqlite3 b/richardN/django/session_words/db.sqlite3 new file mode 100644 index 0000000..10d656b Binary files /dev/null and b/richardN/django/session_words/db.sqlite3 differ diff --git a/richardN/django/session_words/manage.py b/richardN/django/session_words/manage.py new file mode 100644 index 0000000..fe8c8a4 --- /dev/null +++ b/richardN/django/session_words/manage.py @@ -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) diff --git a/richardN/django/session_words/session_words/__init__.py b/richardN/django/session_words/session_words/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/session_words/session_words/settings.py b/richardN/django/session_words/session_words/settings.py new file mode 100644 index 0000000..99696e2 --- /dev/null +++ b/richardN/django/session_words/session_words/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for session_words project. + +Generated by 'django-admin startproject' using Django 1.11.7. + +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 = 'zr+!t*9)age4)xjw98jp#+vpn@26!xmr&^!w8-o8+3j9d6ksnp' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.session_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.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/richardN/django/session_words/session_words/urls.py b/richardN/django/session_words/session_words/urls.py new file mode 100644 index 0000000..8d8fde5 --- /dev/null +++ b/richardN/django/session_words/session_words/urls.py @@ -0,0 +1,22 @@ +"""session_words 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.session_app.urls')), + url(r'^admin/', admin.site.urls), +] diff --git a/richardN/django/session_words/session_words/wsgi.py b/richardN/django/session_words/session_words/wsgi.py new file mode 100644 index 0000000..bc39ad3 --- /dev/null +++ b/richardN/django/session_words/session_words/wsgi.py @@ -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.11/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() diff --git a/richardN/django/timeDisp_asign/apps/__init__.py b/richardN/django/timeDisp_asign/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/timeDisp_asign/apps/timeDisp_app/__init__.py b/richardN/django/timeDisp_asign/apps/timeDisp_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/timeDisp_asign/apps/timeDisp_app/admin.py b/richardN/django/timeDisp_asign/apps/timeDisp_app/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/richardN/django/timeDisp_asign/apps/timeDisp_app/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/richardN/django/timeDisp_asign/apps/timeDisp_app/apps.py b/richardN/django/timeDisp_asign/apps/timeDisp_app/apps.py new file mode 100644 index 0000000..4290ec1 --- /dev/null +++ b/richardN/django/timeDisp_asign/apps/timeDisp_app/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class TimedispAppConfig(AppConfig): + name = 'timeDisp_app' diff --git a/richardN/django/timeDisp_asign/apps/timeDisp_app/migrations/__init__.py b/richardN/django/timeDisp_asign/apps/timeDisp_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/timeDisp_asign/apps/timeDisp_app/models.py b/richardN/django/timeDisp_asign/apps/timeDisp_app/models.py new file mode 100644 index 0000000..1dfab76 --- /dev/null +++ b/richardN/django/timeDisp_asign/apps/timeDisp_app/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/richardN/django/timeDisp_asign/apps/timeDisp_app/templates/timeDisp_app/index.html b/richardN/django/timeDisp_asign/apps/timeDisp_app/templates/timeDisp_app/index.html new file mode 100644 index 0000000..a7cab8f --- /dev/null +++ b/richardN/django/timeDisp_asign/apps/timeDisp_app/templates/timeDisp_app/index.html @@ -0,0 +1,2 @@ +

The date and time is:

+
{{time}}
diff --git a/richardN/django/timeDisp_asign/apps/timeDisp_app/tests.py b/richardN/django/timeDisp_asign/apps/timeDisp_app/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/richardN/django/timeDisp_asign/apps/timeDisp_app/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/richardN/django/timeDisp_asign/apps/timeDisp_app/urls.py b/richardN/django/timeDisp_asign/apps/timeDisp_app/urls.py new file mode 100644 index 0000000..8d28477 --- /dev/null +++ b/richardN/django/timeDisp_asign/apps/timeDisp_app/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url +from . import views + +urlpatterns = [ + url(r'^$', views.index), +] diff --git a/richardN/django/timeDisp_asign/apps/timeDisp_app/views.py b/richardN/django/timeDisp_asign/apps/timeDisp_app/views.py new file mode 100644 index 0000000..eae69d8 --- /dev/null +++ b/richardN/django/timeDisp_asign/apps/timeDisp_app/views.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render + +# Create your views here. + # the index function is called when root is visited +from django.shortcuts import render, HttpResponse, redirect +from time import gmtime, strftime + +def index(request): + response = "The Date and Time is:" + return HttpResponse(response) + +def index(request): + context = { + "time": strftime("%Y-%m-%d %H:%M %p", gmtime()) + } + return render(request,'timeDisp_app/index.html', context) \ No newline at end of file diff --git a/richardN/django/timeDisp_asign/db.sqlite3 b/richardN/django/timeDisp_asign/db.sqlite3 new file mode 100644 index 0000000..e3d7819 Binary files /dev/null and b/richardN/django/timeDisp_asign/db.sqlite3 differ diff --git a/richardN/django/timeDisp_asign/manage.py b/richardN/django/timeDisp_asign/manage.py new file mode 100644 index 0000000..d18003c --- /dev/null +++ b/richardN/django/timeDisp_asign/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "timeDisp_asign.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/richardN/django/timeDisp_asign/timeDisp_asign/__init__.py b/richardN/django/timeDisp_asign/timeDisp_asign/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/timeDisp_asign/timeDisp_asign/settings.py b/richardN/django/timeDisp_asign/timeDisp_asign/settings.py new file mode 100644 index 0000000..5405113 --- /dev/null +++ b/richardN/django/timeDisp_asign/timeDisp_asign/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for timeDisp_asign project. + +Generated by 'django-admin startproject' using Django 1.11.7. + +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 = '@1z1ix4ca@g0@%dw7j8s4g=--6j^m#9cxlps7ac)4-(ubvh6s7' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.timeDisp_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 = 'timeDisp_asign.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 = 'timeDisp_asign.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/richardN/django/timeDisp_asign/timeDisp_asign/urls.py b/richardN/django/timeDisp_asign/timeDisp_asign/urls.py new file mode 100644 index 0000000..d4f6636 --- /dev/null +++ b/richardN/django/timeDisp_asign/timeDisp_asign/urls.py @@ -0,0 +1,22 @@ +"""timeDisp_asign 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.timeDisp_app.urls')), + url(r'^admin/', admin.site.urls), +] diff --git a/richardN/django/timeDisp_asign/timeDisp_asign/wsgi.py b/richardN/django/timeDisp_asign/timeDisp_asign/wsgi.py new file mode 100644 index 0000000..e82a789 --- /dev/null +++ b/richardN/django/timeDisp_asign/timeDisp_asign/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for timeDisp_asign 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", "timeDisp_asign.settings") + +application = get_wsgi_application() diff --git a/richardN/django/user_ass/apps/__init__.py b/richardN/django/user_ass/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/user_ass/apps/user_app/__init__.py b/richardN/django/user_ass/apps/user_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/user_ass/apps/user_app/admin.py b/richardN/django/user_ass/apps/user_app/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/richardN/django/user_ass/apps/user_app/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/richardN/django/user_ass/apps/user_app/apps.py b/richardN/django/user_ass/apps/user_app/apps.py new file mode 100644 index 0000000..b6867f5 --- /dev/null +++ b/richardN/django/user_ass/apps/user_app/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class UserAppConfig(AppConfig): + name = 'user_app' diff --git a/richardN/django/user_ass/apps/user_app/migrations/0001_initial.py b/richardN/django/user_ass/apps/user_app/migrations/0001_initial.py new file mode 100644 index 0000000..0966bce --- /dev/null +++ b/richardN/django/user_ass/apps/user_app/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2017-11-21 22:28 +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)), + ('age', models.IntegerField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/richardN/django/user_ass/apps/user_app/migrations/__init__.py b/richardN/django/user_ass/apps/user_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/user_ass/apps/user_app/models.py b/richardN/django/user_ass/apps/user_app/models.py new file mode 100644 index 0000000..cfe0bd4 --- /dev/null +++ b/richardN/django/user_ass/apps/user_app/models.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +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 = models.CharField(max_length=255) + age =models.IntegerField() + created_at = models.DateTimeField(auto_now_add = True) + updated_at = models.DateTimeField(auto_now = True) + def __str__(self): + return self.email \ No newline at end of file diff --git a/richardN/django/user_ass/apps/user_app/templates/user_app/index.html b/richardN/django/user_ass/apps/user_app/templates/user_app/index.html new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/user_ass/apps/user_app/tests.py b/richardN/django/user_ass/apps/user_app/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/richardN/django/user_ass/apps/user_app/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/richardN/django/user_ass/apps/user_app/urls.py b/richardN/django/user_ass/apps/user_app/urls.py new file mode 100644 index 0000000..0ff096d --- /dev/null +++ b/richardN/django/user_ass/apps/user_app/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls import url +from . import views # This line is new! +urlpatterns = [ + url(r'^$', views.index) # This line has changed! + ] \ No newline at end of file diff --git a/richardN/django/user_ass/apps/user_app/views.py b/richardN/django/user_ass/apps/user_app/views.py new file mode 100644 index 0000000..7a31ee6 --- /dev/null +++ b/richardN/django/user_ass/apps/user_app/views.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render + +# Create your views here. +from django.shortcuts import HttpResponse +# the index function is called when root is visited +def index(request): + return HttpResponse("Shell Queries") \ No newline at end of file diff --git a/richardN/django/user_ass/db.sqlite3 b/richardN/django/user_ass/db.sqlite3 new file mode 100644 index 0000000..17ee685 Binary files /dev/null and b/richardN/django/user_ass/db.sqlite3 differ diff --git a/richardN/django/user_ass/manage.py b/richardN/django/user_ass/manage.py new file mode 100644 index 0000000..5e42903 --- /dev/null +++ b/richardN/django/user_ass/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "user_ass.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/richardN/django/user_ass/user_ass/__init__.py b/richardN/django/user_ass/user_ass/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/richardN/django/user_ass/user_ass/settings.py b/richardN/django/user_ass/user_ass/settings.py new file mode 100644 index 0000000..c8005ba --- /dev/null +++ b/richardN/django/user_ass/user_ass/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for user_ass project. + +Generated by 'django-admin startproject' using Django 1.11.7. + +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 = 'k$+hi!nkuct&_yb1sf1^t*8pril8qsl)5ieg-^i$ys9%)fnz34' + +# 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 = 'user_ass.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 = 'user_ass.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/richardN/django/user_ass/user_ass/urls.py b/richardN/django/user_ass/user_ass/urls.py new file mode 100644 index 0000000..89c7e35 --- /dev/null +++ b/richardN/django/user_ass/user_ass/urls.py @@ -0,0 +1,22 @@ +"""user_ass 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.user_app.urls')), + url(r'^admin/', admin.site.urls), +] diff --git a/richardN/django/user_ass/user_ass/wsgi.py b/richardN/django/user_ass/user_ass/wsgi.py new file mode 100644 index 0000000..d01e2e3 --- /dev/null +++ b/richardN/django/user_ass/user_ass/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for user_ass 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", "user_ass.settings") + +application = get_wsgi_application() diff --git a/richardN/flaskMySQL/friendships/dataBase/friends.sql b/richardN/flaskMySQL/friendships/dataBase/friends.sql new file mode 100644 index 0000000..0f7af16 --- /dev/null +++ b/richardN/flaskMySQL/friendships/dataBase/friends.sql @@ -0,0 +1,33 @@ +-- MySQL Workbench Forward Engineering + +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; + +-- ----------------------------------------------------- +-- Schema mydb +-- ----------------------------------------------------- + +-- ----------------------------------------------------- +-- Schema mydb +-- ----------------------------------------------------- +CREATE SCHEMA IF NOT EXISTS `friendsdb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ; +USE `friendsdb` ; + +-- ----------------------------------------------------- +-- Table `mydb`.`friends` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `friendsdb`.`friends` ( + `id` INT NOT NULL AUTO_INCREMENT, + `first_name` VARCHAR(45) NULL, + `last_name` VARCHAR(45) NULL, + `occupation` VARCHAR(45) NULL, + `created_at` DATETIME NULL, + `updated_at` DATETIME NULL, + PRIMARY KEY (`id`)) +ENGINE = InnoDB; + + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; diff --git a/richardN/flaskMySQL/friendships/server.py b/richardN/flaskMySQL/friendships/server.py new file mode 100644 index 0000000..b62ffac --- /dev/null +++ b/richardN/flaskMySQL/friendships/server.py @@ -0,0 +1,15 @@ +from flask import Flask, request, redirect, render_template, session, flash +from mysqlconnection import MySQLConnector +app = Flask(__name__) +mysql = MySQLConnector(app,'friendsdb') +@app.route('/') +def index(): + friends = mysql.query_db("SELECT * FROM friends") + print friends + return render_template('index.html') +@app.route('/friends', methods=['POST']) +def create(): + # add a friend to the database! + return redirect('/') + +app.run(debug=True) diff --git a/richardN/flaskMySQL/friendships/templates/index.html b/richardN/flaskMySQL/friendships/templates/index.html new file mode 100644 index 0000000..f8adff9 --- /dev/null +++ b/richardN/flaskMySQL/friendships/templates/index.html @@ -0,0 +1,23 @@ + + + Friends + + +

These are all my friends!

+

First Name: Jay

+

Last Name: Patel

+

Occupation: Instructor

+
+

First Name: Jimmy

+

Last Name: Jun

+

Occupation: Instructor

+
+

Add a Friend

+
+ + + + +
+ + diff --git a/richardN/flaskMySQL/mySQLconnection.py b/richardN/flaskMySQL/mySQLconnection.py new file mode 100644 index 0000000..a12daeb --- /dev/null +++ b/richardN/flaskMySQL/mySQLconnection.py @@ -0,0 +1,40 @@ +""" import the necessary modules """ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text +# Create a class that will give us an object that we can use to connect to a database +class MySQLConnection(object): + def __init__(self, app, db): + config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'root', + 'port': '3306' # change the port to match the port your SQL server is running on + } + # this will use the above values to generate the path to connect to your sql database + DATABASE_URI = "mysql://{}:{}@127.0.0.1:{}/{}".format(config['user'], config['password'], config['port'], config['database']) + app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True + # establish the connection to database + self.db = SQLAlchemy(app) + # this is the method we will use to query the database + def query_db(self, query, data=None): + result = self.db.session.execute(text(query), data) + if query[0:6].lower() == 'select': + # if the query was a select + # convert the result to a list of dictionaries + list_result = [dict(r) for r in result] + # return the results as a list of dictionaries + return list_result + elif query[0:6].lower() == 'insert': + # if the query was an insert, return the id of the + # commit changes + self.db.session.commit() + # row that was inserted + return result.lastrowid + else: + # if the query was an update or delete, return nothing and commit changes + self.db.session.commit() +# This is the module method to be called by the user in server.py. Make sure to provide the db name! +def MySQLConnector(app, db): + return MySQLConnection(app, db) diff --git a/richardN/flaskMySQL/server.py b/richardN/flaskMySQL/server.py new file mode 100644 index 0000000..c6f96e5 --- /dev/null +++ b/richardN/flaskMySQL/server.py @@ -0,0 +1,17 @@ +from flask import Flask +# import the Connector function +from mySQLconnection import MySQLConnector +app = Flask(__name__) +# connect and store the connection in "mysql"; note that you pass the database name to the function +mysql = MySQLConnector(app, 'mydb') +# an example of running a query +print mysql.query_db("SELECT * FROM users") +config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'fml', + 'port': '3306' # change the port to match the port your SQL server is running on +} + +app.run(debug=True) diff --git a/richardN/mySqlQueries/friendships/friendships.mwb b/richardN/mySqlQueries/friendships/friendships.mwb new file mode 100644 index 0000000..33ccbd1 Binary files /dev/null and b/richardN/mySqlQueries/friendships/friendships.mwb differ diff --git a/richardN/mySqlQueries/friendships/friendships.mwb 2.mwb b/richardN/mySqlQueries/friendships/friendships.mwb 2.mwb new file mode 100644 index 0000000..3e9cac6 Binary files /dev/null and b/richardN/mySqlQueries/friendships/friendships.mwb 2.mwb differ diff --git a/richardN/mySqlQueries/friendships/friendships.mwb.bak b/richardN/mySqlQueries/friendships/friendships.mwb.bak new file mode 100644 index 0000000..7d9173f Binary files /dev/null and b/richardN/mySqlQueries/friendships/friendships.mwb.bak differ diff --git a/richardN/mySqlQueries/friendships/friendships.mwb.mwb b/richardN/mySqlQueries/friendships/friendships.mwb.mwb new file mode 100644 index 0000000..1cfa9ec Binary files /dev/null and b/richardN/mySqlQueries/friendships/friendships.mwb.mwb differ diff --git a/richardN/mySqlQueries/friendships/friendshipsQuery.sql b/richardN/mySqlQueries/friendships/friendshipsQuery.sql new file mode 100644 index 0000000..b96d779 --- /dev/null +++ b/richardN/mySqlQueries/friendships/friendshipsQuery.sql @@ -0,0 +1,26 @@ +INSERT INTO users (first_name, last_name, created_at, updated_at) +VALUES ('Chris','Baker', NOW(), NOW() ); + +INSERT INTO users (first_name, last_name, created_at, updated_at) +VALUES ('Dianna','Smith', NOW(), NOW() ); + +INSERT INTO users (first_name, last_name, created_at, updated_at) +VALUES ('James','Johnson', NOW(), NOW() ); + +INSERT INTO users (first_name, last_name, created_at, updated_at) +VALUES ('Jessica','Davidson', NOW(), NOW() ); + +INSERT INTO friendships (users_id, friend_id) +VALUES(1,4); + +INSERT INTO friendships (users_id, friend_id) +VALUES(2,1); + +INSERT INTO friendships (users_id, friend_id) +VALUES(3,4); + + +SELECT users.first_name, users.last_name, users1.first_name AS friend_first_name, users1.last_name AS friend_last_name FROM users +LEFT JOIN friendships ON users.id = friendships.users_id +LEFT JOIN users AS users1 ON friendships.friend_id = users1.id +ORDER BY friend_last_name; diff --git a/richardN/mySqlQueries/friendships/queryCommands b/richardN/mySqlQueries/friendships/queryCommands new file mode 100644 index 0000000..b96d779 --- /dev/null +++ b/richardN/mySqlQueries/friendships/queryCommands @@ -0,0 +1,26 @@ +INSERT INTO users (first_name, last_name, created_at, updated_at) +VALUES ('Chris','Baker', NOW(), NOW() ); + +INSERT INTO users (first_name, last_name, created_at, updated_at) +VALUES ('Dianna','Smith', NOW(), NOW() ); + +INSERT INTO users (first_name, last_name, created_at, updated_at) +VALUES ('James','Johnson', NOW(), NOW() ); + +INSERT INTO users (first_name, last_name, created_at, updated_at) +VALUES ('Jessica','Davidson', NOW(), NOW() ); + +INSERT INTO friendships (users_id, friend_id) +VALUES(1,4); + +INSERT INTO friendships (users_id, friend_id) +VALUES(2,1); + +INSERT INTO friendships (users_id, friend_id) +VALUES(3,4); + + +SELECT users.first_name, users.last_name, users1.first_name AS friend_first_name, users1.last_name AS friend_last_name FROM users +LEFT JOIN friendships ON users.id = friendships.users_id +LEFT JOIN users AS users1 ON friendships.friend_id = users1.id +ORDER BY friend_last_name; diff --git a/richardN/sqlFlask/emailValidation/emailval.mwb b/richardN/sqlFlask/emailValidation/emailval.mwb new file mode 100644 index 0000000..32720e0 Binary files /dev/null and b/richardN/sqlFlask/emailValidation/emailval.mwb differ diff --git a/richardN/sqlFlask/emailValidation/emailval.mwb.mwb b/richardN/sqlFlask/emailValidation/emailval.mwb.mwb new file mode 100644 index 0000000..7557529 Binary files /dev/null and b/richardN/sqlFlask/emailValidation/emailval.mwb.mwb differ diff --git a/richardN/sqlFlask/emailValidation/emailvali.py b/richardN/sqlFlask/emailValidation/emailvali.py new file mode 100644 index 0000000..03d6d57 --- /dev/null +++ b/richardN/sqlFlask/emailValidation/emailvali.py @@ -0,0 +1,41 @@ + +from flask import Flask, render_template, redirect, request, flash +from mysqlconnection import MySQLConnector +import re +import sys + +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') + +app = Flask(__name__) +app.secret_key='theyMayTakeOurLandButTheyWillNeverTakeOurFreedom!' + +mysql = MySQLConnector(app, 'emailval') + +@app.route("/") +def index(): + return render_template("page0.html") + +@app.route("/page1", methods=["POST"]) +def process(): + if len(request.form['email']) == 0: + flash("email can't be empty") + return redirect('/') + if not EMAIL_REGEX.match(request.form['email']): + flash("email not valid ") + return redirect('/') + + mysql.query_db("INSERT INTO emails(email, created_at) Values(:email, now())", {"email": request.form['email']}) + return redirect('/page1') + +@app.route('/page1') +def sucess(): + data = mysql.query_db("SELECT id, email, DATE_FORMAT(created_at, '%m/%e/%y %l:%i %p') AS date FROM emails") + + return render_template("page1.html", data = data) + +@app.route('/delete', methods=['POST']) +def delete(): + id = int(request.form['id']) + mysql.query_db("DELETE FROM emails WHERE id = :id", {"id": id }) + return redirect('/page1') +app.run(debug=True) diff --git a/richardN/sqlFlask/emailValidation/mysqlconnection.py b/richardN/sqlFlask/emailValidation/mysqlconnection.py new file mode 100644 index 0000000..a12daeb --- /dev/null +++ b/richardN/sqlFlask/emailValidation/mysqlconnection.py @@ -0,0 +1,40 @@ +""" import the necessary modules """ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text +# Create a class that will give us an object that we can use to connect to a database +class MySQLConnection(object): + def __init__(self, app, db): + config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'root', + 'port': '3306' # change the port to match the port your SQL server is running on + } + # this will use the above values to generate the path to connect to your sql database + DATABASE_URI = "mysql://{}:{}@127.0.0.1:{}/{}".format(config['user'], config['password'], config['port'], config['database']) + app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True + # establish the connection to database + self.db = SQLAlchemy(app) + # this is the method we will use to query the database + def query_db(self, query, data=None): + result = self.db.session.execute(text(query), data) + if query[0:6].lower() == 'select': + # if the query was a select + # convert the result to a list of dictionaries + list_result = [dict(r) for r in result] + # return the results as a list of dictionaries + return list_result + elif query[0:6].lower() == 'insert': + # if the query was an insert, return the id of the + # commit changes + self.db.session.commit() + # row that was inserted + return result.lastrowid + else: + # if the query was an update or delete, return nothing and commit changes + self.db.session.commit() +# This is the module method to be called by the user in server.py. Make sure to provide the db name! +def MySQLConnector(app, db): + return MySQLConnection(app, db) diff --git a/richardN/sqlFlask/emailValidation/templates/page0.html b/richardN/sqlFlask/emailValidation/templates/page0.html new file mode 100644 index 0000000..eae0fb4 --- /dev/null +++ b/richardN/sqlFlask/emailValidation/templates/page0.html @@ -0,0 +1,26 @@ + + + + + emailValidation + + + + + {% with messages = get_flashed_messages() %} + {% if messages %} +
+

EMAIL NOT VALID

+

{{ messages[0] }}

+
+ {% endif %} + {% endwith %} + + +
+ + + +
+ + diff --git a/richardN/sqlFlask/emailValidation/templates/page1.html b/richardN/sqlFlask/emailValidation/templates/page1.html new file mode 100644 index 0000000..43f9c7d --- /dev/null +++ b/richardN/sqlFlask/emailValidation/templates/page1.html @@ -0,0 +1,26 @@ + + + + + Page1 + + + +
+

Your email is VALID

+
+

Email:

+
+ + {% for email in data %} + + + + + + {% endfor %} +
{{email.email}}{{email.date}}
+
+ + + diff --git a/richardN/sqlFlask/friends/friends.mwb b/richardN/sqlFlask/friends/friends.mwb new file mode 100644 index 0000000..5a0fc66 Binary files /dev/null and b/richardN/sqlFlask/friends/friends.mwb differ diff --git a/richardN/sqlFlask/friends/friends.mwb.mwb b/richardN/sqlFlask/friends/friends.mwb.mwb new file mode 100644 index 0000000..89fe84b Binary files /dev/null and b/richardN/sqlFlask/friends/friends.mwb.mwb differ diff --git a/richardN/sqlFlask/friends/friends.py b/richardN/sqlFlask/friends/friends.py new file mode 100644 index 0000000..032b460 --- /dev/null +++ b/richardN/sqlFlask/friends/friends.py @@ -0,0 +1,59 @@ + +from flask import Flask, render_template, redirect, request, flash +from mySqlConnection import MySQLConnector +import re +import sys + +def log(obj): + print(obj) + +NAME_REGEX = re.compile(r'^[a-zA-Z-]+$') + +app = Flask(__name__) +app.secret_key="whoDoYouThinkYouArelookingInHere" + +mysql = MySQLConnector(app, 'mydb') + +@app.route("/") +def index(): + query = "SELECT * FROM friends" + data = mysql.query_db(query) + return render_template("page1.html", data=data) + +@app.route('/process', methods=["POST"]) +def process(): + log(request.form) + error = False + if len(request.form['first_name']) == 0: + flash("enter a first name") + error = True + if not NAME_REGEX.match(request.form['first_name']): + flash("name is invalid") + error = True + if len(request.form['last_name']) == 0: + flash("enter a last name") + error = True + if not NAME_REGEX.match(request.form['last_name']): + flash("name is invalid") + error = True + if len(request.form['age']) == 0: + flash("enter an age") + error = True + elif not request.form['age'].isdigit(): + flash("age must be a number") + error = True + elif int(request.form['age']) < 0: + flash("Age is invalid") + error = True + + if error: + return redirect("/") + + query = 'INSERT INTO friends(first_name, last_name, age, since) VALUES(:first_name, :last_name, :age, now())' + data = {"first_name":request.form["first_name"],"last_name":request.form["last_name"], "age":request.form["age"]} + mysql.query_db(query, data) + return redirect('/') + + + +app.run(debug=True) diff --git a/richardN/sqlFlask/friends/mySqlConnection.py b/richardN/sqlFlask/friends/mySqlConnection.py new file mode 100644 index 0000000..a304b9a --- /dev/null +++ b/richardN/sqlFlask/friends/mySqlConnection.py @@ -0,0 +1,40 @@ +""" import the necessary modules """ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text +# Create a class that will give us an object that we can use to connect to a database +class MySQLConnection(object): + def __init__(self, app, db): + config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'root', + 'port': '3306' # change the port to match the port your SQL server is running on + } + # this will use the above values to generate the path to connect to your sql database + DATABASE_URI = "mysql://{}:{}@127.0.0.1:{}/{}".format(config['user'], config['password'], config['port'], config['database']) + app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True + # establish the connection to database + self.db = SQLAlchemy(app) + # this is the method we will use to query the database + def query_db(self, query, data=None): + result = self.db.session.execute(text(query), data) + if query[0:6].lower() == 'select': + # if the query was a select + # convert the result to a list of dictionaries + list_result = [dict(r) for r in result] + # return the results as a list of dictionaries + return list_result + elif query[0:6].lower() == 'insert': + # if the query was an insert, return the id of the + # commit changes + self.db.session.commit() + # row that was inserted + return result.lastrowid + else: + # if the query was an update or delete, return nothing and commit changes + self.db.session.commit() +# This is the module method to be called by the user in server.py. Make sure to provide the db name! +def MySQLConnector(app, db): + return MySQLConnection(app, db) diff --git a/richardN/sqlFlask/friends/templates/page1.html b/richardN/sqlFlask/friends/templates/page1.html new file mode 100644 index 0000000..d562b5d --- /dev/null +++ b/richardN/sqlFlask/friends/templates/page1.html @@ -0,0 +1,45 @@ + + + + + FacelessBook + + +

Friends

+ + + + + + + + {% with friends = data %} + {% if friends %} + {% for friend in friends %} + + + + + + {% endfor %} + {% endif %} + {% endwith %} +
NameAgeFriend Since
{{friend.first_name}} {{friend.last_name}}{{friend.age}}{{friend.since}}
+

Add a Friend

+ {% with messages = get_flashed_messages() %} + {% if messages %} +
    + {% for message in messages %} +
  • {{ message }}
  • + {% endfor %} +
+ {% endif %} + {% endwith %} + +
+ +
+
+
+ +
diff --git a/richardN/sqlFlask/logNreg/logNreg.mwb b/richardN/sqlFlask/logNreg/logNreg.mwb new file mode 100644 index 0000000..5ac4b23 Binary files /dev/null and b/richardN/sqlFlask/logNreg/logNreg.mwb differ diff --git a/richardN/sqlFlask/logNreg/logNreg.mwb.bak b/richardN/sqlFlask/logNreg/logNreg.mwb.bak new file mode 100644 index 0000000..01eab07 Binary files /dev/null and b/richardN/sqlFlask/logNreg/logNreg.mwb.bak differ diff --git a/richardN/sqlFlask/logNreg/mysqlconnection.py b/richardN/sqlFlask/logNreg/mysqlconnection.py new file mode 100644 index 0000000..a12daeb --- /dev/null +++ b/richardN/sqlFlask/logNreg/mysqlconnection.py @@ -0,0 +1,40 @@ +""" import the necessary modules """ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text +# Create a class that will give us an object that we can use to connect to a database +class MySQLConnection(object): + def __init__(self, app, db): + config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'root', + 'port': '3306' # change the port to match the port your SQL server is running on + } + # this will use the above values to generate the path to connect to your sql database + DATABASE_URI = "mysql://{}:{}@127.0.0.1:{}/{}".format(config['user'], config['password'], config['port'], config['database']) + app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True + # establish the connection to database + self.db = SQLAlchemy(app) + # this is the method we will use to query the database + def query_db(self, query, data=None): + result = self.db.session.execute(text(query), data) + if query[0:6].lower() == 'select': + # if the query was a select + # convert the result to a list of dictionaries + list_result = [dict(r) for r in result] + # return the results as a list of dictionaries + return list_result + elif query[0:6].lower() == 'insert': + # if the query was an insert, return the id of the + # commit changes + self.db.session.commit() + # row that was inserted + return result.lastrowid + else: + # if the query was an update or delete, return nothing and commit changes + self.db.session.commit() +# This is the module method to be called by the user in server.py. Make sure to provide the db name! +def MySQLConnector(app, db): + return MySQLConnection(app, db) diff --git a/richardN/sqlFlask/logNreg/server.py b/richardN/sqlFlask/logNreg/server.py new file mode 100644 index 0000000..28ddc18 --- /dev/null +++ b/richardN/sqlFlask/logNreg/server.py @@ -0,0 +1,116 @@ +import md5, os, binascii, random +from flask import Flask, flash, redirect, render_template, request, session +from mysqlconnection import MySQLConnector + +import re +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') +app = Flask(__name__) +app.secret_key = "nukedMyFirstTry" +mysql = MySQLConnector(app,'logNreg') + + +@app.route('/') +def index(): + return render_template('index.html') + if id not in session: + session['id'] = id + +@app.route('/register', methods = ['POST']) +def reg(): + valid = True + newUser = { + 'email': request.form['email'], + 'hashPass': request.form['hashPass'], + 'cPassword': request.form['cPassword'], + 'first_name': request.form['first_name'], + 'last_name': request.form['last_name'] + } + email = request.form['email'] + hashPass = request.form['hashPass'] + cPassword = request.form['cPassword'] + first_name = request.form['first_name'] + last_name = request.form['last_name'] + + if first_name < 2: + flash("name must be greater than 2 characters") + valid = False + elif not first_name.isalpha(): + flash("name must be letters only") + valid = False + + if last_name < 2: + flash("name must be greater than 2 characters") + valid = False + elif not last_name.isalpha(): + flash("name must be letters only") + valid = False + + if len(email) < 1 or len(hashPass) < 1 or len(cPassword) < 1 : + flash("email and hashPass required") + valid = False + elif len(hashPass) < 8: + flash("hashPass is too short") + valid = False + elif hashPass != cPassword: + flash("passwords dont match") + valid = False + elif not EMAIL_REGEX.match(email): + flash("email not valid") + valid = False + + if valid: + query = "SELECT email FROM users WHERE email = :email" + emails = mysql.query_db(query, {'email':email}) + if emails: + flash("email already in use") + else: + newUser['salt'] = binascii.b2a_hex(os.urandom(15)) + newUser['hash'] = md5.new(request.form['hashPass']+newUser['salt']).hexdigest() + query = "INSERT INTO users (first_name, last_name, email, hashPass, salt, created_at, updated_at) Values ( :first_name, :last_name, :email, :hashPass, :salt, NOW(), NOW() )" + session['user_id'] = mysql.query_db(query, newUser) + print session['user_id'] + print "You registered!" + return redirect('/success') + + return redirect('/') +@app.route('/login', methods = ['POST']) +def login(): + valid = True + newUser = { + 'user_email': request.form['user_email'], + 'user_password': request.form['user_password'], + } + if request.form['user_email'] < 2 : + valid = False + flash("fail") + elif request.form['user_password'] < 2: + valid = False + flash("wrong") + if valid: + query = "SELECT * FROM users WHERE email = :email" + users = mysql.query_db(query, {'email':newUser['user_email']}) + if len(users) > 0: + user = users[0] + if md5.new(request.form['user_password']+user['salt']).hexdigest(): + flash("You are logged in") + session['user_id'] = user['id'] + return redirect('/success') + else: + flash("Login failed") + return redirect ('/') + else: + flash("User not found") + return redirect ('/') + +@app.route('/success') +def show(): + query = "SELECT * from users WHERE id = :id" + data = {'id' :session['user_id']} + users = mysql.query_db(query, data) + print data + return render_template('show.html', user = users[0]) + + + +app.run(debug=True) + diff --git a/richardN/sqlFlask/logNreg/templates/index.html b/richardN/sqlFlask/logNreg/templates/index.html new file mode 100644 index 0000000..3860489 --- /dev/null +++ b/richardN/sqlFlask/logNreg/templates/index.html @@ -0,0 +1,74 @@ + + + + + + + + + + + Login and Registration + + + + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} + {% endwith %} +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ + diff --git a/richardN/sqlFlask/logNreg/templates/show.html b/richardN/sqlFlask/logNreg/templates/show.html new file mode 100644 index 0000000..b62b31a --- /dev/null +++ b/richardN/sqlFlask/logNreg/templates/show.html @@ -0,0 +1,16 @@ + + + + + + + User profile + + +

User

+

First name: {{user['first_name']}}

+

Last name: {{user['last_name']}}

+

Email: {{user['email']}}

+

Password: {{user['password']}}

+ + diff --git a/richardN/sqlFlask/server.py b/richardN/sqlFlask/server.py new file mode 100644 index 0000000..8c47b81 --- /dev/null +++ b/richardN/sqlFlask/server.py @@ -0,0 +1,149 @@ +from flask import Flask, flash, redirect, render_template, request, session +from mysqlconnection import MySQLConnector +import re + +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') +app = Flask(__name__) +app.secret_key = "thisMustBeTrumpsWallCuzItSucks" +mysql = MySQLConnector(app, 'wall') + +@app.route('/', methods=['get']) +def index(): + return render_template('index.html') + if id not in session: + session['id'] = id + +@app.route('/register', methods = ['post']) +def register(): + valid = True + newData = { + 'email': request.form['email'], + 'password': request.form['password'], + 'cPassword': request.form['cPassword'], + 'first_name': request.form['first_name'], + 'last_name': request.form['last_name'] + } + email = request.form['email'] + password = request.form['password'] + cPassword = request.form['cPassword'] + first_name = request.form['first_name'] + last_name = request.form['last_name'] + + if first_name < 0: + flash("First name must be greater than 2 characters") + valid = False + elif not first_name.isalpha(): + flash("First name must contain only letters") + valid = False + + if last_name < 0: + flash("Last name must be greater than 2 characters") + valid = False + elif not last_name.isalpha(): + flash("Last name must contain only letters") + valid = False + + if len(email) < 0 or len(password) < 0 or len(cPassword) < 0 : + flash("Email and password required") + valid = False + elif len(password) < 8: + flash("Password too short must be 8 characters") + valid = False + elif password != cPassword: + flash("Passwords dont match") + valid = False + elif not EMAIL_REGEX.match(email): + flash("Not a valid email") + valid = False + + if valid: + query = "SELECT email FROM users WHERE email = :email" + emails = mysql.query_db(query, {'email':email}) + if emails: + flash("Email already taken") + else: + query = "INSERT INTO users (first_name, last_name, email, password, created_at, updated_at) VALUES (:first_name, :last_name, :email, :password, NOW(), NOW())" + session['user_id'] = mysql.query_db(query, newData) + print session['user_id'] + print "registered!" + return redirect('/wall') + + return redirect('/') + +@app.route('/login', methods = ['POST']) +def login(): + valid = True + userData = { + 'user_email': request.form['user_email'], + 'user_password': request.form['user_password'], + } + if request.form['user_email'] < 2 : + valid = False + flash("Invalid Email") + elif request.form['user_password'] < 2: + valid = False + flash("Invalid Password") + if valid: + query = "SELECT * FROM users WHERE email = :email" + users = mysql.query_db(query, {'email':userData['user_email']}) + if len(users) > 0: + user = users[0] + session['user_id'] = user['id'] + return redirect('/wall') + else: + flash("Login failed") + return redirect ('/') + else: + flash("User not found") + return redirect ('/') + +@app.route('/logoff') +def logoff(): + session.pop('user_id') + return redirect('/') + +@app.route('/wall') +def wall(): + if 'user_id' not in session: + return redirect('/') + + query = "SELECT messages.id, messages.message, users.first_name AS user FROM messages JOIN users on users.id = messages.user_id ORDER BY 'created_at' DESC" + messages = mysql.query_db(query) + + query = "SELECT comments.id, comment, message_id, first_name AS user FROM comments JOIN users on users.id = comments.user_id ORDER BY 'created_at' DESC" + comments = mysql.query_db(query) + + mysql.query_db(query) + return render_template('wall.html', messages=messages, comments=comments) + +@app.route('/messages', methods=["post"]) +def newMessage(): + message = request.form['message'] + if message =="": + return redirect('/wall') + + query = "INSERT INTO messages (message, user_id, created_at) VALUES (:message, :user_id, NOW())" + data = {'message':message, 'user_id': session['user_id']} + + mysql.query_db(query, data) + return redirect('/wall') + +@app.route('/comments', methods=["post"]) +def newComment(): + message_id = request.form['message_id'] + comment = request.form['comment'] + + if comment =="": + return redirect('/wall') + + query = "INSERT INTO comments (comment, created_at, message_id, user_id) VALUES (:comment, NOW(), :message_id, :user_id)" + data = {'comment':comment, 'message_id':message_id, 'user_id': session['user_id']} + + mysql.query_db(query, data) + return redirect('/wall') + + + + + +app.run(debug=True) diff --git a/richardN/sqlFlask/wall/dumpWall.sql b/richardN/sqlFlask/wall/dumpWall.sql new file mode 100644 index 0000000..a771636 --- /dev/null +++ b/richardN/sqlFlask/wall/dumpWall.sql @@ -0,0 +1,73 @@ +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; + +-- ----------------------------------------------------- +-- Schema wall +-- ----------------------------------------------------- +CREATE SCHEMA IF NOT EXISTS `wall` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ; +USE `wall` ; + +-- ----------------------------------------------------- +-- Table `wall`.`users` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `wall`.`users` ( + `id` INT NOT NULL, + `first_name` VARCHAR(255) NULL, + `last_name` VARCHAR(255) NULL, + `email` VARCHAR(255) NULL, + `password` VARCHAR(255) NULL, + `created_at` VARCHAR(255) NULL, + `updated_at` VARCHAR(255) NULL, + PRIMARY KEY (`id`)) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `wall`.`messages` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `wall`.`messages` ( + `id` INT NOT NULL AUTO_INCREMENT, + `users_id` INT NOT NULL, + `message` TEXT NULL, + `created_at` VARCHAR(255) NULL, + `updated_at` VARCHAR(255) NULL, + PRIMARY KEY (`id`), + INDEX `fk_messages_users1_idx` (`users_id` ASC), + CONSTRAINT `fk_messages_users1` + FOREIGN KEY (`users_id`) + REFERENCES `wall`.`users` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `wall`.`comments` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `wall`.`comments` ( + `id` INT NOT NULL AUTO_INCREMENT, + `users_id` INT NOT NULL, + `messages_id` INT NOT NULL, + `comment` TEXT NULL, + `created_at` VARCHAR(255) NULL, + `updated_at` VARCHAR(255) NULL, + PRIMARY KEY (`id`), + INDEX `fk_comments_users_idx` (`users_id` ASC), + INDEX `fk_comments_messages1_idx` (`messages_id` ASC), + CONSTRAINT `fk_comments_users` + FOREIGN KEY (`users_id`) + REFERENCES `wall`.`users` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `fk_comments_messages1` + FOREIGN KEY (`messages_id`) + REFERENCES `wall`.`messages` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; diff --git a/richardN/sqlFlask/wall/dumpWall1.mwb b/richardN/sqlFlask/wall/dumpWall1.mwb new file mode 100644 index 0000000..8c6862f Binary files /dev/null and b/richardN/sqlFlask/wall/dumpWall1.mwb differ diff --git a/richardN/sqlFlask/wall/mysqlconnection.py b/richardN/sqlFlask/wall/mysqlconnection.py new file mode 100644 index 0000000..a12daeb --- /dev/null +++ b/richardN/sqlFlask/wall/mysqlconnection.py @@ -0,0 +1,40 @@ +""" import the necessary modules """ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text +# Create a class that will give us an object that we can use to connect to a database +class MySQLConnection(object): + def __init__(self, app, db): + config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'root', + 'port': '3306' # change the port to match the port your SQL server is running on + } + # this will use the above values to generate the path to connect to your sql database + DATABASE_URI = "mysql://{}:{}@127.0.0.1:{}/{}".format(config['user'], config['password'], config['port'], config['database']) + app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True + # establish the connection to database + self.db = SQLAlchemy(app) + # this is the method we will use to query the database + def query_db(self, query, data=None): + result = self.db.session.execute(text(query), data) + if query[0:6].lower() == 'select': + # if the query was a select + # convert the result to a list of dictionaries + list_result = [dict(r) for r in result] + # return the results as a list of dictionaries + return list_result + elif query[0:6].lower() == 'insert': + # if the query was an insert, return the id of the + # commit changes + self.db.session.commit() + # row that was inserted + return result.lastrowid + else: + # if the query was an update or delete, return nothing and commit changes + self.db.session.commit() +# This is the module method to be called by the user in server.py. Make sure to provide the db name! +def MySQLConnector(app, db): + return MySQLConnection(app, db) diff --git a/richardN/sqlFlask/wall/server.py b/richardN/sqlFlask/wall/server.py new file mode 100644 index 0000000..f928e5c --- /dev/null +++ b/richardN/sqlFlask/wall/server.py @@ -0,0 +1,124 @@ +from flask import Flask, flash, redirect, render_template, request, session +from mysqlconnection import MySQLConnector +import re + +EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') +app = Flask(__name__) +app.secret_key = "imBuildingThisWallForMeNotTRUMP!" + +mysql = MySQLConnector(app, "wall") + +@app.route('/', methods=['GET']) +def index(): + return render_template('root.html') + if id not in session: + session["id"] = id + +@app.route('/register', methods=['POST']) +def register(): + error = True + newUser = { + 'email': request.form['email'], + 'password': request.form['password'], + 'cPassword': request.form['cPassword'], + 'first_name': request.form['first_name'], + 'last_name': request.form['last_name'] + } + email = request.form['email'] + password = request.form['password'] + cPassword = request.form['cPassword'] + first_name = request.form['first_name'] + last_name = request.form['last_name'] + + if first_name < 0: + flash("First name field empty") + error = False + if last_name < 0: + flash("Last name field empty") + error = False + if len(email) < 0 or len(password) < 0 or len(cPassword) < 0: + flash("email and password is missing") + elif len(password) < 8: + flash("password not long enough") + error = False + elif password != cPassword: + flash("passwords don't match") + error = False + elif EMAIL_REGEX.match(email): + flash("Email not valid") + error = False + if error: + query = "SELECT email FROM users WHERE email = :email" + emails = mysql.query_db(query,{'email':email}) + if emails: + flash("email not available") + else: + query = "INSERT INTO users(first_name, last_name, email, password, created_at, updated_at) VALUES (:first_name, :last_name, :email, :password, NOW(), NOW())" + session ['user_id'] = mysql.query_db(Users) + print session["user_id"] + print "You're registered" + return redirect('/wall') + return redirect ('/') + +@app.route('/login', methods = ['POST']) +def login(): + error = True + newUser = { + 'user_email': request.form['user_email'], + 'user_password': request.form['user_password'] + } + if request.form['user_email'] < 0: + error = False + flash("Invalid Email") + if request.form['user_password'] < 0: + error = False + flash("Invalid Password") + if error: + query = "SELECT * FROM users WHERE email = :email" + users = mysql.query_db(query, {'email':request.form['user_email']}) + if len(users) > 0: + user = users[0] + session['user_id'] = user['id'] + return redirect('/wall') + else: + flash("Login failed") + return redirect ('/') + else: + flash("User not found") + return redirect ('/') + +@app.route('/logoff') +def logoff(): + session.pop ('user_id') + return redirect ('/') + +@app.route('/wall') +def wall(): + if 'user_id' not in session: + return redirect ('/') + query = "SELECT messages.id, messages.message, users.first_name, messages.created_at FROM messages JOIN users ON users.id= messages.users_id ORDER BY messages.created_at DESC" + mysql.query_db(query) + return render_template('wall.html') + +@app.route('/messages', methods=["POST"]) +def newMessage(): + message = request.form['message'] + if message =="": + return redirect('/wall') + query = "INSERT INTO messages (message, user_id, created_at) VALUES (:message, :user_id, NOW())" + data = {'message':message, 'user_id': session['user_id']} + mysql.query_db(query, data) + return redirect('/wall') + +@app.route('/comments', methods=["POST"]) +def newComment(): + message_id = request.form['message_id'] + comment = request.form['comment'] + if comment =="": + return redirect('/wall') + query = "INSERT INTO comments (comment, created_at, message_id, user_id) VALUES (:comment, NOW(), :message_id, :user_id)" + data = {'comment':comment, 'message_id':message_id, 'user_id': session['user_id']} + mysql.query_db(query, data) + return redirect('/wall') + +app.run(debug=True) \ No newline at end of file diff --git a/richardN/sqlFlask/wall/static/style.css b/richardN/sqlFlask/wall/static/style.css new file mode 100644 index 0000000..e69de29 diff --git a/richardN/sqlFlask/wall/templates/root.html b/richardN/sqlFlask/wall/templates/root.html new file mode 100644 index 0000000..c60f9d6 --- /dev/null +++ b/richardN/sqlFlask/wall/templates/root.html @@ -0,0 +1,84 @@ + + + + + + + + + + + Login and Registration + + + + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} +

{{message}}

+ {% endfor %} + {% endif %} + {% endwith %} +

Register!

+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+ +
+

Login!

+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ + + \ No newline at end of file diff --git a/richardN/sqlFlask/wall/templates/wall.html b/richardN/sqlFlask/wall/templates/wall.html new file mode 100644 index 0000000..0755777 --- /dev/null +++ b/richardN/sqlFlask/wall/templates/wall.html @@ -0,0 +1,50 @@ + + + + + + Wall + + + + +
+

Post a message

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

{{message.user}}-{{message.created_at}}{{message.message}}

+ + {% for comment in comments %} + {% if comment.message_id == message.id %} +

{{comment.user}}-{{comment.created_at}}{{comment.comment}}

+ {% endif %} + {% endfor %} +

Post a comment

+
+
+ +
+ + +
+
+
+ {% endfor %} + + + + \ No newline at end of file diff --git a/richardN/sqlFlask/wall/wall.mwb b/richardN/sqlFlask/wall/wall.mwb new file mode 100644 index 0000000..d9fce40 Binary files /dev/null and b/richardN/sqlFlask/wall/wall.mwb differ