[cpif] r257 - trunk/frontend-web

svn at argo.es svn at argo.es
Wed Jul 11 00:50:40 CEST 2007


Author: heimy
Date: Wed Jul 11 00:50:38 2007
New Revision: 257

Log:
Modificamos calendario para conseguir el comportamiento que tiene jcea

Modified:
   trunk/frontend-web/calendario.py
   trunk/frontend-web/url_indice.py

Modified: trunk/frontend-web/calendario.py
==============================================================================
--- trunk/frontend-web/calendario.py	(original)
+++ trunk/frontend-web/calendario.py	Wed Jul 11 00:50:38 2007
@@ -11,7 +11,7 @@
   from url_indice import fecha_min
   import calendar, datetime
 
-  orig_date = datetime.date(fecha.year, fecha.month, 1)
+  orig_date = fecha.replace(day = 1)
   month=fecha.month
   fecha=(fecha.year,month)
   mes=cache_meses.get(fecha)
@@ -19,22 +19,23 @@
     mes=calendar.Calendar().monthdatescalendar(*fecha)
     date_number = fecha[0] * 100 + month
     today = datetime.date.today()
-    yearmon_min = datetime.date(fecha_min.year, fecha_min.month, 1)
-    yearmon_max = datetime.date(today.year, today.month, 1)
-    prev_y, next_y = (datetime.date(fecha[0] - 1, month, 1),
+    yearmon_min = fecha_min.replace(day = 1)
+    yearmon_max = today.replace(day = 1)
+    delta_1, delta_32 = datetime.timedelta(1), datetime.timedelta(32)
+    prev_m, next_m = (orig_date - delta_1,
+                      (orig_date + delta_32).replace(day = 1))
+    prev_y, next_y = ((datetime.date(fecha[0] - 1, month, 1) + delta_32).replace(day = 1) - delta_1,
                       datetime.date(fecha[0] + 1, month, 1))
+    fecha_str = lambda x: "%04d%02d%02d" % (x.year, x.month, x.day)
     data = {
       "month_name": nombres_meses[fecha[1]].capitalize(),
       "current_year": fecha[0],
       }
-    prev_year_text = '<a href="/indice/%%(metatag)d/%d">&#171;</a>' % (date_number - 100)
-    next_year_text = '<a href="/indice/%%(metatag)d/%d">&#187;</a>' % (date_number + 100)
-    prev_month_text = '<a href="/indice/%%(metatag)d/%d">&lsaquo;</a>' % ((date_number - 1)
-                                                                       if month > 1
-                                                                       else (date_number - 89))
-    next_month_text = '<a href="/indice/%%(metatag)d/%d">&rsaquo;</a>' % ((date_number + 1)
-                                                                       if month < 12
-                                                                       else (date_number + 89))
+    prev_year_text = '<a href="/indice/%%(metatag)d/%s">&#171;</a>' % fecha_str(prev_y)
+    prev_month_text = '<a href="/indice/%%(metatag)d/%s">&lsaquo;</a>' % fecha_str(prev_m)
+    next_month_text = '<a href="/indice/%%(metatag)d/%s">&rsaquo;</a>' % fecha_str(next_m)
+    next_year_text = '<a href="/indice/%%(metatag)d/%s">&#187;</a>' % fecha_str(next_y)
+
     if yearmon_min > prev_y:
         data.update({ 'prev_year':   "&#171;",
                       'prev_month': (prev_month_text

Modified: trunk/frontend-web/url_indice.py
==============================================================================
--- trunk/frontend-web/url_indice.py	(original)
+++ trunk/frontend-web/url_indice.py	Wed Jul 11 00:50:38 2007
@@ -32,16 +32,8 @@
     try :
       fecha_max=fecha
       fecha=path[2]
-      assert len(fecha) == 8 or len(fecha) == 6
-      if len(fecha) == 8:
-        fecha=datetime.date(int(fecha[:4]),int(fecha[4:6]),int(fecha[6:8]))
-      else:
-        yy, mm = int(fecha[:4]), int(fecha[4:6])
-        fecha=(datetime.date(yy, mm + 1, 1) - datetime.timedelta(1)
-               if mm < 12
-               else datetime.date(yy, 12, 31))
-        if fecha > fecha_max and fecha.year == fecha_max.year and fecha.month == fecha_max.month:
-          fecha = fecha_max
+      assert len(fecha) == 8
+      fecha=datetime.date(int(fecha[:4]),int(fecha[4:6]),int(fecha[6:8]))
       if fecha>fecha_max : return None
       if fecha<fecha_min : return None
     except :



More information about the cpif mailing list