## Wiki80 is a semantic information network, designed to be used both ## by carbon- and silicon-based life. ## Copyright (C) 2018 Davis Remmel ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . # This file contains all the routes for our application. This will tell Flask what to display on which path. from flask import render_template, request, redirect from app import app from app import models graph = models.Graph() # This would be a very appropriate place to load the graph from a file # on disk. # The following functions return if they are successful! THIS NEEDS # to have a check!! graph.edit_instance({ '.id': [ 'id_2' ], '.type': [ 'device' ], '.title': [ 'Lenovo X1' ], '.wiki_body': [ '' ], 'serial': [ '1' ], '.link': [ '@id_1' ]}) graph.edit_instance({ '.id': [ 'id_3' ], '.type': [ 'device' ], '.title': [ 'iPhone 5S' ], '.wiki_body': [ 'The iPhone is different than the Newton.' ], 'serial': [ '2' ], '.link': [ '@id_1' ]}) graph.edit_instance({ '.id': [ 'id_1' ], '.type': [ 'person' ], '.title': [ 'Davis Remmel' ], '.wiki_body': [ 'Davis is the creator of wiki80.' ], 'name': [ 'Davis' ], 'age': [ '25' ], '.link': [ '@id_2', '@id_3' ]}) @app.route('/', methods = ['GET']) def index(): return 'hi!'; @app.route('/', methods = ['GET']) def iid(iid=None): instance = graph.get_instance(iid) return render_template('index.html', page_data = instance.page_data(), graph = graph) # Note about the editor: the editor only uses the iid to _load_ the # values into the HTML. The actual editor's '.id' value will be the # determinant of which object gets modified. This means, in effect, it # doesn't matter what //edit endpoint one goes to, because the # editor page itself is really global in scope. #~ @app.route('//edit', #~ methods = ['GET', 'POST']) #~ def edit(iid): #~ # This is the editor page for the object, where a user may assign #~ # or link information. #~ instance = graph.get_instance(iid) #~ if (request.method == 'GET'): #~ return render_template('edit.html', #~ page_data = instance.page_data(), #~ instance = instance) #~ if (request.method == 'POST'): #~ # Update the values with the information posted. Use #~ # request.form['htmlname'] to access them. #~ reassembled = {} #~ keys = request.form.getlist('key[]') #~ values = request.form.getlist('value[]') #~ # Reassemble #~ for i in range(0, len(keys)): #~ key = keys[i] #~ v = values[i].split(', ') #~ if len(key) > 0: #~ reassembled[key] = v #~ # There is no verification that goes on here. There should be! #~ graph.edit_instance(reassembled) #~ return redirect('../' + iid, #~ code = 302)