todo_list.py :  » Business-Application » ganttproject-at-web » gantt » older » old_18feb » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » ganttproject at web 
ganttproject at web » gantt » older » old_18feb » todo_list.py
#!/usr/bin/python
"""
  todo list manager
  
  tests: Firefox, Mozilla Camino, apple's Safari
  @author: Baruffaldi Paolo
  @since: 24/01/2005
  
"""
import xml.dom.minidom
import cgi
import cgitb;cgitb.enable()

setup = {
  "page_title":"lista todo",
  "campi":["data_ini","data_fine","cosa","descrizione"],
  "ramo_label":"to do:",
  "file_tabella":"/var/www/progetti/tmp/todo.csv"
  }
  
def main():
  
  print "Content-Type:text/html\n\n"
  core=diz_parametri_cgi()
  core["msg"]=[]
  html="<html><body onreload=''>"+html_css()
  html+= html_javascript()
  html+=html_render_intestazione(core)
  add_msg(core,repr(diz_parametri_cgi()))
  op = core["op"]
  if not (dati_leggi_da_input(core)):
    dati_leggi_da_storage(core)
  if op == "salva":
    dati_scrivi_valori(core)
  html+= html_msg(core)
  if op == "modifica":
    html+= html_render_modulo(core)
    html+= html_carica_valori(core)
  else:
    html+= html_render_vista(core)
  html+="</body>"
  print html
    
  
################################################################################
################################################################################

def diz_parametri_cgi():
  diz = {}
  x=cgi.FieldStorage(keep_blank_values=1)
  for a in x.list:
    if a.name in diz:
      diz[a.name].append(a.value)
    else:
      diz[a.name] = [a.value]
  diz["op"]=diz.get("op",[""])[0]
  diz["msg"]=[]
  return diz
  

def dati_leggi_da_storage(diz):
  add_msg(diz,"dati_leggi_da_storage",7)
  try:
    src = open(setup["file_tabella"],"r")
  except:
    return False
  txt = src.read()
  src.close()
  diz["valori_tabella"]=[x.split(";") for x in txt.splitlines()]
  return True
  
  
def dati_leggi_da_input(diz):
  """
    legge i valori dati dall'utente
    o presenti su file
  """
  add_msg(diz,"dati_leggi_da_input",7)
  for a in setup["campi"]:
    if not(a in diz.keys()):
      return False
  valori = []
  for a in setup["campi"]:
    valori.append(diz[a])
  valori=zip(*valori)
  valori=[list(x) for x in valori]
  diz["valori_tabella"]=valori
  return True
  
    
    
def dati_scrivi_valori(diz):
  add_msg(diz,"dati_scrivi_valori",7)
  txt = "\n".join([";".join([x for x in y]) for y in diz["valori_tabella"]]) 
  src = open(setup["file_tabella"],"w")
  src.write(txt)
  src.close()
  
def html_render_intestazione(diz):
  html= ["""<h1 class='etichetta'>%(page_title)s</h1><form method='post'>
  <input type='hidden' name='op'>"""]
  if diz["op"]<="":
    html.append("""  <input type='button' value='modifica' onclick='op.value="modifica";form.submit()'>""")
  else:
    html.append("""
    <input type='button' value='visualizza' onclick='form.submit()'>[
    <input type='button' value='nuovo' onclick='aggiungi("")'>
    <input type='button' value='salva' onclick='salva()'>]""")
  html.append("</form>")
  
  return "".join(html) % setup
  
def html_carica_valori(diz):
  add_msg(diz,"dati_scrivi_valori",7)
  valori = diz["valori_tabella"]
  html="""<script>
  valori_old=%r;
  for (var a=0;a<valori_old.length;a++){
    var nuovo=aggiungi("");
    var lista_campi=nuovo.getElementsByTagName("input");
    for (b=0;b<campi.length;b++){
      lista_campi[b].value=valori_old[a][b];
      }
    
    }
  </script>
  """ % valori
  return html
  
def html_render_vista(diz):
  add_msg(diz,"html_render_vista",7)  
  html="""<br><br><br><div class='etichetta'>
  <script>
  campi=%(campi)r;
  valori_old=%%(valori_tabella)r;
  for (var a=0;a<campi.length;a++){
    document.write("<div class='atomo"+a+"'>"+campi[a]+"</div>");
  }  
  document.write("</div><br><br>");
  for (var a=0;a<valori_old.length;a++){
    document.write("<div class='elemento'>");
    for (b=0;b<campi.length;b++){
      document.write("<span class='atomo"+b+"' onclick='evidenzia(this,1)' ondblclick='evidenzia(this,0)'>"+valori_old[a][b]+"</span>");
      }
    document.write("</div>");
    }  
  </script>
  """ % setup % diz
  return html
  
def html_render_modulo(diz):
  html="""
<script>
campi= %(campi)r;
document.write("<table width='100%%'><tr>");
for (var a = 0; a< campi.length;a++){
  document.write("<th>"+campi[a]+"</th>");
  }
document.write("</tr></table>");
</script>
<form action='' id='the_form'>
<input type='hidden' name='op' value=''>
</form>
<script>
x_form=document.getElementById("the_form");

function risultato(){
  k = window.open();
  k.document.write(x_form.innerHTML);
  k.document.close();
}
function salva(){
  var x =document.getElementById("the_form");
  x.op.value='salva';
  x.submit();
  }
var CODICE_INS = 0;
function aggiungi(padre){
  CODICE_INS++;
  elemento= document.createElement("div");
  for (var a =0;a< campi.length;a++){
      x_inp=document.createElement("input");
      x_inp.setAttribute("type","text");
      x_inp.setAttribute("name",campi[a]);
      elemento.appendChild(x_inp);
    }
    x_del=document.createElement("input");
    x_del.setAttribute("type","button");
    x_del.setAttribute("value","elimina");
    x_del.setAttribute("onclick","elimina(this.parentNode)");
    elemento.appendChild(x_del);
    x_ins=document.createElement("input");
    x_ins.setAttribute("type","button");
    x_ins.setAttribute("value","nuovo");
    x_ins.setAttribute("onclick","aggiungi(this.parentNode)");
    elemento.appendChild(x_ins);
  elemento.setAttribute("class","elemento");
  last = elemento;
  if (padre==""){
    x_form.appendChild(last);
    }
  else {
    padre.appendChild(last);
    }
  return last;
  }
  
  
function elimina(chi){
  chi.parentNode.removeChild(chi);
}
</script>
  """ % setup
    
    
  return html
  
def add_msg(diz,msg,livello=1):
  """
    aggiunge un messaggio
  """
  diz["msg"].append([livello,msg])
  
################################################################################
################################################################################

def html_css():
  return """<style>
  body {background-color:#eed;}
  input[type~=button]{
  -moz-border-radius:100px;
  background-color:#88f;
  }
  
  code {
  background-color:#eee;
  color:#080;
  }
  .elemento {
  border:solid 1px #88c;
  border-width:0px 0px 0px 5px;
  background-color:#eef;
  display:block;
  margin:0 5 0 5;
  padding-top:5;
  padding-bottom:5;
  }
  .elemento .elemento {background-color:#ccf;}
  .elemento .elemento .elemento {background-color:#aaf;}
  .elemento .elemento .elemento {background-color:#99f;}
  .elemento .elemento .elemento .elemento {background-color:#77f;}
  .elemento .elemento .elemento .elemento .elemento {background-color:#55f;}
  .elemento .elemento .elemento .elemento .elemento .elemento {background-color:#33f;}
  .elemento .elemento .elemento .elemento .elemento .elemento .elemento {background-color:#11f;}
  .elemento:before{
    content:"%(ramo_label)s";
    color:black;
  }
  #messaggi div {
    border:solid 1px #080;
    background-color:#ffe;
  }
  .atomo0, .atomo1, .atomo2, .atomo3, .atomo4, .atomo5{  
  position:absolute;
  display:inline;
  min-width: 90px;
  background:#fff;
  border:solid 1px #ccf;
  }
  .atomo0 {left:60px;}
  .atomo1 {left:150px;}
  .atomo2 {left:230px;font-weight:bolder;}
  .atomo3 {left:400px; width:580px;}
  .atomo4 {left:450px;}
  .atomo5 {left:550px;}
  .etichetta {color:blue;text-align:center;}
  </style>""" % setup
  
def html_msg(diz):
  """
    visualizza i messaggi
  """
  
  livello=["messaggio","errore","warning",
  "messaggo admin","errore admin","warning admin",
  "debug admin","log admin"]
  
  html="""
  messaggi:<input type='checkbox' value='messaggi log' onclick='mostra_nascondi(this.nextSibling)'
  ><div id='messaggi' style='display:none'>
  """
  for msg in diz.get("msg"):
    html+="<div><code>%s</code>:%s</div>" % (livello[msg[0]],msg[1])
  html+="</div>"
  return html

def html_javascript():
  html="""
  <script>
  function evidenzia(chi,v){
  if (v == 1){
    chi.style.background="yellow";
    chi.style.color="blue";
    }
  else {
    chi.style.background="";
    chi.style.color="";
    }
  }
  function mostra_nascondi(chi){
    if (chi.style.display=="block"){
      chi.style.display="none";
      }
    else {
      chi.style.display="block";
    }
    }
  </script>
  """
  return html
  

  
################################################################################
################################################################################
  
if __name__ == "__main__":
  main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.