瀏覽代碼

show categories and projects

https
jakobsn 6 年之前
父節點
當前提交
4859f1bf74
共有 12 個文件被更改,包括 86 次插入14 次删除
  1. +22
    -2
      README.md
  2. +2
    -1
      src/app/models/database.py
  3. +1
    -0
      src/app/models/guestbook.py
  4. +12
    -7
      src/app/models/project.py
  5. +1
    -0
      src/app/models/register.py
  6. +22
    -0
      src/app/static/stylesheet.css
  7. +1
    -0
      src/app/templates/guestbook.html
  8. +14
    -2
      src/app/templates/index.html
  9. +2
    -1
      src/app/templates/login.html
  10. +1
    -0
      src/app/templates/project.html
  11. +1
    -0
      src/app/templates/register.html
  12. +7
    -1
      src/app/views/index.py

+ 22
- 2
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

+ 2
- 1
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'
)

+ 1
- 0
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()


+ 12
- 7
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

+ 1
- 0
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()

+ 22
- 0
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;
}


+ 1
- 0
src/app/templates/guestbook.html 查看文件

@@ -4,6 +4,7 @@ $def with (nav, entries, guestbook_form)
<title>Friends</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="static/stylesheet.css">
<link rel="shortcut icon" type="image/png" href="static/honeybee.png"/>

</head>



+ 14
- 2
src/app/templates/index.html 查看文件

@@ -1,15 +1,27 @@
$def with (nav)
$def with (nav, categories, projects)

<head>
<title>Beelance2</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="static/stylesheet.css">
<link rel="shortcut icon" type="image/png" href="static/honeybee.png"/>
</head>

<body>

$: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">



+ 2
- 1
src/app/templates/login.html 查看文件

@@ -4,6 +4,7 @@ $def with (nav, login_form, friends)
<title>Beelance2</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="static/stylesheet.css">
<link rel="shortcut icon" type="image/png" href="static/honeybee.png"/>

</head>

@@ -22,7 +23,7 @@ $def with (nav, login_form, friends)
<h3>Registered friends:</h3>
<ul>
$for user in friends:
<li id="user[0]">$user[1]</li>
<li id="$user[0]">$user[1]</li>
</ul>

</body>

+ 1
- 0
src/app/templates/project.html 查看文件

@@ -4,6 +4,7 @@ $def with (nav, project_form)
<title>Beelance2</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="static/stylesheet.css">
<link rel="shortcut icon" type="image/png" href="static/honeybee.png"/>

</head>



+ 1
- 0
src/app/templates/register.html 查看文件

@@ -4,6 +4,7 @@ $def with (nav, register_form)
<title>Beelance2</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="static/stylesheet.css">
<link rel="shortcut icon" type="image/png" href="static/honeybee.png"/>

</head>



+ 7
- 1
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)

Loading…
取消
儲存