[cpif] r69 - in trunk: . frontend-web

svn at argo.es svn at argo.es
Tue May 22 02:12:59 CEST 2007


Author: alvaro
Date: Tue May 22 02:12:58 2007
New Revision: 69

Log:
Está visto que hay que dormir más...

Comitto el TODO y el fichero skins.py, si no
menuda gracia :)



Added:
   trunk/frontend-web/skins.py   (contents, props changed)
Modified:
   trunk/TODO

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	(original)
+++ trunk/TODO	Tue May 22 02:12:58 2007
@@ -59,3 +59,9 @@
   de bases de datos, no hara falta que guardemos un backup
   de los usuarios.
 
+- 20070522: FRONTAL WEB: Faltan por modificar los siguientes
+  ficheros del frontal:
+    - url_nuevo_usuario.py
+    - url_stop.py
+  Sacar la comprobacion de los skins fuera de la clase.
+

Added: trunk/frontend-web/skins.py
==============================================================================
--- (empty file)
+++ trunk/frontend-web/skins.py	Tue May 22 02:12:58 2007
@@ -0,0 +1,132 @@
+# $Id$
+# -*- coding: iso-8859-15 -*-
+
+import globales
+
+class Skin:
+  available_skins = {}
+
+  skin_files = {
+      'header': 'header/default.html',
+      'body_thread':   'body/body_thread.html',
+      'thread_entry':   'body/thread_entry.html',
+      'error':   'body/default.html',
+      'body':   'body/body.html',
+      'thread': 'body/thread.html',
+      'group_date': 'body/thread_group.html',
+      'footer': 'footer/default.html'
+      }
+
+  __text = []
+
+  def __init__(self):
+    # FIXME: toda esta morralla va aqui por vagancia, pero va movida.
+    #        no vamos a ser tan melones de comprobar todo cada vez que se intsancia
+    import os
+    sdir = "%s/skins/" % os.path.curdir
+    for i in os.listdir(sdir):
+      control = True
+      for j in self.skin_files.values():
+        if not os.path.exists("%s/%s/%s" % (sdir, i, j)):
+          control = False
+      if control:
+        self.available_skins[i]="%s/%s/" % (sdir, i)
+    if "default" not in self.available_skins: # FIXME: añadir un script de fallback?
+      raise "Error, no tenemos el skin por defecto!!"
+    self.skin="default"
+    self.__url=""
+    self.reset()
+    self.__t_count = 0
+    self.__dict={
+        "version": globales.version,
+        "page_title": "cpif",
+        "calendar":""
+        }
+
+  def __load_file(self,file):
+    str = ""
+    # Hmmm, en teoría no hace falta el try (hemos comprobado antes que todo va OK) , pero por seguridad...
+    try:
+      f = open(file)
+      try:
+        str = f.read()
+      finally:
+        f.close()
+    except:
+      raise
+    return str
+
+  def reset(self):
+    self.__text = []
+
+  def load_url(self,url):
+    if not url[0] or (url[0] == 'indice' and len(url) == 2):
+      self.__url="listado hilos"
+    elif url[0] == "hilo":
+      self.__url="hilo"
+    else:
+      print "Error" # FIXME
+
+  def load_dict(self,dict):
+    for key,val in dict.iteritems():
+      self.__dict[key]=val
+
+  def set_text(self,text):
+    self.__text.append(text)
+
+  def header(self):
+    file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['header'])
+    return self.__load_file(file) % self.__dict
+  
+  def thread_entries(self,e):
+    """Format some entries inside a thread"""
+    for msg_num,author,date,text in e:
+      if self.__t_count % 2:
+        format = "even"
+        self.__t_count = 0
+      else:
+        format = "odd"
+        self.__t_count = 1
+      file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['thread_entry'])
+      aux = self.__load_file(file) % {"msg_num":msg_num, "author":author, "date":date, "text":text,"format":format }
+      self.set_text.append(aux)
+
+
+  def threads(self,t):
+    """Format the thread list"""
+    # FIXME: falta pasarle la fecha, se le puede pasar el array entero de todos los posts
+    #        y hacer la búsqueda aquí, pero es algo sucio
+    if self.__url=="listado hilos":
+      for thread,title,read in t:
+        if self.__t_count % 2:
+          format = "even"
+          self.__t_count = 0
+        else:
+          format = "odd"
+          self.__t_count = 1
+        file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['thread'])
+        aux = self.__load_file(file) % {"title":title,"thread":thread,"t_date":"FIXME","format": format}
+        self.set_text.append(aux)
+  
+  def group_date(self,date):
+    """Insert the thread date"""
+    if self.__url=="listado hilos":
+      file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['group_date'])
+      self.set_text(self.__load_file(file) % {'group_date':date})
+
+  def body(self,title=None):
+    if self.__url=="listado hilos":
+      file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['body'])
+    elif self.__url=="hilo":
+      file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['body_thread'])
+    else:
+      file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['error'])
+
+    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
+
+  def footer(self):
+    file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['footer'])
+    return self.__load_file(file) % self.__dict



More information about the cpif mailing list