You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.3 KiB
Python

# WORKINON
# A small and shared archive to keep track of how ideas change during work, research and development
# A call to share what we are doing with others, while we are doing it.
# In a way that doesn't focus on results, but on process and sharing.
# How does it work
# The core of Workinon is a small API that read and write updates to a JSON file.
# The inputs can be received through a form from the application page.
# Structure of the JSON:
# a list of projects, and each update has a codename and a list of steps
# (since this is a first prototype this could change anytime)
# (it's already changed 3 times while writing this initial documentation ah ah)
# {
# 'Workin title of the project or idea': [
# {'13.05.2022', 'First idea of the project'},
# {'14.05.2022', 'Second thoughts'},
# {'15.05.2022', 'Something new and now everything makes sense'}
# ]
# }
# To insert a new project just send in the first step and a name
# to update with a new step just refer to the name you used the first time and add the new step
# this structure is not super robust.
# if two different project use the same codename, this could lead to interferences between the two
# so one suggestion for the usage of the Workinon could be to choose a really really really personal title
import os
import json
from glob import glob
from flask import Flask, render_template, request, redirect, url_for
import datetime
# prefix to add /SOUPBOAT/ATLAS-API to all the routes
# and to leave the @app.route() decorator more clean
class PrefixMiddleware(object):
def __init__(self, app, prefix=""):
self.app = app
self.prefix = prefix
def __call__(self, environ, start_response):
if environ["PATH_INFO"].startswith(self.prefix):
environ["PATH_INFO"] = environ["PATH_INFO"][len(self.prefix):]
environ["SCRIPT_NAME"] = self.prefix
return self.app(environ, start_response)
else:
start_response("404", [("Content-Type", "text/plain")])
return ["This url does not belong to the app.".encode()]
base_url = '/soupboat/workinon'
# create flask application
app = Flask(__name__)
# register the middleware to prefix all the requests with our base_url
app.wsgi_app = PrefixMiddleware(
app.wsgi_app, prefix=base_url
)
# definition of the routes
@app.route('/')
def home():
with open('archive.json', 'r') as f:
projects = json.load(f)
return render_template('home.html', projects=projects)
@app.route('/add', methods=['GET', 'POST'])
def add():
if request.method == 'POST':
name = request.form.get('name')
update = request.form.get('update')
if name != '' and update != '':
with open('archive.json', 'r') as f:
projects = json.load(f)
date = datetime.date.today().strftime('%d.%m.%Y')
step = {'when': date, 'what': update}
if name in projects:
projects[name].append(step)
else:
projects[name] = [step]
with open('archive.json', 'w') as f:
f.write(json.dumps(projects))
return redirect(url_for('home'))
return render_template('add.html')
app.run(port=3144)