From 4859f1bf746b1b9525db7f156bab9ade987b98bf Mon Sep 17 00:00:00 2001 From: jakobsn Date: Tue, 5 Nov 2019 13:56:27 +0100 Subject: [PATCH] show categories and projects --- README.md | 24 ++++++++++++++++++++++-- src/app/models/database.py | 3 ++- src/app/models/guestbook.py | 1 + src/app/models/project.py | 19 ++++++++++++------- src/app/models/register.py | 1 + src/app/static/stylesheet.css | 22 ++++++++++++++++++++++ src/app/templates/guestbook.html | 1 + src/app/templates/index.html | 16 ++++++++++++++-- src/app/templates/login.html | 3 ++- src/app/templates/project.html | 1 + src/app/templates/register.html | 1 + src/app/views/index.py | 8 +++++++- 12 files changed, 86 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 756f5a1..36a67f0 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,25 @@ webpy framework: http://webpy.org/ ### prerequisites: docker https://www.docker.com/ -### Run -docker-compose up +### Build & Run +$ docker-compose up --build + +### Prune/Recreate +If you need a fresh rebuild in case of startup issues use this command (WARNING this will remove all your docker images) +$ docker system prune -a +$ docker-compose up --build + +### Deploy locally + +Install: +mysql +src/app/requirements.txt + +Run: +Launch mysql at port 3306 +Execute mysql queries +"CREATE database db;" +"USE db;" +Populate mysql by posting mysql/sql/init.sql into mysql +Edit src/app/models/database.py to point at local server +python3 src/app/main.py diff --git a/src/app/models/database.py b/src/app/models/database.py index 11bbd81..f1de688 100644 --- a/src/app/models/database.py +++ b/src/app/models/database.py @@ -3,6 +3,7 @@ import mysql.connector db = mysql.connector.connect( user='root', password='root', - host='10.5.0.5', + #host='10.5.0.5', # Docker address + host='0.0.0.0', # Local address database='db' ) diff --git a/src/app/models/guestbook.py b/src/app/models/guestbook.py index 076cf98..d987615 100644 --- a/src/app/models/guestbook.py +++ b/src/app/models/guestbook.py @@ -12,6 +12,7 @@ def set_guestbook_entry(entry): cursor = db.cursor() query = ("INSERT INTO guestbook VALUES (NULL, \"" + entry + "\")") cursor.execute(query) + db.commit() cursor.close() diff --git a/src/app/models/project.py b/src/app/models/project.py index f75a217..50a67bc 100644 --- a/src/app/models/project.py +++ b/src/app/models/project.py @@ -10,14 +10,19 @@ def get_categories(): def set_project(categoryid, userid, title, project_description, project_status): cursor = db.cursor() - query = ("INSERT INTO projects values (NULL, \"1\", \"1\", \"sad\", \"desdf\", \"open\")") - #("INSERT INTO projects values (NULL, \"" + - #categoryid + "\", \"" + userid + "\", \"" + title + "\", \"" + - #project_description + "\", \"" + project_status + "\")") - print(query) + query = ("INSERT INTO projects VALUES (NULL, \"" + + categoryid + "\", \"" + userid + "\", \"" + title + "\", \"" + + project_description + "\", \"" + project_status + "\")") cursor.execute(query) + db.commit() cursor.close() categories = get_categories() - print(categories) return categories - + +def get_projects_by_status_and_category(categoryid, project_status): + cursor = db.cursor() + query = ("SELECT * FROM projects WHERE project_status = \"" + + project_status + "\" AND categoryid = \"" + categoryid + "\"") + cursor.execute(query) + projects = cursor.fetchall() + return projects diff --git a/src/app/models/register.py b/src/app/models/register.py index af5172e..8ffeefd 100644 --- a/src/app/models/register.py +++ b/src/app/models/register.py @@ -8,4 +8,5 @@ def set_user(username, password, full_name, company, phone_number, phone_number + "\", \"" + street_address + "\", \"" + city + "\", \"" + state + "\", \"" + postal_code + "\", \"" + country + "\")") cursor.execute(query) + db.commit() cursor.close() diff --git a/src/app/static/stylesheet.css b/src/app/static/stylesheet.css index 692858e..4bff02b 100644 --- a/src/app/static/stylesheet.css +++ b/src/app/static/stylesheet.css @@ -5,6 +5,28 @@ body { margin: 0; } +.title { + margin: auto; +} + +.categories { + display: flex; /* or inline-flex */ + flex-direction: row; +} + +.category { + margin: auto; +} + +.projects { + display: flex; /* or inline-flex */ + flex-direction: row; +} + +.projects * { + margin: auto; +} + h1 { margin: auto; } diff --git a/src/app/templates/guestbook.html b/src/app/templates/guestbook.html index 09747d0..1914e43 100644 --- a/src/app/templates/guestbook.html +++ b/src/app/templates/guestbook.html @@ -4,6 +4,7 @@ $def with (nav, entries, guestbook_form) Friends + diff --git a/src/app/templates/index.html b/src/app/templates/index.html index 0a11129..ffc65bd 100644 --- a/src/app/templates/index.html +++ b/src/app/templates/index.html @@ -1,15 +1,27 @@ -$def with (nav) +$def with (nav, categories, projects) + Beelance2 - + $:nav +

Open Projects:

+ +
+ $for category in categories: +
$category[1]
+
+ +
+ $for project in projects: +

$project[3]

$project[4]

+
Honeybee diff --git a/src/app/templates/login.html b/src/app/templates/login.html index 8f369e5..595edc2 100644 --- a/src/app/templates/login.html +++ b/src/app/templates/login.html @@ -4,6 +4,7 @@ $def with (nav, login_form, friends) Beelance2 + @@ -22,7 +23,7 @@ $def with (nav, login_form, friends)

Registered friends:

\ No newline at end of file diff --git a/src/app/templates/project.html b/src/app/templates/project.html index 8682a59..f827652 100644 --- a/src/app/templates/project.html +++ b/src/app/templates/project.html @@ -4,6 +4,7 @@ $def with (nav, project_form) Beelance2 + diff --git a/src/app/templates/register.html b/src/app/templates/register.html index 5b66eea..ba1a49d 100644 --- a/src/app/templates/register.html +++ b/src/app/templates/register.html @@ -4,6 +4,7 @@ $def with (nav, register_form) Beelance2 + diff --git a/src/app/views/index.py b/src/app/views/index.py index d665de5..7b48187 100644 --- a/src/app/views/index.py +++ b/src/app/views/index.py @@ -6,6 +6,7 @@ from views.logout import Logout from views.register import Register from views.admin import Admin from views.project import Project +from models.project import get_categories, get_projects_by_status_and_category # Define application routes urls = ( @@ -45,5 +46,10 @@ class Index: # Get main page def GET(self): + data = web.input(categoryid=0) + projects=[] + if data.categoryid != 0: + projects = get_projects_by_status_and_category(data.categoryid, "open") nav = get_nav_bar(session) - return render.index(nav) + categories = get_categories() + return render.index(nav, categories, projects)