[cpif] r144 - in trunk/frontend-web: . skins/default
svn at argo.es
svn at argo.es
Tue Jun 12 02:27:50 CEST 2007
Author: alvaro
Date: Tue Jun 12 02:27:48 2007
New Revision: 144
Log:
Aniadido el soporte para usuarios anonimos. Ahora al instanciar
al skin se debe pasar la url y el nombre de usuario al skin del
modo Skin(path,usuario)
Added:
trunk/frontend-web/skins/default/form_login.html
- copied, changed from r143, /trunk/frontend-web/skins/default/header.html
trunk/frontend-web/skins/default/link_login.html
- copied, changed from r143, /trunk/frontend-web/skins/default/footer.html
trunk/frontend-web/skins/default/link_logout.html
- copied, changed from r143, /trunk/frontend-web/skins/default/footer.html
trunk/frontend-web/url_login.py
- copied, changed from r143, /trunk/frontend-web/url_LOGIN.py
Modified:
trunk/frontend-web/globales.py
trunk/frontend-web/skins.py
trunk/frontend-web/skins/default/footer.html
trunk/frontend-web/url_.py
trunk/frontend-web/url_INVALIDA.py
trunk/frontend-web/url_hilo.py
trunk/frontend-web/url_indice.py
trunk/frontend-web/url_nuevo_usuario.py
trunk/frontend-web/url_nuevo_usuario_POST.py
trunk/frontend-web/url_stop.py
Modified: trunk/frontend-web/globales.py
==============================================================================
--- trunk/frontend-web/globales.py (original)
+++ trunk/frontend-web/globales.py Tue Jun 12 02:27:48 2007
@@ -16,5 +16,4 @@
thread_len=10
# Permitimos el acceso anonimo al foro
-allow_anonymous=False
-
+allow_anonymous=True
Modified: trunk/frontend-web/skins.py
==============================================================================
--- trunk/frontend-web/skins.py (original)
+++ trunk/frontend-web/skins.py Tue Jun 12 02:27:48 2007
@@ -23,6 +23,9 @@
'thread_unread': 'body_threadlist_thread_unread.html',
'thread': 'body_threadlist_thread.html',
'group_date': 'body_threadlist_group.html',
+ 'link_logout': 'link_logout.html',
+ 'link_login': 'link_login.html',
+ 'form_login': 'form_login.html',
'footer': 'footer.html'
}
@@ -31,6 +34,7 @@
'/indice': ['group_date', 'threads', 'threads'],
'/hilo': ['thread_entries'],
'/nuevo_usuario': ['new_user'],
+ '/login': ['login'],
'/error': [],
'/stop': [],
'/nuevo_usuario_POST': []
@@ -56,18 +60,25 @@
class Skin:
- def __init__(self):
+ def __init__(self,url,user=None):
import pytz
- self._tz=pytz.timezone("Europe/Madrid")
- self._skin="default"
- self._url=""
- self._style=["odd","even"]
+ self._tz = pytz.timezone("Europe/Madrid")
+ self._skin = "default"
+ self._path = url
+ self._url = "/%s" % url[0]
+ self._style = ["odd","even"]
self._text = []
- self._dict={
+ self._dict = {
"version": globales.version,
"page_title": "cpif",
+ "user": user,
+ "generic_message": "Algo va mal",
"calendar":""
}
+ if user:
+ self._dict["auth"] = available_skins[self._skin]["link_logout"] % { "link_auth": "/logout", "user":user }
+ else:
+ self._dict["auth"] = available_skins[self._skin]["link_login"] % { "link_auth": "/login/%s" % "/".join(self._path) if self._path else "/login" }
def set_skin(self,skin):
if skin in available_skins:
@@ -76,7 +87,8 @@
return None
def load_url(self,url):
- self._url="/%s" % url[0]
+ self._url = "/%s" % url[0]
+ self._path = url
def load_dict(self,d):
for key,val in d.iteritems():
@@ -166,8 +178,11 @@
self._dict["link_new_post"] = "/nuevo_post_POST/%d/%d" %(metatag,self._dict["msg_num"])
self._dict["link_metatag"] = "/indice/%d" % metatag
aux = available_skins[self._skin]['body_thread']
+ elif "login" in urls[self._url]:
+ aux = available_skins[self._skin]['generic'] % { "body": available_skins[self._skin]['form_login']}
+ self._dict["link_form_login"] = "/LOGIN/%s" % "/".join(self._path[1:])
elif "new_user" in urls[self._url]:
- aux = available_skins[self._skin]['new_user']
+ aux = available_skins[self._skin]['generic'] % { "body": available_skins[self._skin]['new_user']}
else: # Removed the stop, error, etc urls from there, they (at the moment) are all tall the same
aux = available_skins[self._skin]['generic']
self.set_text(self._dict.get('generic_message',None))
Modified: trunk/frontend-web/skins/default/footer.html
==============================================================================
--- trunk/frontend-web/skins/default/footer.html (original)
+++ trunk/frontend-web/skins/default/footer.html Tue Jun 12 02:27:48 2007
@@ -1,4 +1,4 @@
-<p><a href="/logout">LOG OUT</a>
+%(auth)s
<p><a href="/nuevo_usuario">Dar de alta un nuevo usuario</a>
<p><a href="/stop">Parar la demo</a>
<p align=right>Version: %(version)d</p>
Copied: trunk/frontend-web/skins/default/form_login.html (from r143, /trunk/frontend-web/skins/default/header.html)
==============================================================================
--- /trunk/frontend-web/skins/default/header.html (original)
+++ trunk/frontend-web/skins/default/form_login.html Tue Jun 12 02:27:48 2007
@@ -1,10 +1,7 @@
-<html>
- <head>
- <title>%(page_title)s</title>
- <style>
- .even {background-color: efe}
- .odd {background-color: eef}
- </style>
- </head>
- <body>
- <h1>CPIF - La madre de todos los foros</h1>
+<form action="%(link_form_login)s" 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="clave" size="25" value="" /></td></tr>
+ <tr><td colspan=2 align=right><input class="form-element" type="submit" name="submit" value="Log In"/></td></tr>
+ </table>
+</form>
Copied: trunk/frontend-web/skins/default/link_login.html (from r143, /trunk/frontend-web/skins/default/footer.html)
==============================================================================
--- /trunk/frontend-web/skins/default/footer.html (original)
+++ trunk/frontend-web/skins/default/link_login.html Tue Jun 12 02:27:48 2007
@@ -1,6 +1 @@
-<p><a href="/logout">LOG OUT</a>
-<p><a href="/nuevo_usuario">Dar de alta un nuevo usuario</a>
-<p><a href="/stop">Parar la demo</a>
-<p align=right>Version: %(version)d</p>
-</body>
-</html>
+<p><a href="%(link_auth)s">LOGIN</a>
Copied: trunk/frontend-web/skins/default/link_logout.html (from r143, /trunk/frontend-web/skins/default/footer.html)
==============================================================================
--- /trunk/frontend-web/skins/default/footer.html (original)
+++ trunk/frontend-web/skins/default/link_logout.html Tue Jun 12 02:27:48 2007
@@ -1,6 +1 @@
-<p><a href="/logout">LOG OUT</a>
-<p><a href="/nuevo_usuario">Dar de alta un nuevo usuario</a>
-<p><a href="/stop">Parar la demo</a>
-<p align=right>Version: %(version)d</p>
-</body>
-</html>
+<p><a href="%(link_auth)s">LOGOUT (%(user)s)</a>
Modified: trunk/frontend-web/url_.py
==============================================================================
--- trunk/frontend-web/url_.py (original)
+++ trunk/frontend-web/url_.py Tue Jun 12 02:27:48 2007
@@ -10,8 +10,7 @@
database.actualiza_no_leidos(conn,usuario)
import skins
- pagina = skins.Skin()
- pagina.load_url(path)
+ pagina = skins.Skin(path,usuario)
d = {
"page_title": "cpif - listado de subforos",
Modified: trunk/frontend-web/url_INVALIDA.py
==============================================================================
--- trunk/frontend-web/url_INVALIDA.py (original)
+++ trunk/frontend-web/url_INVALIDA.py Tue Jun 12 02:27:48 2007
@@ -4,9 +4,8 @@
def gestiona_url(handler,path,usuario) :
import skins
- pagina = skins.Skin()
- pagina.load_url(['error'])
- pagina.load_dict({"page_title": "cpif - ERROR"})
- pagina.load_dict({"generic_message": "<h2>ERROR<H2>\r\nLa pagina que buscas no existe, pichón</h2>"})
-
+ pagina = skins.Skin(['error'], usuario)
+ d = {"page_title": "cpif - ERROR",
+ "generic_message": "<h2>ERROR<H2>\r\nLa pagina que buscas no existe, pichón</h2>"}
+ pagina.load_dict(d)
return (pagina.web(404))
Modified: trunk/frontend-web/url_hilo.py
==============================================================================
--- trunk/frontend-web/url_hilo.py (original)
+++ trunk/frontend-web/url_hilo.py Tue Jun 12 02:27:48 2007
@@ -27,8 +27,7 @@
assert len(metatags)==1 # De momento no permitimos multiples metatags para un hilo
metatag=iter(metatags).next()
import skins
- pagina = skins.Skin()
- pagina.load_url(path)
+ pagina = skins.Skin(path,usuario)
d = {
"page_title":"cpif - %s" % meta["titulo"],
Modified: trunk/frontend-web/url_indice.py
==============================================================================
--- trunk/frontend-web/url_indice.py (original)
+++ trunk/frontend-web/url_indice.py Tue Jun 12 02:27:48 2007
@@ -48,8 +48,7 @@
ts=timegm(fecha_max)
import skins
- pagina = skins.Skin()
- pagina.load_url(path)
+ pagina = skins.Skin(path,usuario)
import calendario
d = {
"page_title": "cpif - listado de hilos",
Copied: trunk/frontend-web/url_login.py (from r143, /trunk/frontend-web/url_LOGIN.py)
==============================================================================
--- /trunk/frontend-web/url_LOGIN.py (original)
+++ trunk/frontend-web/url_login.py Tue Jun 12 02:27:48 2007
@@ -3,34 +3,15 @@
from globales import monitor
def gestiona_url(handler,path,usuario) :
- if path[0]=="LOGIN" :
- import cgi,database
- path.pop(0)
- ctype,pdict=cgi.parse_header(handler.headers.getheader('content-type'))
- cuerpo=cgi.FieldStorage(fp=handler.rfile,headers=handler.headers,environ={'REQUEST_METHOD':'POST'},keep_blank_values=1)
- usuario=cuerpo.getfirst("usuario")
- clave=cuerpo.getfirst("clave")
- if usuario and clave :
- @monitor
- def login(conn,usuario,clave) :
- return database.usuario_verifica(conn,nick=usuario,clave=clave)
- resultado=login(usuario,clave)
- if resultado :
- nick,cookie=resultado
- if cookie :
- cookie="cpif_auth=%s; path=/;" %cookie
- return (302,{"Set-Cookie":cookie,"Location":"/"+"/".join(path)},"")
-
- return (200,{"Content-Type":"text/html; charset=utf-8"},
-"""
-<html><head></head>
-<body>
-<form action="/LOGIN/%s" 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="clave" size="25" value="" /></td></tr>
-<tr><td colspan=2 align=right><input class="form-element" type="submit" name="submit" value="Log In"/></td></tr>
-</table>
-</form>
-</body></html>""" % ("/".join(path)) )
-
+ import skins
+ pagina = skins.Skin(path,usuario)
+ if usuario:
+ pagina.load_url(['error'])
+ d = {"page_title": "cpif - ERROR",
+ "generic_message": "<h2>ERROR<H2>\r\nYa logueado</h2>"
+ }
+ else:
+ d = {"page_title": "cpif - LOGIN"}
+
+ pagina.load_dict(d)
+ return(pagina.web())
Modified: trunk/frontend-web/url_nuevo_usuario.py
==============================================================================
--- trunk/frontend-web/url_nuevo_usuario.py (original)
+++ trunk/frontend-web/url_nuevo_usuario.py Tue Jun 12 02:27:48 2007
@@ -5,8 +5,7 @@
def gestiona_url(handler,path,usuario) :
if len(path)!=1 : return None
import skins
- pagina = skins.Skin()
- pagina.load_url(path)
+ pagina = skins.Skin(path,usuario)
pagina.load_dict({"page_title": "cpif - Añadir nuevo usuario"})
if usuario!="master" :
Modified: trunk/frontend-web/url_nuevo_usuario_POST.py
==============================================================================
--- trunk/frontend-web/url_nuevo_usuario_POST.py (original)
+++ trunk/frontend-web/url_nuevo_usuario_POST.py Tue Jun 12 02:27:48 2007
@@ -11,8 +11,7 @@
if len(path)!=1 : return None
import skins
- pagina = skins.Skin()
- pagina.load_url(path)
+ pagina = skins.Skin(path,usuario)
pagina.load_dict({"page_title": "cpif - Alta exitosa"})
if usuario!="master" :
Modified: trunk/frontend-web/url_stop.py
==============================================================================
--- trunk/frontend-web/url_stop.py (original)
+++ trunk/frontend-web/url_stop.py Tue Jun 12 02:27:48 2007
@@ -6,8 +6,7 @@
if len(path)!=1 : return None
import skins
- pagina = skins.Skin()
- pagina.load_url(path)
+ pagina = skins.Skin(path,usuario)
pagina.load_dict({"page_title": "cpif - parando el servicio"})
if usuario!="master" :
More information about the cpif
mailing list