[cpif] r366 - in trunk: . backend frontend-web
svn at argo.es
svn at argo.es
Thu Sep 13 15:33:13 CEST 2007
Author: jcea
Date: Thu Sep 13 15:33:10 2007
New Revision: 366
Log:
Completamos el soporte de zonas horarias. Solo falta
que los usuarios puedan cambiarlas.
Modified:
trunk/TODO
trunk/backend/database.py
trunk/backend/upgrade.py
trunk/frontend-web/globales.py
trunk/frontend-web/skins.py
trunk/frontend-web/url_hilo.py
trunk/frontend-web/url_indice.py
Modified: trunk/TODO
==============================================================================
--- trunk/TODO (original)
+++ trunk/TODO Thu Sep 13 15:33:10 2007
@@ -378,3 +378,6 @@
nunca y que no tienen ningun mensaje privado. El caso evidente
son nuevas altas.
+- 20070913: FRONTAL WEB: Haciendo un "POST" malicioso, se pueden
+ cambiar objetos en "globales.py". Controlarlo.
+
Modified: trunk/backend/database.py
==============================================================================
--- trunk/backend/database.py (original)
+++ trunk/backend/database.py Thu Sep 13 15:33:10 2007
@@ -1,13 +1,15 @@
# $Id$
-VERSION_DB="2007091303"
+VERSION_DB="2007091306"
import globales
# Chanchullo para los "tests"
do_backup_users=True
+timezones={}
+
def normaliza_nick(nick) :
return nick.lower()
@@ -104,6 +106,22 @@
for k,v in conf.items() :
setattr(globales,k,v)
+
+def usuario_get_tz(conn,nick) :
+ root=conn.get_root()
+ usuario=root["usuarios"]["usuarios"].get(normaliza_nick(nick),None)
+ if usuario and ("tz" in usuario) :
+ tz=usuario["tz"]
+ if tz in timezones :
+ tz=timezones[tz]
+ else : # RACES have no bad consecuences
+ import pytz
+ tz=timezones[tz]=pytz.timezone(tz)
+ else :
+ tz=globales.tz
+
+ print (nick,tz)
+ return tz
def usuario_new_cookie(conn,nick) :
root=conn.get_root()
Modified: trunk/backend/upgrade.py
==============================================================================
--- trunk/backend/upgrade.py (original)
+++ trunk/backend/upgrade.py Thu Sep 13 15:33:10 2007
@@ -323,3 +323,25 @@
root["usuarios"]["pending_sign_ins"]=BTree()
conn.commit()
+ if root["version del foro"]=="2007091303" :
+ print "Actualizando la base de datos: 2007091303 -> 2007091304"
+ root["version del foro"]="2007091304"
+ if "jcea" in root["usuarios"]["usuarios"] :
+ root["usuarios"]["usuarios"]["jcea"]["ts"]="Atlantic/Canary"
+ conn.commit()
+
+ if root["version del foro"]=="2007091304" :
+ print "Actualizando la base de datos: 2007091304 -> 2007091305"
+ root["version del foro"]="2007091305"
+ if "jcea" in root["usuarios"]["usuarios"] :
+ del root["usuarios"]["usuarios"]["jcea"]["ts"]
+ root["usuarios"]["usuarios"]["jcea"]["tz"]="Atlantic/Canary"
+ conn.commit()
+
+ if root["version del foro"]=="2007091305" :
+ print "Actualizando la base de datos: 2007091305 -> 2007091306"
+ root["version del foro"]="2007091306"
+ if "jcea" in root["usuarios"]["usuarios"] :
+ del root["usuarios"]["usuarios"]["jcea"]["tz"]
+ conn.commit()
+
Modified: trunk/frontend-web/globales.py
==============================================================================
--- trunk/frontend-web/globales.py (original)
+++ trunk/frontend-web/globales.py Thu Sep 13 15:33:10 2007
@@ -15,4 +15,3 @@
# Global TimeZone
import pytz
tz=pytz.timezone("Europe/Madrid")
-
Modified: trunk/frontend-web/skins.py
==============================================================================
--- trunk/frontend-web/skins.py (original)
+++ trunk/frontend-web/skins.py Thu Sep 13 15:33:10 2007
@@ -116,8 +116,6 @@
class Skin:
def __init__(self,url,user=None,headers={}) :
- from globales import tz
- self._tz = tz
self._skin = "default"
self._path = url
self._url = "/%s" % url[0]
@@ -160,6 +158,7 @@
first_post, num_msgs, messages = self._dict.pop("messages")
thread_num = self._dict.get("thread_num")
metatag = self._dict.get("metatag",None)
+ tz=self._dict["tz"]
for msg_num,author,date,text,avatar in messages:
format = self._style.pop(0)
self._style.append(format)
@@ -181,7 +180,7 @@
avatar = ""
aux = aux % {"msg_num":msg_num, "author":author,
- "date":hourdate(date,self._tz),
+ "date":hourdate(date,tz),
"text":text,"format":format,
"avatar": avatar,
"read only": available_skins[self._skin]["read only"] % icons
@@ -235,6 +234,7 @@
"""Format the thread list"""
threads = ["stickies", "threads"]
metatag = self._dict.get("metatag",None)
+ tz=self._dict["tz"]
thread_len=globales.thread_len
for list_type in threads:
t_list = self._dict.pop(list_type,None)
@@ -242,7 +242,7 @@
if list_type == "stickies":
self.set_text(available_skins[self._skin]['stickies title'])
else:
- self.set_text(available_skins[self._skin]['group_date'] % {'group_date':daydate(date,self._tz)})
+ self.set_text(available_skins[self._skin]['group_date'] % {'group_date':daydate(date,tz)})
for thread, title, ts, nr, nr_point, n_msgs, mon, ro in threads:
format = self._style.pop(0)
self._style.append(format)
@@ -260,7 +260,7 @@
aux = available_skins[self._skin]['thread_unread'] % {"title":title,
"link": "/hilo/%d" %(thread),
"link_notread": "/hilo/%d/%d#m%d" %(thread,page,nr_point),
- "t_date": hourdate(ts,self._tz),
+ "t_date": hourdate(ts,tz),
"format": format,
"not_read": nr_point,
"t_replies": n_msgs,
@@ -270,11 +270,9 @@
"sticky": sticky,
}
else:
- print read_only
- print sticky
aux = available_skins[self._skin]['thread'] % {"title":title,
"link": "/hilo/%d" %thread,
- "t_date":hourdate(ts,self._tz),
+ "t_date":hourdate(ts,tz),
"format": format,
"t_replies": n_msgs,
"mon":mon,
@@ -284,7 +282,7 @@
else:
aux = available_skins[self._skin]['thread_anonymous'] % {"title":title,
"link": "/hilo/%d" %thread,
- "t_date":hourdate(ts,self._tz),
+ "t_date":hourdate(ts,tz),
"format": format,
"t_replies": n_msgs,
"read only": read_only,
Modified: trunk/frontend-web/url_hilo.py
==============================================================================
--- trunk/frontend-web/url_hilo.py (original)
+++ trunk/frontend-web/url_hilo.py Thu Sep 13 15:33:10 2007
@@ -39,6 +39,7 @@
"metatag_title": metatag[1],
"monitor": mon,
"read only": meta["read only"],
+ "tz": database.usuario_get_tz(conn,usuario) # Also valid if anonymous
}
pagina.load_dict(d)
Modified: trunk/frontend-web/url_indice.py
==============================================================================
--- trunk/frontend-web/url_indice.py (original)
+++ trunk/frontend-web/url_indice.py Thu Sep 13 15:33:10 2007
@@ -43,8 +43,10 @@
fecha_elegida=fecha
fecha_max=fecha+delta_dia # Empezamos a listar los hilos escritos desde las 0:00 de "man~ana"
+
+ tz=database.usuario_get_tz(conn,usuario) # Also valid if anonymous
+
def timegm(fecha) :
- tz=globales.tz
dt=tz.localize(datetime.datetime.combine(fecha,medianoche))
return calendar.timegm(dt.utctimetuple())
ts=timegm(fecha_max)
@@ -59,7 +61,8 @@
"calendar": calendario.vista_mensual(conn,fecha_elegida,usuario,metatag),
"metatag": metatag,
"monitor": database.monitored_metatag(conn,usuario,metatag),
- "user": usuario
+ "user": usuario,
+ "tz": tz,
}
root=conn.get_root()
More information about the cpif
mailing list