gantt_web3.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 » gantt_web3.py
#!/usr/bin/python
"""
  ganttproject at web 
  @verion 1.0
"""

import types, xml.dom.minidom
import cgi, os
import cgitb;cgitb.enable()

setup = {
  "url_base":"http://localhost/cgi-bin/gantt/gantt_web3.py",
  "url_gantt_prj_xslt":"/css/gantt_prj.xslt",
  "page_title":"ganttproject@web",
  "campi":["start","duration","name","complete"],
  "nome_tag_padre":"tasks",
  "nome_tag_uno":"task",
  "ramo_label":"task:",
  "file_tabella":"/var/www/progetti/tmp/todo.xml",
  "projects_path":"/var/www/progetti",
  "personal_ip_list":["127.0.0.1"],
  "img_url":"/gantt/",
  "cgi_url":"/cgi-bin/gantt/"
  }
  


def main():
  pagina = pagemaker()
  core=diz_parametri_cgi()
  core["op"]= core.get("op","app.home")
  op=core["op"].split(".")
  if op==[""]:
    op=["app","home"]
  op.extend([None,None,None])
  op0,op1,op2 = op[:3]
  result=[]
  if op0 == "projects":
    if op1=="show":
      pagina.set_xslt(setup["url_gantt_prj_xslt"])
      if op2=="all":
        result.extend(xml_projects_list("*"))
      elif op2=="summary":
        result.extend(xml_projects_list(["project","resources"]))
      elif op2=="list":
        result.extend(xml_projects_list(["project"]))
      elif op2=="resources":
        result.extend(xml_projects_list(["resources"]))
  elif op0 == "app":
    pagina.set_kind("html")
    pagina.set_css("gantt_app.css")
    if op1 == "home":
      result.extend(page_app_home())
    elif op1 == "help":
      result.extend(page_app_help())
  else:
      result.append("<error>ERRORE: %s = %s %s %s</error>" % (op,op0,op1,op2))
    
  
  pagina.set_content(result)
  print pagina.build()
  

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

#######################    ##############################################
####################### pages  ##############################################
#######################    ##############################################

def page_app_home():
  ls =[]
  diz = {"opening":"benvenuto su ganttproject@web",
  "_L_app.home":"home",
  "_URL_app.home":app_url(op="app.home"),
  "_L_projects.show.all":"progetti - esteso",
  "_URL_projects.show.all":app_url(op="projects.show.all"),
  "_L_projects.show.list":"progetti - sintesi",
  "_URL_projects.show.list":app_url(op="projects.show.list"),
  "_L_projects.show.summary":"sommario",
  "_URL_projects.show.summary":app_url(op="projects.show.summary"),
  "_L_projects.show.resources":"risorse",
  "_URL_projects.show.resources":app_url(op="projects.show.resources"),
  "img_url":setup["img_url"],
  }
  diz.update(setup)
  
  ls.append("""<table>
  <tr><td><img src='%(img_url)s/gantt.png'></td></tr>
  <tr><td>%(opening)s</td></tr>
  <tr><td>
  <a href='%(_URL_app.home)s'>%(_L_app.home)s</a>
  </td></tr><tr><td>
  <a href='%(_URL_projects.show.summary)s'>%(_L_projects.show.summary)s</a>
  </td></tr><tr><td>
  <a href='%(_URL_projects.show.list)s'>%(_L_projects.show.list)s</a>
  </td></tr><tr><td>
  <a href='%(_URL_projects.show.all)s'>%(_L_projects.show.all)s</a>
  <tr><td>
  <a href='%(_URL_projects.show.resources)s'>%(_L_projects.show.resources)s</a>
  </td></tr>
  </table>
  """ % diz
  )
  return ls

def page_app_help():
  return ["""
  <pre>
  This is <b><i>Ganttproject at web</i></b>, a gantt projects' charts viewer.
  
  author: Baruffaldi Paolo
  since: 01/02/2005
  </pre>
  """]
  
def app_url(op=None):
  param=[]
  if op:
    param.append("op=%s" % op)
  if len(param) >0:
    return setup["url_base"]+"?"+param[0]+"&".join(param[1:])
  else:
    return setup["url_base"]
#######################    ##############################################
####################### core  ##############################################
#######################    ##############################################
def xml_projects_list(cosa=["project"]):
  """
    made an xml "synthesis" of the projects
    listed.
  """
  xml=[]
  xml.append("<projects>")
  for a in PRJS:
    #xml.append("<project>%s</project>" % a.get_name())
    xml.append("<!--\n file: %s \n - - - - - - - - - - - - - - - - - - - - - - -->\n" % a.get_name())
    if cosa == None or cosa == "*":
      xml.append(a.get_xml())
    else:
      base =a.get_dom()
      if "project" in cosa:
        descrizione=base.getElementsByTagName("description")[0].toxml()
        attributi = " ".join(["%s='%s'" % x for x in base.attributes.items()])
        xml.append("<project %s>%s" % (attributi,descrizione))
      # gestione di opzioni su tasks
      if "project" in cosa:
        xml.append("</project>")
      if "resources" in cosa:
        xml.append("<resources>")
        for risorsa in base.getElementsByTagName("resources")[0].getElementsByTagName("resource"):
          attributi = " ".join(["%s='%s'" % x for x in risorsa.attributes.items()])
          xml.append("<resource %s />"% attributi)
        xml.append("</resources>")
  xml.append("</projects>")
  return xml


def load_projects():
  k=[]
  for nome in os.listdir(setup["projects_path"]):
    if len(nome)<4 or nome[-4:]!=".gan":
      continue
    if not(permissions(nome)):
      continue
    k.append( project(nome))
  return k

def permissions(nomefile):
  """
    An ip based control:
    by default only localhost can see files starting with "MY"
  """  
  #usato MY per definire i files Nascosti, per dar modo a ganttproject di vedere
  #il file
  if nomefile[:2]=="MY" and os.environ["REMOTE_ADDR"] not in setup["personal_ip_list"]:
    return False
  else:
    return True
    
class project:
  
  def __init__(self,filename):
    self.filename = filename
    self.dom = None
    
  def load_dom(self):
    self.dom = xml.dom.minidom.parse(setup["projects_path"]+"/"+self.filename)
  
  def get_dom(self):
    if not( self.dom):
      self.load_dom()
    return self.dom.documentElement
    
  def get_xml(self):
    if not( self.dom):
      self.load_dom()
    return self.dom.documentElement.toxml()
    
  def get_name(self):
    return self.filename

class pagemaker:
  def __init__(self):
    self.content = ""
    self.kind = "xml"
    self.css = None
    self.xslt = None
    
  def set_content(self,contenuto):
    """
      the xml documentElement in list or str format
    """
    if type(contenuto) in (types.ListType,types.TupleType):
      self.content = "\n".join(contenuto)
    else:
      self.content = contenuto
  
  def set_kind(self,kind):
    self.kind = kind
    
  def set_css(self,css):
    self.css = css
    
  def set_xslt(self,xslt):
    self.xslt = xslt
    
  def build(self):
  
    if self.kind == "xml":
      x= "Content-type:text/xml\n\n"
      x+="<?xml version='1.0'?>\n"
      if self.css:
        x+="<?xml-stylesheet type='text/css' href='%s'?>\n" % self.css
      if self.xslt:
        x+="<?xml-stylesheet type='text/xsl' href='%s'?>\n" % self.xslt
      x+=self.content
      
    elif self.kind== "html":
      x= "Content-type:text/html\n\n"
      x+="<html charset-encoding='UTF-8'>\n"
      x+=self.content
      x+="\n</html>"
      
    return x.encode("UTF-8")
    
if __name__ == "__main__":
  PRJS = load_projects()
  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.