[Mpuls-commits] r938 - wasko/branches/2.0/waskaweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jan 27 10:45:42 CET 2010


Author: torsten
Date: 2010-01-27 10:45:41 +0100 (Wed, 27 Jan 2010)
New Revision: 938

Modified:
   wasko/branches/2.0/waskaweb/lib/helpers.py
Log:
* waskaweb/lib/helpers.py: Reordered functions and added some comments


Modified: wasko/branches/2.0/waskaweb/lib/helpers.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/helpers.py	2010-01-27 09:40:50 UTC (rev 937)
+++ wasko/branches/2.0/waskaweb/lib/helpers.py	2010-01-27 09:45:41 UTC (rev 938)
@@ -51,7 +51,37 @@
 
 log = logging.getLogger(__name__)
 
+# Helper functions used in the UI to show some information like status messages
+# or icons
+
+def status_message(s):
+    return "%s: %s" % (format_datetime(datetime.datetime.now()), s)
+
+def get_logouttime():
+    """Estimate log-out time and return it as a formatted string (HH:MM).
+    The estimated logout time is two minutes before the time the session
+    actually expires to make sure it's earlier.
+    """
+    timeout = int(config.get("beaker.session.timeout"))
+    return format_time(datetime.datetime.now()
+                 + datetime.timedelta(seconds=timeout - 120))
+
+def getHelp(help_id):
+    '''
+    Returns a HTML link with a help icon if help is present for help_id. Else
+    return empty string 
+    '''
+    out = []
+    help = g.helpData.getHelp(help_id)
+    if help:
+        out.append('<a href="/annotations/help/%s" target="_blank">' % help_id)
+        out.append('<img src="/images/icons/formular/help.png" alt="help">')
+        out.append('</a>')
+    return "".join(out)
+
+
 # Helper functions to get some information about the logged in user
+
 def getRole():
     try:
         user = session['USER_AUTHORIZED']
@@ -87,6 +117,7 @@
         return ''
 
 # Format functions 
+
 def format_number(number):
     retval = locale.format("%.2f",(number),1)
     return retval
@@ -118,6 +149,45 @@
         log.error(err)
         return dd_mm_yyyy_HH_MM(dt)
 
+def timedelta_in_minutes(ti):
+    if ti is None:
+        return None
+    return round(float(ti.days * (24*60)) + ti.seconds / 60.0)
+
+def timedelta_in_weeks(ti, empty=None):
+    if ti is None:
+        return empty
+    return format_number(float(ti.days) / 7.0 + ti.seconds / (60.0 * 24.0 * 7.0))
+
+def human_timedelta(td, empty=None):
+    if td is None:
+        return empty
+    out = []
+    if -td == abs(td):
+        out.append("-")
+        td = -td
+    days = td.days
+    if days == 1:
+        out.append("1 Tag,")
+    if days > 1:
+        out.append("%d Tage," % days)
+
+    secs  = td.seconds
+    hours = secs / 3600
+    secs -= hours * 3600
+    mins  = secs / 60
+    secs -= mins * 60
+
+    out.append("%d:%02d:%02d" % (hours, mins, secs))
+
+    return " ".join(out)
+
+
+# Fallback functions for the localized format_* functions. If localalisation
+# fails because of dates before 1900 (which aren't sensefull anyway') the
+# fallback functions are called. These functions will convert dates and time in
+# german date and time formats  
+
 def dd_mm_YYYY(d, empty=''):
     """Format the date of the date/time object d as 'dd.mm.YYYY'.
     The parameter d may be a string or a datetime instance.  If d is
@@ -159,65 +229,8 @@
         return empty
     return dd_mm_YYYY(d) + " " + HH_MM(d)
 
-def status_message(s):
-    return "%s: %s" % (format_datetime(datetime.datetime.now()), s)
+# Phases helpers. Used in evaluation
 
-def get_logouttime():
-    """Estimate log-out time and return it as a formatted string (HH:MM).
-    The estimated logout time is two minutes before the time the session
-    actually expires to make sure it's earlier.
-    """
-    timeout = int(config.get("beaker.session.timeout"))
-    return format_time(datetime.datetime.now()
-                 + datetime.timedelta(seconds=timeout - 120))
-
-def timedelta_in_minutes(ti):
-    if ti is None:
-        return None
-    return round(float(ti.days * (24*60)) + ti.seconds / 60.0)
-
-def timedelta_in_weeks(ti, empty=None):
-    if ti is None:
-        return empty
-    return format_number(float(ti.days) / 7.0 + ti.seconds / (60.0 * 24.0 * 7.0))
-
-def human_timedelta(td, empty=None):
-    if td is None:
-        return empty
-    out = []
-    if -td == abs(td):
-        out.append("-")
-        td = -td
-    days = td.days
-    if days == 1:
-        out.append("1 Tag,")
-    if days > 1:
-        out.append("%d Tage," % days)
-
-    secs  = td.seconds
-    hours = secs / 3600
-    secs -= hours * 3600
-    mins  = secs / 60
-    secs -= mins * 60
-
-    out.append("%d:%02d:%02d" % (hours, mins, secs))
-
-    return " ".join(out)
-
-def getHelp(help_id):
-    '''
-    Returns a HTML link with a help icon if help is present for help_id. Else
-    return empty string 
-    '''
-    out = []
-    help = g.helpData.getHelp(help_id)
-    if help:
-        out.append('<a href="/annotations/help/%s" target="_blank">' % help_id)
-        out.append('<img src="/images/icons/formular/help.png" alt="help">')
-        out.append('</a>')
-    return "".join(out)
-
-# Phases helpers. Used in evaluation
 def get_phasesuccessors(p):
     #p = int(p)
     phasesuc = []



More information about the Mpuls-commits mailing list