You are here:   » Home » Documentation » Details » ZMS API » acc. to Objects » _zmsglobals

_zmsglobals.ZMSGlobals

Author: D. Nordmann, 2002/12/13

General functions are defined in class ZMSGlobals.

ZMSGlobals.rand_int(n)

BESCHREIBUNG:
Generates a random number between 0 and n-1.

EINGABE-PARAMETER:
n: the basis of the value area

AUSGABE-PARAMETER:
int: the random number

BEISPIELE
[1]  Selects a random image from a folder and displays it:
  <dtml-let imgs="objectValues(['Image'])">
    <img src="<dtml-var "imgs[rand_int(_.len(imgs))].absolute_url()">
  </dtml-let>


_zmsglobals.url_append_params(url, dict)

BESCHREIBUNG:
The function attaches the parameters stated by dict to the stated URL. The parameters are attached with & (resp. ?) to the URL according to url-encoded.
So e.g. url_append_params('http://host/path/index.html?lang=ger',{'par1':'val1','par2':'val2'}) delivers back the string 'http://host/path/index.html?lang=ger&par1=var1&par2=var2'.

EINGABE-PARAMETER:
url[url]: the URL
dict[dictionary]: the dictionary (Key/Value-pairs) of parameters

AUSGABE-PARAMETER:
url[url]: the URL enhanced with the stated parameters

BEISPIELE
[1]  Attaches the current date through the parameters year, month and day to the target-URL:
 <dtml-let dt="ZopeTime()">
  <a href="<dtml-var "url_append_params(
     getHref2IndexHtml(REQUEST),
     {'year:int':dt.year()
     ,'month:int':dt.month()
     ,'day:int':dt.day()
    })">">
   <dtml-var "getTitle(REQUEST)">
  </a>
 </dtml-let>
[2]  Attaches the ID of the authenticated user to the current URL:
  <a href="<dtml-var "url_append_params(
     URL,
     {'auth_user':_.str(AUTHENTICATED_USER)
    })">">
   Edit profile
  </a>


ZMSGlobals.url_quote(s)

BESCHREIBUNG:
The function converts characters having a special meaning in URLs to HTML character-entities as decimal values.
So e.g. the string 'Hello World!' is convered to 'Hello%20World!'.

EINGABE-PARAMETER:
s: the URL-string

AUSGABE-PARAMETER:
string: the converted URL-string

BEISPIELE
[1]  Gives over title as URL-parameter to the DTML-method <<index_html>>:
  <a href="index_html?title=<dtml-var "url_quote(getTitle(REQUEST))">">


ZMSGlobals.string_list(s, sep='\\n')

BESCHREIBUNG:
Converts a string to a list. the list elements are seperated in the string by the stated delimiter (e.g. '\\n' for CR).

EINGABE-PARAMETER:
s[string]: the string
sep[string]='\\n': the delimiter of the list elements

AUSGABE-PARAMETER:
items[list]: list


ZMSGlobals.string_maxlen(s, maxlen=20)

BESCHREIBUNG:
Limits a string to the stated maximum length. Longer strings are cut and provided with "···".

EINGABE-PARAMETER:
s[string]: the string
maxlen[int]: the maximum length of the new string

AUSGABE-PARAMETER:
s[string]: the new string


Table of contents: