add project page

This commit is contained in:
fram3d 2024-01-16 13:44:51 +01:00
parent 52866f9c84
commit d81ff0592e
Signed by: fram3d
GPG Key ID: 938920E709EEA32A
4 changed files with 67 additions and 30 deletions

View File

@ -8,20 +8,48 @@ def index():
tasks = Task.query.all()
return render_template('index.html', tasks = tasks)
@app.route('/submit', methods=['POST', 'GET'])
def submit():
@app.route('/register', methods=['POST', 'GET'])
def register():
if request.method == 'GET':
return render_template('submit.html')
return render_template('register.html')
elif request.method == 'POST':
userinput1 = request.form['forminput1']
userinput2 = request.form['forminput2']
sqlrow = Table(variable1 = int(userinput1), variable2 = int(userinput2))
username = request.form['username']
contact = request.form['contact']
sqladduser = User(username = username, contact = contact)
try:
db.session.add(sqlrow)
db.session.add(sqladduser)
db.session.commit()
return 'Row added'
return 'User added'
except:
return 'Adding row to table failed'
return 'Adding user failed'
else:
return 'HTTP request method not recogniezed'
@app.route('/projects/<int:task_id>', methods=['GET','POST'])
def project(task_id:int):
if request.method == 'GET':
try:
task = Task.query.get(task_id)
except:
return 'Task not found, bad URL'
try:
userid = TaskUser.query.filter_by(taskid = task_id).first().userid
users = User.query.get(userid).username
except:
users = "No users added to this task"
return render_template("project.html", task = task, users = users)
elif request.method == 'POST':
username = request.form['username']
try:
userid = User.query.filter_by(username = username).first().id
except:
return 'User not found, please <a href="/register">register</a>.'
sqladduser = TaskUser(userid = userid, taskid = task_id)
try:
db.session.add(sqladduser)
db.session.commit()
return 'User added'
except:
return 'Adding user failed'

View File

@ -12,7 +12,7 @@
<main>
<section>
{% for task in tasks %}
<li>{{task}}</li>
<li><a href="/projects/{{task.id}}"> {{task.name}} </a></li>
{% endfor %}
</section>
</main>

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Decentrala</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<header>
</header>
<main>
<section>
<li>{{task.name}}</li>
<li>{{task.desc}}</li>
<li>{{users}}</li>
</section>
<h1> Add yourself to task </h1>
<form action="/projects/{{task.id}}" method="POST">
<label for="username">username</label>
<input type="text" name="username" id="username" required>
<button> Submit </button>
</form>
</main>
<footer>
</footer>
</body>
</html>

View File

@ -1,20 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Submit</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<main>
<form action="/submit" method="POST">
<label for="forminput1">forminput1</label>
<input type="text" name="forminput1" id="forminput1" required>
<label for="forminput2">forminput2</label>
<input type="text" name="forminput2" id="forminput2" required>
<button> Submit </button>
</form>
</main>
</body>
</html>