| @@ -9,5 +9,25 @@ webpy framework: http://webpy.org/ | |||||
| ### prerequisites: | ### prerequisites: | ||||
| docker https://www.docker.com/ | 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 | |||||
| @@ -3,6 +3,7 @@ import mysql.connector | |||||
| db = mysql.connector.connect( | db = mysql.connector.connect( | ||||
| user='root', | user='root', | ||||
| password='root', | password='root', | ||||
| host='10.5.0.5', | |||||
| #host='10.5.0.5', # Docker address | |||||
| host='0.0.0.0', # Local address | |||||
| database='db' | database='db' | ||||
| ) | ) | ||||
| @@ -12,6 +12,7 @@ def set_guestbook_entry(entry): | |||||
| cursor = db.cursor() | cursor = db.cursor() | ||||
| query = ("INSERT INTO guestbook VALUES (NULL, \"" + entry + "\")") | query = ("INSERT INTO guestbook VALUES (NULL, \"" + entry + "\")") | ||||
| cursor.execute(query) | cursor.execute(query) | ||||
| db.commit() | |||||
| cursor.close() | cursor.close() | ||||
| @@ -10,14 +10,19 @@ def get_categories(): | |||||
| def set_project(categoryid, userid, title, project_description, project_status): | def set_project(categoryid, userid, title, project_description, project_status): | ||||
| cursor = db.cursor() | 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) | cursor.execute(query) | ||||
| db.commit() | |||||
| cursor.close() | cursor.close() | ||||
| categories = get_categories() | categories = get_categories() | ||||
| print(categories) | |||||
| return 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 | |||||
| @@ -8,4 +8,5 @@ def set_user(username, password, full_name, company, phone_number, | |||||
| phone_number + "\", \"" + street_address + "\", \"" + city + "\", \"" + | phone_number + "\", \"" + street_address + "\", \"" + city + "\", \"" + | ||||
| state + "\", \"" + postal_code + "\", \"" + country + "\")") | state + "\", \"" + postal_code + "\", \"" + country + "\")") | ||||
| cursor.execute(query) | cursor.execute(query) | ||||
| db.commit() | |||||
| cursor.close() | cursor.close() | ||||
| @@ -5,6 +5,28 @@ body { | |||||
| margin: 0; | 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 { | h1 { | ||||
| margin: auto; | margin: auto; | ||||
| } | } | ||||
| @@ -4,6 +4,7 @@ $def with (nav, entries, guestbook_form) | |||||
| <title>Friends</title> | <title>Friends</title> | ||||
| <meta charset="utf-8"> | <meta charset="utf-8"> | ||||
| <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | ||||
| <link rel="shortcut icon" type="image/png" href="static/honeybee.png"/> | |||||
| </head> | </head> | ||||
| @@ -1,15 +1,27 @@ | |||||
| $def with (nav) | |||||
| $def with (nav, categories, projects) | |||||
| <head> | <head> | ||||
| <title>Beelance2</title> | <title>Beelance2</title> | ||||
| <meta charset="utf-8"> | <meta charset="utf-8"> | ||||
| <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | ||||
| <link rel="shortcut icon" type="image/png" href="static/honeybee.png"/> | |||||
| </head> | </head> | ||||
| <body> | <body> | ||||
| $:nav | $:nav | ||||
| <h1 class="title">Open Projects:</h1> | |||||
| <div id="categories"> | |||||
| $for category in categories: | |||||
| <div class="category" onclick="location.href='/?categoryid=$category[0]'">$category[1]</div> | |||||
| </div> | |||||
| <div class="projects"> | |||||
| $for project in projects: | |||||
| <div class="project"><h4>$project[3]</h4><p>$project[4]</p></div> | |||||
| </div> | |||||
| <img src="static/honeybee.png" alt="Honeybee"> | <img src="static/honeybee.png" alt="Honeybee"> | ||||
| @@ -4,6 +4,7 @@ $def with (nav, login_form, friends) | |||||
| <title>Beelance2</title> | <title>Beelance2</title> | ||||
| <meta charset="utf-8"> | <meta charset="utf-8"> | ||||
| <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | ||||
| <link rel="shortcut icon" type="image/png" href="static/honeybee.png"/> | |||||
| </head> | </head> | ||||
| @@ -22,7 +23,7 @@ $def with (nav, login_form, friends) | |||||
| <h3>Registered friends:</h3> | <h3>Registered friends:</h3> | ||||
| <ul> | <ul> | ||||
| $for user in friends: | $for user in friends: | ||||
| <li id="user[0]">$user[1]</li> | |||||
| <li id="$user[0]">$user[1]</li> | |||||
| </ul> | </ul> | ||||
| </body> | </body> | ||||
| @@ -4,6 +4,7 @@ $def with (nav, project_form) | |||||
| <title>Beelance2</title> | <title>Beelance2</title> | ||||
| <meta charset="utf-8"> | <meta charset="utf-8"> | ||||
| <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | ||||
| <link rel="shortcut icon" type="image/png" href="static/honeybee.png"/> | |||||
| </head> | </head> | ||||
| @@ -4,6 +4,7 @@ $def with (nav, register_form) | |||||
| <title>Beelance2</title> | <title>Beelance2</title> | ||||
| <meta charset="utf-8"> | <meta charset="utf-8"> | ||||
| <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | ||||
| <link rel="shortcut icon" type="image/png" href="static/honeybee.png"/> | |||||
| </head> | </head> | ||||
| @@ -6,6 +6,7 @@ from views.logout import Logout | |||||
| from views.register import Register | from views.register import Register | ||||
| from views.admin import Admin | from views.admin import Admin | ||||
| from views.project import Project | from views.project import Project | ||||
| from models.project import get_categories, get_projects_by_status_and_category | |||||
| # Define application routes | # Define application routes | ||||
| urls = ( | urls = ( | ||||
| @@ -45,5 +46,10 @@ class Index: | |||||
| # Get main page | # Get main page | ||||
| def GET(self): | 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) | nav = get_nav_bar(session) | ||||
| return render.index(nav) | |||||
| categories = get_categories() | |||||
| return render.index(nav, categories, projects) | |||||