Compare commits

...

4 Commits

Author SHA1 Message Date
d81ff0592e
add project page 2024-01-16 13:44:51 +01:00
52866f9c84
fix init_db file and run.py 2024-01-16 13:28:11 +01:00
d9a73a6fd9
change more filenames and strings to say taskmanager instead of flaskapp 2024-01-16 13:24:45 +01:00
7aa57af9ef
add register html 2024-01-15 20:37:45 +01:00
11 changed files with 109 additions and 39 deletions

4
.gitignore vendored
View File

@ -24,11 +24,11 @@ dist/
downloads/
eggs/
.eggs/
lib/
#lib/
lib64/
parts/
sdist/
var/
#var/
wheels/
pip-wheel-metadata/
share/python-wheels/

View File

@ -219,7 +219,7 @@ If you develop a new program, and you want it to be of the greatest possible use
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
flaskapp
taskmanager
Copyright (C) 2023 Decentrala
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

View File

@ -1,4 +1,3 @@
# flaskapp
Web app
# taskmanager
Interactive TODO list web application

View File

@ -0,0 +1,12 @@
[Unit]
Description=Gunicorn taskmanager service
Documentation=man:gunicorn(1)
After=network.target nss-lookup.target
[Service]
WorkingDirectory=/var/taskmanager/
ExecStart=/usr/bin/gunicorn --workers 3 --bind 127.0.0.1:5000 run:app
[Install]
WantedBy=multi-user.target

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python3
from flaskapp import db
from taskmanager import db, app
print('[i] Trying to create databse...')
try:
db.create_all()
with app.app_context():
db.create_all()
print('[+] Success you can proceed with deployment!')
except:
print('[-] Creating db failed :/')

3
run.py
View File

@ -1,4 +1,5 @@
from flaskapp import app
#!/usr/bin/env python3
from taskmanager import app
if __name__ == '__main__':
app.run(debug=False)

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

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