Explorar el Código

more database tables and creating of projects. Bug encountered, sleep on it

https
jakobsn hace 6 años
padre
commit
bd6504646a
Se han modificado 13 ficheros con 241 adiciones y 19 borrados
  1. +1
    -0
      .gitignore
  2. +134
    -11
      mysql/sql/init.sql
  3. +1
    -1
      src/app/models/database.py
  4. +23
    -0
      src/app/models/project.py
  5. +6
    -3
      src/app/models/register.py
  6. +20
    -0
      src/app/templates/project.html
  7. +2
    -2
      src/app/templates/register.html
  8. +20
    -0
      src/app/views/forms.py
  9. +2
    -0
      src/app/views/index.py
  10. +2
    -1
      src/app/views/login.py
  11. +26
    -0
      src/app/views/project.py
  12. +3
    -1
      src/app/views/register.py
  13. +1
    -0
      src/app/views/utils.py

+ 1
- 0
.gitignore Ver fichero

@@ -1 +1,2 @@
__pycache__
src/app/sessions/

+ 134
- 11
mysql/sql/init.sql Ver fichero

@@ -1,20 +1,143 @@

CREATE TABLE `db`.`users` (
`userid` INT AUTO_INCREMENT,
`username` VARCHAR(45) NULL,
`password` VARCHAR(45) NULL,
PRIMARY KEY (`userid`)
CREATE TABLE users (
userid INT UNSIGNED AUTO_INCREMENT,
username VARCHAR(45) UNIQUE NOT NULL,
password VARCHAR(45) NOT NULL,
full_name VARCHAR(200) NOT NULL,
company VARCHAR(50),
phone_number VARCHAR(50),
street_address VARCHAR(50),
city VARCHAR(50),
state VARCHAR(50),
postal_code VARCHAR(50),
country VARCHAR(50),
PRIMARY KEY (userid)
);
CREATE TABLE `db`.`guestbook` (
`entryid` INT AUTO_INCREMENT,
`text` VARCHAR(255) NULL,
PRIMARY KEY (`entryid`)

CREATE TABLE guestbook (
entryid INT UNSIGNED AUTO_INCREMENT,
text VARCHAR(255) NOT NULL,
PRIMARY KEY (entryid)
);

/*
* Project tables
*/

CREATE TABLE teams (
teamid INT UNSIGNED AUTO_INCREMENT,
team_name VARCHAR(200) NOT NULL,
write_permission BOOLEAN,
PRIMARY KEY (teamid)
);

insert into users values (NULL, "admin", "password");
insert into users values (NULL, "bernt", "inge");
CREATE TABLE teams_users (
teamid INT UNSIGNED NOT NULL,
userid INT UNSIGNED NOT NULL,
PRIMARY KEY (teamid, userid),
FOREIGN KEY (teamid) REFERENCES teams(teamid),
FOREIGN KEY (userid) REFERENCES users(userid)
);

CREATE TABLE project_category (
categoryid INT UNSIGNED AUTO_INCREMENT,
category_name VARCHAR(200) UNIQUE NOT NULL,
PRIMARY KEY (categoryid)
);

CREATE TABLE users_categories (
userid INT UNSIGNED NOT NULL,
categoryid INT UNSIGNED NOT NULL,
PRIMARY KEY (userid, categoryid),
FOREIGN KEY (userid) REFERENCES users(userid),
FOREIGN KEY (categoryid) REFERENCES project_category(categoryid)
);

CREATE TABLE projects (
projectid INT UNSIGNED AUTO_INCREMENT,
categoryid INT UNSIGNED NOT NULL,
userid INT UNSIGNED NOT NULL,
title VARCHAR(200) NOT NULL,
project_description VARCHAR(500) NOT NULL,
project_status VARCHAR(16) NOT NULL, -- This should be either open, in progress or finished
PRIMARY KEY (projectid),
FOREIGN KEY (categoryid) REFERENCES project_category(categoryid),
FOREIGN KEY (userid) REFERENCES users(userid)
);

CREATE TABLE projects_users (
projectid INT UNSIGNED NOT NULL,
userid INT UNSIGNED NOT NULL,
read_permission BOOLEAN,
write_permission BOOLEAN,
modify_permission BOOLEAN,
PRIMARY KEY (projectid, userid),
FOREIGN KEY (projectid) REFERENCES projects(projectid),
FOREIGN KEY (userid) REFERENCES users(userid)
);

CREATE TABLE tasks (
taskid INT UNSIGNED AUTO_INCREMENT,
projectid INT NOT NULL,
teamid INT UNSIGNED NOT NULL,
title VARCHAR(200) NOT NULL,
task_description VARCHAR(500),
budget INT,
task_status VARCHAR(64), -- This should be Waiting for delivery, Delivered and waiting for acceptance, Delivery has been accepted, awaiting payment, Payment for delivery is done or Declined delivery, please revise
feedback VARCHAR(500),
PRIMARY KEY (taskid),
FOREIGN KEY (teamid) REFERENCES teams(teamid)
);

CREATE TABLE task_files (
fileid INT NOT NULL AUTO_INCREMENT,
taskid INT UNSIGNED NOT NULL,
filename VARCHAR(45) NOT NULL,
PRIMARY KEY (fileid),
FOREIGN KEY (taskid) REFERENCES tasks(taskid)
);

CREATE TABLE delivery (
deliveryid INT UNSIGNED AUTO_INCREMENT,
taskid INT UNSIGNED NOT NULL,
userid INT UNSIGNED NOT NULL,
filename VARCHAR(45) NOT NULL,
comment VARCHAR(500),
delivery_time DATETIME DEFAULT CURRENT_TIMESTAMP,
responding_userid INT NOT NULL,
responding_time DATETIME,
delivery_status VARCHAR(16), -- Should be Accepted, Pending or Declined
feedback VARCHAR(500),
PRIMARY KEY (deliveryid),
FOREIGN KEY (taskid) REFERENCES tasks(taskid),
FOREIGN KEY (userid) REFERENCES users(userid)
);

CREATE TABLE task_offer (
offerid INT UNSIGNED AUTO_INCREMENT,
taskid INT UNSIGNED NOT NULL,
title VARCHAR(200) NOT NULL,
price INT,
description VARCHAR(500),
offer_status VARCHAR(16), -- Should be Accepted, Pending or Declined
feedback VARCHAR(500),
PRIMARY KEY (offerid),
FOREIGN KEY (taskid) REFERENCES tasks(taskid)
);

/*
* Initial data
*/

insert into users values (NULL, "admin", "password", "Admin Modsen", "ntnu", "12345678", "street", "trondheim", "trondheim", "1234", "norway");

insert into guestbook values (NULL, "Hello World");

insert into project_category values (NULL, "Test");

/*
Create default database user
*/

CREATE USER 'root'@'10.5.0.6' IDENTIFIED BY 'root';
GRANT ALL PRIVILEGES ON db.* TO 'root'@'10.5.0.6';

+ 1
- 1
src/app/models/database.py Ver fichero

@@ -3,6 +3,6 @@ import mysql.connector
db = mysql.connector.connect(
user='root',
password='root',
host='0.0.0.0',
host='10.5.0.5',
database='db'
)

+ 23
- 0
src/app/models/project.py Ver fichero

@@ -0,0 +1,23 @@
from models.database import db

def get_categories():
cursor = db.cursor()
query = ("SELECT * FROM project_category")
cursor.execute(query)
categories = cursor.fetchall()
cursor.close()
return 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)
cursor.execute(query)
cursor.close()
categories = get_categories()
print(categories)
return categories

+ 6
- 3
src/app/models/register.py Ver fichero

@@ -1,8 +1,11 @@
from models.database import db

def set_user(username, password):
def set_user(username, password, full_name, company, phone_number,
street_address, city, state, postal_code, country):
cursor = db.cursor()
query = ("INSERT INTO users VALUES (NULL, \"" + username +
"\", \"" + password + "\")")
query = ("INSERT INTO users VALUES (NULL, \"" + username + "\", \"" +
password + "\", \"" + full_name + "\" , \"" + company + "\", \"" +
phone_number + "\", \"" + street_address + "\", \"" + city + "\", \"" +
state + "\", \"" + postal_code + "\", \"" + country + "\")")
cursor.execute(query)
cursor.close()

+ 20
- 0
src/app/templates/project.html Ver fichero

@@ -0,0 +1,20 @@
$def with (nav, project_form)

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

</head>

<body>

$:nav

<h2>Add project!</h2>
<form method="POST">
$:project_form.render()
</form>
</body>

<footer></footer>

+ 2
- 2
src/app/templates/register.html Ver fichero

@@ -1,7 +1,7 @@
$def with (nav, register_form)

<head>
<title>Friends</title>
<title>Beelance2</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="static/stylesheet.css">

@@ -11,7 +11,7 @@ $def with (nav, register_form)

$:nav

<h2>Become a friend!</h2>
<h2>Register user!</h2>
<form method="POST">
$:register_form.render()
</form>


+ 20
- 0
src/app/views/forms.py Ver fichero

@@ -1,4 +1,5 @@
from web import form
from models.project import get_categories

# Define the login form
login_form = form.Form(
@@ -10,10 +11,29 @@ login_form = form.Form(
# Define the register form
register_form = form.Form(
form.Textbox("username", description="Username"),
form.Textbox("full_name", description="Full name"),
form.Textbox("company", description="Company"),
form.Textbox("phone_number", description="Phone Number"),
form.Textbox("street_address", description="Street address"),
form.Textbox("city", description="City"),
form.Textbox("state", description="State"),
form.Textbox("postal_code", description="Postal code"),
form.Textbox("country", description="Country"),
form.Password("password", description="Password"),
form.Button("Register", type="submit", description="Register"),
)

# Define the project form

categories = get_categories()

project_form = form.Form(
form.Textbox("project_title", description="Title"),
form.Textbox("project_description", description="Description"),
form.Dropdown("category_name", args=categories),
form.Button("Submit", type="submit", description="submit")
)

# Define the guestbook form
guestbook_form = form.Form(
form.Textbox("entry", description="Entry"),


+ 2
- 0
src/app/views/index.py Ver fichero

@@ -5,6 +5,7 @@ from views.login import Login
from views.logout import Logout
from views.register import Register
from views.admin import Admin
from views.project import Project

# Define application routes
urls = (
@@ -13,6 +14,7 @@ urls = (
'/logout', 'Logout',
'/register', 'Register',
'/guestbook', 'Guestbook',
'/project', 'Project',
'/admin', 'Admin',
)


+ 2
- 1
src/app/views/login.py Ver fichero

@@ -27,7 +27,8 @@ class Login():
# If there is a matching user/password in the database the user is logged in
if len(user):
friends = models.login.get_users()
session.username = data.username
session.username = user[0][1]
session.userid = user[0][0]
else:
friends = [[],[]]
nav = get_nav_bar(session)


+ 26
- 0
src/app/views/project.py Ver fichero

@@ -0,0 +1,26 @@
import web
from views.forms import project_form
import models.project
from views.utils import get_nav_bar

# Get html templates
render = web.template.render('templates/')

class Project:

# Get the registration form
def GET(self):
session = web.ctx.session
nav = get_nav_bar(session)
return render.project(nav, project_form)

# Register new user in database
def POST(self):
data = web.input()
session = web.ctx.session
print(data)
print(session.userid)
categories = models.project.set_project(data.category_name, str(session.userid),
data.project_title, data.project_description, "open")
print(categories)
raise web.seeother('/')

+ 3
- 1
src/app/views/register.py Ver fichero

@@ -18,6 +18,8 @@ class Register:
# Register new user in database
def POST(self):
data = web.input()
models.register.set_user(data.username, data.password)
models.register.set_user(data.username, data.password,
data.full_name, data.company, data.phone_number, data.street_address,
data.city, data.state, data.postal_code, data.country)
raise web.seeother('/')


+ 1
- 0
src/app/views/utils.py Ver fichero

@@ -9,6 +9,7 @@ def get_nav_bar(session):
else:
result += ' <li><a href="register">Register</a></li>'
result += ' <li><a href="login">Login</a></li>'
result += ' <li><a href="project">Projects</a></li>'
result += ' <li><a href="guestbook">Guestbook</a></li>'
result += ' </ul>'
result += '</nav>'


Cargando…
Cancelar
Guardar