Mercurial > avadmin > converted
changeset 500:2bd91e74e581
Prefix all system template variables with 'sys_'
2004/01/15 21:25:46-05:00 optonline.net!jeffpc
BODY() class now allows the use of templates
2004/01/10 13:25:02-05:00 optonline.net!jeffpc
Use templates
(Logical change 1.148)
author | optonline.net!jeffpc |
---|---|
date | Fri, 16 Jan 2004 02:46:03 +0000 |
parents | 3f11f8e93035 |
children | cc1ac6c1395e |
files | av_html.py |
diffstat | 1 files changed, 166 insertions(+), 145 deletions(-) [+] |
line wrap: on
line diff
--- a/av_html.py Fri Jan 16 02:46:03 2004 +0000 +++ b/av_html.py Fri Jan 16 02:46:03 2004 +0000 @@ -20,18 +20,52 @@ # * $Id$ # */ +from htmltmpl import TemplateManager + import av_conn import av_log import av_settings import av_message +class BODY: + def __init__(self,template=None,conn=None): + self.init(template,conn) + + def init(self,template=None,conn=None): + self.usetempl = False + self.templ = None + self.buff = "" + self.conn = conn + + if (template is not None): + self.usetempl = True + self.templ = TemplateManager().prepare("templates/"+template+".tmpl") + + def append(self,text): + self.buff += text + + def prepend(self,text): + self.buff = text + self.buff + + def get(self): + if (self.usetempl): + return self.conn.tproc.process(self.templ) + return self.buff + + def clear(self): + self.buff = "" + + def set(self,text): + self.clear() + self.append(text) + class HTML: """ Class to hold all connection data and more """ def __init__(self): """ Set all variables to their default values does not return anything """ - pass + self.body = BODY() def attach(self,conn): self.conn = conn @@ -43,36 +77,30 @@ def content(self,ctype): """ Print out content type of choice """ - return "Content-Type: " + ctype + "\n" + self.conn.tproc.set("sys_content-type", ctype) - def header(self,title,reqlogin=1,nomenuerror=0): + def header(self,title): """ Returns the html header returns string """ - text = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" - text += "<?xml version=\"1.0\" encoding=\"" + av_settings.getSetting(self.conn,"charset") + "\"?>\n" - text += "<html>\n<head>\n<title>" + self.conn.parse(av_settings.getSetting(self.conn,"title")) + self.conn.tproc.set("sys_charset", av_settings.getSetting(self.conn,"charset")) + + header = self.conn.parse(av_settings.getSetting(self.conn,"title")) if (title.__len__()>0): - text += " - " + title - text += "</title>\n" - text += "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + self.conn.makeURL("themes/$THEME$/stylesheet.css",static=1) + "\" />\n" - text += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + av_settings.getSetting(self.conn,"charset") + "\" />\n" - text += "<script type=\"text/javascript\" src=\"" + self.conn.makeURL("script.js",static=1) + "\"></script>\n" # Warning! <script ... /> will NOT display in IE (gotta love Microsoft) - text += "</head>\n" - text += "<body>\n" - text += "<table style=\"width: 775px;\">\n" - text += "<tr><td style=\"width: 175px;\">\n" - text += self.menu(reqlogin,(nomenuerror,title)) - text += "</td><td style=\"width: 600px;\">\n" - text += "<table class=\"main\">\n" - text += "<tr><td class=\"main\">\n" - return text + header += " - " + title + self.conn.tproc.set("sys_header", header) + + self.conn.tproc.set("sys_stylesheet", self.conn.makeURL("themes/$THEME$/stylesheet.css",static=1)) + + self.conn.tproc.set("sys_javascript", self.conn.makeURL("script.js",static=1)) + + #text += self.menu(reqlogin,(nomenuerror,title)) def heading(self,head): """ Returns the page heading in html returns string """ - return "<div class=\"title\">" + head + "</div>\n<br />\n" + self.conn.tproc.set("sys_title", head) def subheading(self,head): """ Returns the page subheading in html @@ -112,150 +140,143 @@ return text; - def menu(self,reqlogin,noerror): + def menu(self,reqlogin): """ Returns the html menu returns string """ - text = "<table class=\"navbar\">\n" - # The logo - text += "<tr><td class=\"navbar\"><a href=\"" - if (self.user.isloggedin()): - text += self.conn.makeURL("main.py") - else: - text += self.conn.makeURL("main.py",usesid=0) - text += "\"><img src=\"" + self.conn.makeURL("themes/$THEME$/images/logo.png",static=1) + "\" alt=\"" + av_settings.getSetting(self.conn,"name") + "\" /></a></td></tr>\n" + tproc = self.conn.tproc + templ = TemplateManager().prepare("templates/menu.tmpl") - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" - + usesid = 0 if (self.user.isloggedin()): - # Rules - if (av_settings.getSetting(self.conn,"showrules")): - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("rules_ls.py") + "\">Rules</a></td></tr>\n" - if (self.user.getPERM()["rules"]): - text += "<tr><td class=\"navbar\"> <u>Management</u></td></tr>\n" - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("rules_edit.py",params={"rulen":"new"}) + "\">Add Rule</a></td></tr>\n" - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" - - # Messages - if (self.user.getPERM()["mess"]): - text += "<tr><td class=\"navbar\"><b><u>Messages</u></b></td></tr>\n" - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("mess_ls.py") + "\">Read</a>" - if (av_message.newMessage(self.conn)): - text += " - <b>NEW!</b>" - text += "</td></tr>\n" - if (self.user.getPERM()["messs"]): - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("mess_comp.py") + "\">Compose</a></td></tr>\n" - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" - - # Equipment - if (self.user.getPERM()["eq"]): - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("eq_ls.py") + "\">Equipment</a></td></tr>\n" - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("eq_leases.py") + "\">Current Status</a></td></tr>\n" - if (self.user.getPERM()["eqh"]): - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("eq_history.py") + "\">History</a></td></tr>\n" - if (self.user.getPERM()["eqa"] or self.user.getPERM()["eqm"] or self.user.getPERM()["eqr"]): - text += "<tr><td class=\"navbar\"> <u>Management</u></td></tr>\n" # FIXME: we are NOT supposed to use <b> <i> and <u> - if (self.user.getPERM()["eqa"]): - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("eq_edit.py",params={"eqn":"new"}) + "\">Add Equipment</a></td></tr>\n" - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" + usesid = 1 + tproc.set("sys_loggedin",1) + + # Scripts + tproc.set("sys_main.py", self.conn.makeURL("main.py",usesid=usesid)) + tproc.set("sys_login.py", self.conn.makeURL("login.py",usesid=usesid)) + tproc.set("sys_logout.py", self.conn.makeURL("logout.py",usesid=usesid)) - # Work - if (self.user.getPERM()["work"]): - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("work_ls.py") + "\">Work</a></td></tr>\n" - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("work_status.py") + "\">Current Status</a></td></tr>\n" - if (self.user.getPERM()["workh"]): - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("work_history.py") + "\">History</a></td></tr>\n" - if (self.user.getPERM()["worka"]): - text += "<tr><td class=\"navbar\"> <u>Management</u></td></tr>\n" # FIXME: we are NOT supposed to use <b> <i> and <u> - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("work_edit.py",params={"work":"new"}) + "\">Add Work</a></td></tr>\n" - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" - - # Room - if (self.user.getPERM()["room"]): - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("room_ls.py") + "\">Rooms</a></td></tr>\n" - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("room_edit.py",params={"room":"new"}) + "\">Add Room</a></td></tr>\n" - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" + # Static files + tproc.set("sys_logo.png", self.conn.makeURL("themes/$THEME$/images/logo.png",static=1)) - # User - if (self.user.getPERM()["user"]): - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("user_ls.py") + "\">User Accounts</a></td></tr>\n" - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("user_edit.py",params={"user":"new"}) + "\">Add User</a></td></tr>\n" - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" + # Rules + tproc.set("sys_rules_ls.py", self.conn.makeURL("rules_ls.py",usesid=usesid)) + tproc.set("sys_rules_edit.py", self.conn.makeURL("rules_edit.py",params={"rulen":"new"},usesid=usesid)) + if (av_settings.getSetting(self.conn,"showrules")): + tproc.set("sys_showrules",1) + if (self.user.getPERM()["rules"]): + tproc.set("sys_showaddrules",1) + + # Messages + tproc.set("sys_mess_ls.py", self.conn.makeURL("mess_ls.py",usesid=usesid)) + tproc.set("sys_mess_comp.py", self.conn.makeURL("mess_comp.py",usesid=usesid)) + if (self.user.getPERM()["mess"]): + tproc.set("sys_showmess",1) + if (av_message.newMessage(self.conn)): + tproc.set("sys_newmess"," - <b>NEW!</b>") + if (self.user.getPERM()["messs"]): + tproc.set("sys_showcomposemess",1) + + # Equipment + tproc.set("sys_eq_ls.py", self.conn.makeURL("eq_ls.py",usesid=usesid)) + tproc.set("sys_eq_leases.py", self.conn.makeURL("eq_leases.py",usesid=usesid)) + tproc.set("sys_eq_history.py", self.conn.makeURL("eq_history.py",usesid=usesid)) + tproc.set("sys_eq_edit.py-add", self.conn.makeURL("eq_edit.py",params={"eqn":"new"},usesid=usesid)) + if (self.user.getPERM()["eq"]): + tproc.set("sys_showeq",1) + if (self.user.getPERM()["eqh"]): + tproc.set("sys_showeqhist",1) + if (self.user.getPERM()["eqa"] or self.user.getPERM()["eqm"] or self.user.getPERM()["eqr"]): + tproc.set("sys_showeqmgr",1) + if (self.user.getPERM()["eqa"]): + tproc.set("sys_showeqadd",1) + # Work + tproc.set("sys_work_ls.py", self.conn.makeURL("work_ls.py",usesid=usesid)) + tproc.set("sys_work_status.py", self.conn.makeURL("work_status.py",usesid=usesid)) + tproc.set("sys_work_history.py", self.conn.makeURL("work_history.py",usesid=usesid)) + tproc.set("sys_work_edit.py-add", self.conn.makeURL("work_edit.py",params={"work":"new"},usesid=usesid)) + if (self.user.getPERM()["work"]): + tproc.set("sys_showwork",1) + if (self.user.getPERM()["workh"]): + tproc.set("sys_showworkhist",1) + if (self.user.getPERM()["worka"]): + tproc.set("sys_showworkadd",1) - # Logs - if (self.user.getPERM()["eql"] or self.user.getPERM()["userl"] or self.user.getPERM()["workl"] or self.user.getPERM()["secl"] or self.user.getPERM()["sysl"]): - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("log.py") + "\">Logs</a></td></tr>\n" - if (self.user.getPERM()["eql"]): - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("eq_log.py") + "\">Equipment Log</a></td></tr>\n" - if (self.user.getPERM()["secl"]): - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("sec_log.py") + "\">Security Log</a></td></tr>\n" - if (self.user.getPERM()["sysl"]): - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("sys_log.py") + "\">System Log</a></td></tr>\n" - if (self.user.getPERM()["userl"]): - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("user_log.py") + "\">User Log</a></td></tr>\n" - if (self.user.getPERM()["workl"]): - text += "<tr><td class=\"navbar\"> <a href=\"" + self.conn.makeURL("work_log.py") + "\">Work Log</a></td></tr>\n" - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" - - # System Settings - if (self.user.getPERM()["settings"]): - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("settings_ls.py") + "\">System Settings</a></td></tr>\n" - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" + # Room + tproc.set("sys_room_ls.py", self.conn.makeURL("room_ls.py",usesid=usesid)) + tproc.set("sys_room_edit.py-add", self.conn.makeURL("room_edit.py",params={"room":"new"},usesid=usesid)) + if (self.user.getPERM()["room"]): + tproc.set("sys_showroom",1) + + # User + tproc.set("sys_user_ls.py", self.conn.makeURL("user_ls.py",usesid=usesid)) + tproc.set("sys_user_edit.py-add", self.conn.makeURL("user_edit.py",params={"user":"new"},usesid=usesid)) + if (self.user.getPERM()["user"]): + tproc.set("sys_showuser",1) - # Passwd - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("passwd.py") + "\">Change Password</a></td></tr>\n" - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" + # Logs + tproc.set("sys_log.py", self.conn.makeURL("log.py",usesid=usesid)) + tproc.set("sys_eq_log.py", self.conn.makeURL("eq_log.py",usesid=usesid)) + tproc.set("sys_sec_log.py", self.conn.makeURL("sec_log.py",usesid=usesid)) + tproc.set("sys_sys_log.py", self.conn.makeURL("sys_log.py",usesid=usesid)) + tproc.set("sys_user_log.py", self.conn.makeURL("user_log.py",usesid=usesid)) + tproc.set("sys_work_log.py", self.conn.makeURL("work_log.py",usesid=usesid)) + if (self.user.getPERM()["eql"] or self.user.getPERM()["userl"] or self.user.getPERM()["workl"] or self.user.getPERM()["secl"] or self.user.getPERM()["sysl"]): + tproc.set("sys_showlog",1) + if (self.user.getPERM()["eql"]): + tproc.set("sys_showeqlog",1) + if (self.user.getPERM()["secl"]): + tproc.set("sys_showseclog",1) + if (self.user.getPERM()["sysl"]): + tproc.set("sys_showsyslog",1) + if (self.user.getPERM()["userl"]): + tproc.set("sys_showuserlog",1) + if (self.user.getPERM()["workl"]): + tproc.set("sys_showworklog",1) + + # System Settings + tproc.set("sys_settings_ls.py", self.conn.makeURL("settings_ls.py",usesid=usesid)) + if (self.user.getPERM()["settings"]): + tproc.set("sys_showsettings",1) - # Logout - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("logout.py") + "\">Logout</a></td></tr>\n" - else: - # Caution and login - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("main.py",usesid=0) + "\">Caution</a></td></tr>\n" - text += "<tr><td class=\"nbnavbar\"> </td></tr>\n" - text += "<tr><td class=\"navbar\"><a class=\"bold\" href=\"" + self.conn.makeURL("login.py",usesid=0) + "\">Login</a></td></tr>\n" - text += "</table>\n" + # Passwd + tproc.set("sys_passwd.py", self.conn.makeURL("passwd.py",usesid=usesid)) # FIXME: if an error occured and reqlogin==0, nothing happens, user gets the page :-( - if ((reqlogin) and (not noerror[0]) and (not self.user.isloggedin()) and (not self.user.timedout())): - print self.header(noerror[1],reqlogin,1) - print self.heading("Error") - text = "ERROR" # default text, will be changed at run time - if (self.user.TEXTBUF["logincheckerror"]): - text = self.user.TEXTBUF["logincheckerror"] - if (text=="ERROR"): # This should not happen - text = "<br />Sorry, but you must log in to access this page. To log in, select the appropreate option from the menu." - av_log.seclog("User attempted to access " + self.user.currentpage() + " without specifying SESSION ID") - print text - print self.footer(1) - self.conn.exit() - if (self.user.timedout() and (not noerror[0])): - print self.header(noerror[1],reqlogin,1) - print self.heading("Warning") - text = "<br />Sorry, but you session expired. Whenever you are inactive for more than " + av_settings.getSetting(self.conn,"timeout") + " minute" - if (int(av_settings.getSetting(self.conn,"timeout")) > 1): - text += "s" - text += " you will be automatically logged out. To log back in, select the apropreate option from the menu." - print text - print self.footer(1) - self.conn.exit() +# if ((reqlogin) and (not noerror[0]) and (not self.user.isloggedin()) and (not self.user.timedout())): +# print self.header(noerror[1],reqlogin,1) +# print self.heading("Error") +# text = "ERROR" # default text, will be changed at run time +# if (self.user.TEXTBUF["logincheckerror"]): +# text = self.user.TEXTBUF["logincheckerror"] +# if (text=="ERROR"): # This should not happen +# text = "<br />Sorry, but you must log in to access this page. To log in, select the appropreate option from the menu." +# av_log.seclog("User attempted to access " + self.user.currentpage() + " without specifying SESSION ID") +# print text +# print self.footer(1) +# self.conn.exit() +# if (self.user.timedout() and (not noerror[0])): +# print self.header(noerror[1],reqlogin,1) +# print self.heading("Warning") +# text = "<br />Sorry, but you session expired. Whenever you are inactive for more than " + av_settings.getSetting(self.conn,"timeout") + " minute" +# if (int(av_settings.getSetting(self.conn,"timeout")) > 1): +# text += "s" +# text += " you will be automatically logged out. To log back in, select the apropreate option from the menu." +# print text +# print self.footer(1) +# self.conn.exit() - return text + tproc.set("sys_menu",tproc.process(templ)) def footer(self,copyright=1): """ Prints out the html footer returns string """ - text = "<br /><br /></td></tr>\n" + if (copyright): - text += "<tr><td class=\"main\"><div class=\"footer\">" + av_settings.getSetting(self.conn,"name") + " " + av_settings.getSetting(self.conn,"version") + " Copyright © 2003 <a href=\"" + self.conn.makeURL("about.py") + "\">Josef "Jeff" Sipek</a></div>\n" - text += "</td></tr>\n" - text += "</table>\n" - text += "</td></tr>\n" - text += "</table>\n" - text += "</body>\n" - text += "</html>\n" - return text + self.conn.tproc.set("sys_footer", "<tr><td class=\"main\"><div class=\"footer\">" + av_settings.getSetting(self.conn,"name") + " " + av_settings.getSetting(self.conn,"version") + " Copyright © 2003 <a href=\"" + self.conn.makeURL("about.py") + "\">Josef "Jeff" Sipek</a></div>\n</td></tr>\n") if __name__ == "__main__": print "ERROR!"