[cpif] r81 - trunk/frontend-web
svn at argo.es
svn at argo.es
Wed May 23 17:43:56 CEST 2007
Author: alvaro
Date: Wed May 23 17:43:55 2007
New Revision: 81
Log:
Sacada fuera de la clase la comprobacion de los scripts.
Simplificacion y limpieza de parte del codigo.
Modified:
trunk/frontend-web/skins.py
Modified: trunk/frontend-web/skins.py
==============================================================================
--- trunk/frontend-web/skins.py (original)
+++ trunk/frontend-web/skins.py Wed May 23 17:43:55 2007
@@ -2,38 +2,40 @@
import globales
-class Skin:
- available_skins = {}
+available_skins = {}
+
+skin_files = {
+ 'header': 'header.html',
+ 'body_thread': 'body_show_thread.html',
+ 'thread_entry': 'body_show_thread_entry.html',
+ 'error': 'body_generic.html',
+ 'body': 'body_threadlist.html',
+ 'thread_unread': 'body_threadlist_thread_unread.html',
+ 'thread': 'body_threadlist_thread.html',
+ 'group_date': 'body_threadlist_group.html',
+ 'footer': 'footer.html'
+ }
+
+import os
+sdir = "%s/skins/" % os.path.curdir
+print "Inicializo los skins"
+for i in os.listdir(sdir):
+ control = True
+ for j in skin_files.values():
+ if not os.path.exists("%s/%s/%s" % (sdir, i, j)):
+ control = False
+ if control:
+ available_skins[i]=dict([(k,"%s/%s/%s" % (sdir,i,j)) for k,j in skin_files.items()])
+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()
- skin_files = {
- 'header': 'header.html',
- 'body_thread': 'body_show_thread.html',
- 'thread_entry': 'body_show_thread_entry.html',
- 'error': 'body_generic.html',
- 'body': 'body_threadlist.html',
- 'thread_unread': 'body_threadlist_thread_unread.html',
- 'thread': 'body_threadlist_thread.html',
- 'group_date': 'body_threadlist_group.html',
- 'footer': 'footer.html'
- }
+class Skin:
__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 instancia
- 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: an~adir un script de fallback?
- raise "Error, no tenemos el skin por defecto!!"
- self.skin="default"
+ self.__skin="default"
self.__url=""
self.reset()
self.__t_count = 0
@@ -57,6 +59,12 @@
raise
return str
+ def set_skin(self,skin):
+ if skin in available_skins:
+ self.__skin=skin
+ return True
+ return None
+
def reset(self):
self.__text = []
@@ -76,7 +84,7 @@
self.__text.append(text)
def header(self):
- file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['header'])
+ file = available_skins[self.__skin]['header']
return self.__load_file(file) % self.__dict
def thread_entries(self,e):
@@ -85,12 +93,11 @@
format = self.__style.pop(0)
self.__style.append(format)
- file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['thread_entry'])
+ 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 }
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
@@ -102,26 +109,26 @@
import time
ts_created=time.ctime(threads[thread]["TS"])
if not_read:
- file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['thread_unread'])
+ 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]}
else:
- file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['thread'])
+ file = available_skins[self.__skin]['thread']
aux = self.__load_file(file) % {"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 = "%s/%s" % (self.available_skins[self.skin], self.skin_files['group_date'])
+ file = available_skins[self.__skin]['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'])
+ file = available_skins[self.__skin]['body']
elif self.__url=="hilo":
- file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['body_thread'])
+ file = available_skins[self.__skin]['body_thread']
else:
- file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['error'])
+ file = available_skins[self.__skin]['error']
ret = self.__dict # Pillamos el diccionario a deolver
ret['body'] = "\r\n".join(self.__text) # Aniado el texto
@@ -129,5 +136,5 @@
return self.__load_file(file) % ret
def footer(self):
- file = "%s/%s" % (self.available_skins[self.skin], self.skin_files['footer'])
+ file = available_skins[self.__skin]['footer']
return self.__load_file(file) % self.__dict
More information about the cpif
mailing list