[cpif] r85 - in trunk/frontend-web: . skins/default

svn at argo.es svn at argo.es
Wed May 23 20:04:42 CEST 2007


Author: alvaro
Date: Wed May 23 20:04:41 2007
New Revision: 85

Log:
Aniadidas las paginas que faltaban.

Carga de los skins al inicio en memoria.


Modified:
   trunk/frontend-web/skins.py
   trunk/frontend-web/skins/default/body_generic.html
   trunk/frontend-web/url_INVALIDA.py
   trunk/frontend-web/url_nuevo_usuario.py
   trunk/frontend-web/url_stop.py

Modified: trunk/frontend-web/skins.py
==============================================================================
--- trunk/frontend-web/skins.py	(original)
+++ trunk/frontend-web/skins.py	Wed May 23 20:04:41 2007
@@ -8,7 +8,8 @@
     'header':        'header.html',
     'body_thread':   'body_show_thread.html',
     'thread_entry':  'body_show_thread_entry.html',
-    'error':         'body_generic.html',
+    'new_user':      'body_new_user.html',
+    'generic':       'body_generic.html',
     'body':          'body_threadlist.html',
     'thread_unread': 'body_threadlist_thread_unread.html',
     'thread':        'body_threadlist_thread.html',
@@ -17,36 +18,39 @@
     }
 
 import os
-sdir = "%s/skins/" % os.path.curdir
+sdir = os.path.join(os.path.curdir,"skins")
 print "Inicializo los skins"
-for i in os.listdir(sdir):
+for dir in os.listdir(sdir):
   control = True
   for j in skin_files.values():
-    if not os.path.exists(os.path.join(sdir, i, j)): #FIXME: use join
+    if not os.path.exists(os.path.join(sdir, dir, j)):
       control = False
   if control:
-    available_skins[i]=dict([(k,os.path.join(sdir,i,j)) for k,j in skin_files.items()]) # FIXME
-if "default" not in available_skins: # FIXME: an~adir un skin de fallback?
-  raise "Error, no tenemos el skin por defecto!!"
+    available_skins[dir]= {}
+    for skin,file in skin_files.items():
+      f=open(os.path.join(sdir,dir,file))
+      available_skins[dir][skin]=f.read()
+
+  if "default" not in available_skins: # FIXME: an~adir un skin de fallback?
+    raise "Error, no tenemos el skin por defecto!!"
 print available_skins.keys()
 
 class Skin:
 
-  __text = []
+  _text = []
 
   def __init__(self):
-    self.__skin="default"
-    self.__url=""
+    self._skin="default"
+    self._url=""
     self.reset()
-    self.__t_count = 0
-    self.__style=["odd","even"]
-    self.__dict={
+    self._style=["odd","even"]
+    self._dict={
         "version": globales.version,
         "page_title": "cpif",
         "calendar":""
         }
 
-  def __load_file(self,file):
+  def _load_file(self,file):
     str = ""
     # Hmmm, en teoria no hace falta el try (hemos comprobado antes que todo va OK) , pero por seguridad...
     try:
@@ -61,80 +65,80 @@
 
   def set_skin(self,skin):
     if skin in available_skins:
-      self.__skin=skin
+      self._skin=skin
       return True
     return None
 
   def reset(self):
-    self.__text = []
+    self._text = []
 
   def load_url(self,url):
     if not url[0] or (url[0] == 'indice' and len(url) == 2):
-      self.__url="listado hilos"
+      self._url="listado hilos"
     elif url[0] == "hilo":
-      self.__url="hilo"
+      self._url="hilo"
+    elif url[0] == "nuevo_usuario":
+      self._url="nuevo usuario"
     else:
+      self._url=""
       print "Error" # FIXME
 
   def load_dict(self,dict):
     for key,val in dict.iteritems():
-      self.__dict[key]=val
+      self._dict[key]=val
 
   def set_text(self,text):
-    self.__text.append(text)
+    self._text.append(text)
 
   def header(self):
-    file = available_skins[self.__skin]['header']
-    return self.__load_file(file) % self.__dict
+    return  available_skins[self._skin]['header'] % self._dict
   
   def thread_entries(self,e):
     """Format some entries inside a thread"""
     for msg_num,author,date,text in e:
-      format = self.__style.pop(0)
-      self.__style.append(format)
+      format = self._style.pop(0)
+      self._style.append(format)
 
-      file = available_skins[self.__skin]['thread_entry']
       import time
-      aux = self.__load_file(file) % {"msg_num":msg_num, "author":author, "date":time.ctime(date), "text":text,"format":format }
+      aux = available_skins[self._skin]['thread_entry'] % {"msg_num":msg_num, "author":author, "date":time.ctime(date), "text":text,"format":format }
       self.set_text(aux)
 
   def threads(self,t,notread,threads):
     """Format the thread list"""
     # FIXME: No me gusta pasarle el array entero de hilos para hacer la busqueda de la fecha
-    if self.__url=="listado hilos":
+    if self._url=="listado hilos":
       for thread,title,not_read in t:
-        format = self.__style.pop(0)
-        self.__style.append(format)
+        format = self._style.pop(0)
+        self._style.append(format)
 
         import time
         ts_created=time.ctime(threads[thread]["TS"])
         if not_read:
-          file = available_skins[self.__skin]['thread_unread']
-          aux = self.__load_file(file) % {"title":title,"thread":thread,"t_date":ts_created,"format": format,"notread":notread[thread]}
+          aux = available_skins[self._skin]['thread_unread'] % {"title":title,"thread":thread,"t_date":ts_created,"format": format,"notread":notread[thread]}
         else:
-          file = available_skins[self.__skin]['thread']
-          aux = self.__load_file(file) % {"title":title,"thread":thread,"t_date":ts_created,"format": format}
+          aux = available_skins[self._skin]['thread'] % {"title":title,"thread":thread,"t_date":ts_created,"format": format}
         self.set_text(aux)
   
   def group_date(self,date):
     """Insert the thread date"""
-    if self.__url=="listado hilos":
-      file = available_skins[self.__skin]['group_date']
-      self.set_text(self.__load_file(file) % {'group_date':date})
+    if self._url=="listado hilos":
+      self.set_text(available_skins[self._skin]['group_date'] % {'group_date':date})
 
   def body(self,title=None):
-    if self.__url=="listado hilos":
-      file = available_skins[self.__skin]['body']
-    elif self.__url=="hilo":
-      file = available_skins[self.__skin]['body_thread']
+    if self._url=="listado hilos":
+      aux = available_skins[self._skin]['body']
+    elif self._url=="hilo":
+      aux = available_skins[self._skin]['body_thread']
+    elif self._url=="nuevo usuario":
+      aux = available_skins[self._skin]['new_user']
     else:
-      file = available_skins[self.__skin]['error']
+      aux = available_skins[self._skin]['generic']
 
-    ret = self.__dict # Pillamos el diccionario a deolver
-    ret['body'] = "\r\n".join(self.__text) # Aniado el texto
+    ret = self._dict # Pillamos el diccionario a deolver
+    ret['body'] = "\r\n".join(self._text) # Aniado el texto
     self.reset()
-    return self.__load_file(file) % ret
+    return aux % ret
 
   def footer(self):
-    file = available_skins[self.__skin]['footer']
-    return self.__load_file(file) % self.__dict
+    return available_skins[self._skin]['footer'] % self._dict
+

Modified: trunk/frontend-web/skins/default/body_generic.html
==============================================================================
--- trunk/frontend-web/skins/default/body_generic.html	(original)
+++ trunk/frontend-web/skins/default/body_generic.html	Wed May 23 20:04:41 2007
@@ -2,8 +2,6 @@
       .even   {background-color: efe}
       .odd {background-color: eef}
     </style>
-
-    <h2>ERROR QUE TE CAGAS</h2>
     %(body)s
     <hr>
     <a href="/">Pagina principal</a>

Modified: trunk/frontend-web/url_INVALIDA.py
==============================================================================
--- trunk/frontend-web/url_INVALIDA.py	(original)
+++ trunk/frontend-web/url_INVALIDA.py	Wed May 23 20:04:41 2007
@@ -7,6 +7,6 @@
   pagina = skins.Skin()
   pagina.load_url("404")
   pagina.load_dict({"page_title": "cpif - ERROR"})
-  pagina.set_text("La pagina que buscas no existe, pich&oacute;n")
+  pagina.set_text("<h2>ERROR<H2>\r\nLa pagina que buscas no existe, pich&oacute;n</h2>")
 
   return (404,"text/html; charset=utf-8","\r\n".join([pagina.header(),pagina.body(),pagina.footer()]))

Modified: trunk/frontend-web/url_nuevo_usuario.py
==============================================================================
--- trunk/frontend-web/url_nuevo_usuario.py	(original)
+++ trunk/frontend-web/url_nuevo_usuario.py	Wed May 23 20:04:41 2007
@@ -3,28 +3,13 @@
 from globales import monitor
 
 def gestiona_url(handler,path,usuario) :
-  if usuario!="master" :
-    return(200,"text/html; charset=utf-8",
-"""
-<html><head></head><body>
-<h1>Solo el usuario 'master' puede dar de alta nuevos usuarios</h1>
-<p><a href="/">P&aacute;gina principal</a>
-<p><a href="/stop">Parar la demo</a>
-</body></html>""")
+  import skins
+  pagina = skins.Skin()
+  pagina.load_url(path)
+  pagina.load_dict({"page_title": "cpif - parando el servicio"})
 
-  return (200,"text/html; charset=utf-8",
-"""
-<html><head></head>
-<body>
-<form action="/nuevo_usuario_POST" method="post" enctype="multipart/form-data">
-<table>
-<tr><td>Usuario:</td><td><input type="text" name="usuario" size="25" value="" /></td></tr>
-<tr><td>Clave:</td><td><input type="password" name="clave1" size="25" value="" /></td></tr>
-<tr><td>Confirma la clave:</td><td><input type="password" name="clave2" size="25" value="" /></td></tr>
-<tr><td colspan=2 align=right><input class="form-element" type="submit" name="submit" value="Crea usuario"/></td></tr>
-</table>
-</form>
-<p><a href="/">P&aacute;gina principal</a>
-<p><a href="/stop">Parar la demo</a>
-</body></html>""")
+  if usuario!="master" :
+    pagina.load_url("error")
+    pagina.set_text("<h1>Solo el usuario 'master' puede dar de alta nuevos usuarios</h1>")
 
+  return (200,"text/html; charset=utf-8","\r\n".join([pagina.header(),pagina.body(),pagina.footer()]))

Modified: trunk/frontend-web/url_stop.py
==============================================================================
--- trunk/frontend-web/url_stop.py	(original)
+++ trunk/frontend-web/url_stop.py	Wed May 23 20:04:41 2007
@@ -3,20 +3,15 @@
 from globales import monitor
 
 def gestiona_url(handler,path,usuario) :
-  if usuario!="master" :
-    return(200,"text/html; charset=utf-8",
-"""
-<html><head></head><body>
-<h1>Solo el usuario 'master' puede parar el servicio</h1>
-<p><a href="/">P&aacute;gina principal</a>
-<p><a href="/stop">Parar la demo</a>
-</body></html>""")
-
+  import skins
+  pagina = skins.Skin()
+  pagina.load_url(path)
+  pagina.load_dict({"page_title": "cpif - parando el servicio"})
 
-  handler.must_stop=True
-  return (200,"text/html; charset=utf-8",
-"""
-<html><head></head><body>
-<h1>PARAMOS EL SERVICIO!!</h1>
-</body></html>""")
+  if usuario!="master" :
+    pagina.set_text("<h2>Solo el usuario 'master' puede parar el servicio</h2>")
+  else:
+    handler.must_stop=True
+    pagina.set_text("<h2>PARAMOS EL SERVICIO!!</h2>")
 
+  return(200,"text/html; charset=utf-8","\r\n".join([pagina.header(),pagina.body(),pagina.footer()]))



More information about the cpif mailing list