first try at web editor
parent
c2addd9cbd
commit
41febd1038
@ -0,0 +1,60 @@
|
|||||||
|
# this is a web interface for simple edits to configuration or editing data
|
||||||
|
# for particular bureaus
|
||||||
|
import configparser
|
||||||
|
import os
|
||||||
|
|
||||||
|
from bottle import Bottle, request
|
||||||
|
|
||||||
|
class IhrApp(Bottle):
|
||||||
|
def __init__(self):
|
||||||
|
super(IhrApp, self).__init__()
|
||||||
|
self.name = "IHR App"
|
||||||
|
self.route("/", callback=self.index)
|
||||||
|
self.route("/config/<bureau>", callback=self.config)
|
||||||
|
self.route("/config/<bureau>", callback=self.config, method="POST")
|
||||||
|
self.bureaus = []
|
||||||
|
|
||||||
|
def index(self):
|
||||||
|
# return a list of active bureaus with links
|
||||||
|
# TODO: allow (de)activation of non-essential bureaus
|
||||||
|
out = """
|
||||||
|
<h3>The Screenless Office</h3>
|
||||||
|
<h4><em>Config Manager</em></h4>
|
||||||
|
<ul>
|
||||||
|
"""
|
||||||
|
for bureau in self.bureaus:
|
||||||
|
out += '<li><a href="/config/"' + bureau + '"></li>\n'
|
||||||
|
|
||||||
|
out += "</ul>"
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
|
def config(self, bureau):
|
||||||
|
# parse the config and make it into a form
|
||||||
|
out = "<h3>config file for " + bureau + "</h3>\n"
|
||||||
|
basedir = os.path.expanduser("~/.screenless")
|
||||||
|
if bureau == "mgmt":
|
||||||
|
cfgfile = "mgmt.ini"
|
||||||
|
elif bureau == "printers":
|
||||||
|
cfgfile = printers.cfg
|
||||||
|
else:
|
||||||
|
cfgfile = bureau + ".yml"
|
||||||
|
cfgfile = os.path.join(basedir, cfgfile)
|
||||||
|
if request.method == "POST":
|
||||||
|
#save all the request.forms stuff to the config
|
||||||
|
# tell the bureau to restart / reload
|
||||||
|
# set our message to be "updated config"
|
||||||
|
print("NOT saving updated ", cfgfile)
|
||||||
|
pass
|
||||||
|
#parse and show the config as a form
|
||||||
|
with open(cfgfile) as cfg:
|
||||||
|
out += cfg.read()
|
||||||
|
return out
|
||||||
|
|
||||||
|
def register_bureau(self, bureau):
|
||||||
|
self.bureaus.append(bureau)
|
||||||
|
|
||||||
|
def register_crud(self, data):
|
||||||
|
# adds callbacks for crud operations on a database
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue