annotate SrvTxtUtils.py @ 265:9adba5461dfa new_pro_struct

167: Title of projects' info blocks can't be changed Task-Url: https://it-dev.mpiwg-berlin.mpg.de/tracs/webpage/ticket/167
author casties
date Mon, 25 Aug 2014 17:45:51 +0200
parents 649f74b167e6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
1 """Utility methods for handling XML, reading HTTP, etc"""
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
2
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
3 from App.ImageFile import ImageFile
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
4 from App.Common import rfc1123_date
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
5
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
6 import sys
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
7 import os
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
8 import stat
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
9 import urllib
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
10 import logging
65
63184d71c014 lots of cleaning up.
casties
parents: 49
diff changeset
11 import time
188
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
12 import re
216
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
13 import datetime
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
14 try:
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
15 import httplib2
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
16 httplib = 'httplib2'
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
17 except:
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
18 logging.warn("Unable to import httplib2! Falling back to urllib2!")
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
19 import urllib2
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
20 httplib = 'urllib2'
0
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
21
49
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
22 import xml.etree.ElementTree as ET
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
23
231
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
24 srvTxtUtilsVersion = "1.12.3"
0
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
25
16
54f135c1ed65 updated MPIWGFeature.
casties
parents: 0
diff changeset
26 map_months = {'en': [u"",
231
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
27 u"January",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
28 u"February",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
29 u"March",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
30 u"April",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
31 u"May",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
32 u"June",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
33 u"July",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
34 u"August",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
35 u"September",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
36 u"October",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
37 u"November",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
38 u"December"],
16
54f135c1ed65 updated MPIWGFeature.
casties
parents: 0
diff changeset
39 'de': [u"",
231
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
40 u"Januar",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
41 u"Februar",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
42 u"M\u00e4rz",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
43 u"April",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
44 u"Mai",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
45 u"Juni",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
46 u"Juli",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
47 u"August",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
48 u"September",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
49 u"Oktober",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
50 u"November",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
51 u"Dezember"]}
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
52
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
53 map_weekdays_short = {'en': [
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
54 u"Mo",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
55 u"Tu",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
56 u"We",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
57 u"Th",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
58 u"Fr",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
59 u"Sa",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
60 u"Su",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
61 ],
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
62 'de': [
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
63 u"Mo",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
64 u"Di",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
65 u"Mi",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
66 u"Do",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
67 u"Fr",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
68 u"Sa",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
69 u"So",
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
70 ]}
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
71
0
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
72
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
73 def getInt(number, default=0):
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
74 """returns always an int (0 in case of problems)"""
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
75 try:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
76 return int(number)
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
77 except:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
78 return int(default)
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
79
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
80 def getAt(array, idx, default=None):
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
81 """returns element idx from array or default (in case of problems)"""
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
82 try:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
83 return array[idx]
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
84 except:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
85 return default
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
86
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
87 def unicodify(s):
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
88 """decode str (utf-8 or latin-1 representation) into unicode object"""
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
89 if not s:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
90 return u""
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
91 if isinstance(s, str):
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
92 try:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
93 return s.decode('utf-8')
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
94 except:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
95 return s.decode('latin-1')
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
96 else:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
97 return s
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
98
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
99 def utf8ify(s):
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
100 """encode unicode object or string into byte string in utf-8 representation.
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
101 assumes string objects to be utf-8"""
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
102 if not s:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
103 return ""
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
104 if isinstance(s, str):
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
105 return s
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
106 else:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
107 return s.encode('utf-8')
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
108
231
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
109
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
110 def getTextFromNode(node, recursive=False, length=0):
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
111 """Return all text content of a (etree) node.
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
112
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
113 :param recursive: descend subnodes
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
114
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
115 :returns: text string
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
116 """
0
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
117 if node is None:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
118 return ''
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
119
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
120 # ElementTree:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
121 text = node.text or ''
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
122 for e in node:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
123 if recursive:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
124 text += getText(e)
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
125 else:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
126 text += e.text or ''
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
127 if e.tail:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
128 text += e.tail
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
129
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
130 # 4Suite:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
131 #nodelist=node.childNodes
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
132 #text = ""
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
133 #for n in nodelist:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
134 # if n.nodeType == node.TEXT_NODE:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
135 # text = text + n.data
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
136
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
137 return text
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
138
231
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
139 getText = getTextFromNode
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
140
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
141 def getPlaintext(text, length=0, wordwrap=False, ignoretags=[]):
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
142 """Return plain text content by filtering out XML tags.
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
143
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
144 :param text: string or etree node
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
145 :param length: length of text to return (0=all)
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
146 :param wordwrap: try not to break the last word (may return shorter string)
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
147 :returns: text string
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
148 """
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
149 if text is None:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
150 return ''
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
151
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
152 try:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
153 if isinstance(text, basestring):
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
154 xmltext = utf8ify("<div>%s</div>"%text)
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
155 dom = ET.fromstring(xmltext)
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
156 else:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
157 dom = text
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
158
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
159 plaintext = ''
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
160 for elem in dom.iter():
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
161 if elem.tag in ignoretags:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
162 # ignore tag
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
163 continue
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
164
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
165 if elem.text:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
166 plaintext += elem.text
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
167 if elem.tail:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
168 plaintext += elem.tail
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
169
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
170 if length > 0 and len(plaintext) > length:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
171 break
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
172
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
173 text = plaintext
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
174
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
175 except Exception, e:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
176 logging.warn("getPlaintext: error parsing text! Returning everything. %s"%e)
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
177
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
178 if length > 0 and len(text) > length:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
179 # try to not break words
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
180 if wordwrap and text[length] not in [' ', '.', '?', '!']:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
181 # search the last blank
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
182 length = text.rfind(' ', 0, length)
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
183
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
184 return text[:length] + '...'
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
185
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
186 return text
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
187
49
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
188
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
189 def serialize(node):
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
190 """returns a string containing an XML snippet of (etree) node"""
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
191 s = ET.tostring(node, 'UTF-8')
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
192 # snip off XML declaration
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
193 if s.startswith('<?xml'):
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
194 i = s.find('?>')
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
195 return s[i+3:]
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
196
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
197 return s
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
198
e40ff9829108 improved old project inline image handling.
casties
parents: 16
diff changeset
199
16
54f135c1ed65 updated MPIWGFeature.
casties
parents: 0
diff changeset
200 def getMonthName(mon, lang):
54f135c1ed65 updated MPIWGFeature.
casties
parents: 0
diff changeset
201 """returns the name of the month mon in the language lang"""
231
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
202 return map_months[lang.lower()][mon]
0
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
203
87
77f2478ae971 getDateString method to format dates in English and German.
casties
parents: 65
diff changeset
204
231
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
205 def getWeekdayName(day, lang, short=True):
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
206 """returns the name of the weekday day in the language lang"""
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
207 return map_weekdays_short[lang.lower()][day]
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
208
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
209
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
210 def getDateString(date=None, lang='en', short=False, withYear=True, monthNames=True, abbrev=False):
87
77f2478ae971 getDateString method to format dates in English and German.
casties
parents: 65
diff changeset
211 """Return formatted date string."""
170
485bf377913a fix staff editing pages.
casties
parents: 137
diff changeset
212 if date is None:
485bf377913a fix staff editing pages.
casties
parents: 137
diff changeset
213 return None
485bf377913a fix staff editing pages.
casties
parents: 137
diff changeset
214
87
77f2478ae971 getDateString method to format dates in English and German.
casties
parents: 65
diff changeset
215 ds = None
126
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
216 if callable(date.day):
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
217 # callable members
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
218 day = date.day()
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
219 month = date.month()
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
220 year = date.year()
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
221 else:
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
222 # data members
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
223 day = date.day
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
224 month = date.month
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
225 year = date.year
2e2dd6a5ab26 cleanups and fixed getDateString.
casties
parents: 87
diff changeset
226
87
77f2478ae971 getDateString method to format dates in English and German.
casties
parents: 65
diff changeset
227 if lang.lower() == 'en':
231
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
228 if short:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
229 ds = "%s/%s/%s"%(year,month,day)
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
230 else:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
231 ds = "%s %s"%(getMonthName(month, lang), day)
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
232 if withYear:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
233 ds += ", %s"%year
137
e0b343cee9dd cleanup.
casties
parents: 126
diff changeset
234
e0b343cee9dd cleanup.
casties
parents: 126
diff changeset
235 elif lang.lower() == 'de':
231
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
236 if short:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
237 ds = "%s.%s.%s"%(day,month,year)
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
238 else:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
239 ds = "%s. %s"%(day, getMonthName(month, lang))
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
240 if withYear:
649f74b167e6 extract getPlaintext to SrvTxtUtils. add character count to project description editor.
casties
parents: 216
diff changeset
241 ds += " %s"%year
137
e0b343cee9dd cleanup.
casties
parents: 126
diff changeset
242
e0b343cee9dd cleanup.
casties
parents: 126
diff changeset
243 elif lang.lower() == 'iso':
e0b343cee9dd cleanup.
casties
parents: 126
diff changeset
244 ds = date.isoformat()
87
77f2478ae971 getDateString method to format dates in English and German.
casties
parents: 65
diff changeset
245
77f2478ae971 getDateString method to format dates in English and German.
casties
parents: 65
diff changeset
246 return ds
77f2478ae971 getDateString method to format dates in English and German.
casties
parents: 65
diff changeset
247
77f2478ae971 getDateString method to format dates in English and German.
casties
parents: 65
diff changeset
248
216
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
249 def getDate(date):
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
250 """return date object from date or datetime date."""
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
251 if isinstance(date, datetime.datetime):
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
252 # strip time
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
253 return date.date()
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
254
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
255 return date
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
256
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
257
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
258 def getDatetime(date):
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
259 """return datetime object from date or datetime date."""
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
260 if isinstance(date, datetime.date):
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
261 # add time 0:00
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
262 return datetime.datetime.combine(date, datetime.time())
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
263
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
264 return date
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
265
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
266
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
267 def getHttpData(url, data=None, num_tries=3, timeout=10, username=None, password=None, cache=None, insecure=False, noExceptions=False):
0
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
268 """returns result from url+data HTTP request"""
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
269 # we do GET (by appending data to url)
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
270 if isinstance(data, str) or isinstance(data, unicode):
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
271 # if data is string then append
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
272 url = "%s?%s"%(url,data)
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
273 elif isinstance(data, dict) or isinstance(data, list) or isinstance(data, tuple):
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
274 # urlencode
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
275 url = "%s?%s"%(url,urllib.urlencode(data))
216
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
276
0
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
277 errmsg = None
216
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
278 if httplib == 'httplib2':
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
279 # use httplib2
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
280 for cnt in range(num_tries):
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
281 try:
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
282 logging.debug("getHttp(lib2)Data(#%s %ss) url=%s"%(cnt+1,timeout,url))
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
283 h = httplib2.Http(cache=cache, timeout=float(timeout), disable_ssl_certificate_validation=insecure)
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
284 if username:
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
285 h.add_credentials(username, password)
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
286
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
287 resp, data = h.request(url)
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
288 return data
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
289
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
290 except httplib2.HttpLib2Error, e:
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
291 logging.error("getHttp(lib2)Data: HTTP error(%s): %s"%(e.code,e))
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
292 errmsg = str(e)
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
293 # stop trying
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
294 break
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
295
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
296 else:
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
297 # use urllib2
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
298 response = None
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
299 for cnt in range(num_tries):
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
300 try:
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
301 logging.debug("getHttpData(#%s %ss) url=%s"%(cnt+1,timeout,url))
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
302 if sys.version_info < (2, 6):
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
303 # set timeout on socket -- ugly :-(
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
304 import socket
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
305 socket.setdefaulttimeout(float(timeout))
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
306 response = urllib2.urlopen(url)
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
307 else:
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
308 # timeout as parameter
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
309 response = urllib2.urlopen(url,timeout=float(timeout))
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
310 # check result?
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
311 data = response.read()
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
312 response.close()
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
313 return data
0
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
314
216
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
315 except urllib2.HTTPError, e:
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
316 logging.error("getHttpData: HTTP error(%s): %s"%(e.code,e))
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
317 errmsg = str(e)
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
318 # stop trying
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
319 break
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
320 except urllib2.URLError, e:
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
321 logging.error("getHttpData: URLLIB error(%s): %s"%(e.reason,e))
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
322 errmsg = str(e)
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
323 # stop trying
3b517b412f77 fixed problem updating users with new IDs
casties
parents: 207
diff changeset
324 #break
0
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
325
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
326 if noExceptions:
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
327 return None
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
328
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
329 raise IOError("ERROR fetching HTTP data from %s: %s"%(url,errmsg))
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
330 #return None
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
331
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
332
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
333 def refreshingImageFileIndexHtml(self, REQUEST, RESPONSE):
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
334 """index_html method for App.ImageFile that updates the file info for each request."""
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
335 stat_info = os.stat(self.path)
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
336 self.size = stat_info[stat.ST_SIZE]
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
337 self.lmt = float(stat_info[stat.ST_MTIME]) or time.time()
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
338 self.lmh = rfc1123_date(self.lmt)
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
339 # call original method
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
340 return ImageFile.index_html(self, REQUEST, RESPONSE)
bca61e893fcc first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff changeset
341
65
63184d71c014 lots of cleaning up.
casties
parents: 49
diff changeset
342
63184d71c014 lots of cleaning up.
casties
parents: 49
diff changeset
343 def shortenString(s, l, ellipsis='...'):
63184d71c014 lots of cleaning up.
casties
parents: 49
diff changeset
344 """returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis."""
207
938add25f81b export shortenString to web
casties
parents: 188
diff changeset
345 if len(s) <= l:
938add25f81b export shortenString to web
casties
parents: 188
diff changeset
346 return s
938add25f81b export shortenString to web
casties
parents: 188
diff changeset
347
65
63184d71c014 lots of cleaning up.
casties
parents: 49
diff changeset
348 l1 = int((l - len(ellipsis)) / 2)
63184d71c014 lots of cleaning up.
casties
parents: 49
diff changeset
349 return "%s%s%s"%(s[:l1],ellipsis,s[-l1:])
63184d71c014 lots of cleaning up.
casties
parents: 49
diff changeset
350
188
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
351
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
352 def sqlName(s, lc=True, more=''):
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
353 """returns restricted ASCII-only version of string"""
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
354 if s is None:
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
355 return ""
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
356
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
357 if not isinstance(s, basestring):
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
358 # make string object
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
359 s = str(s)
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
360
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
361 # remove '
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
362 s = s.replace("'","")
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
363 # all else -> "_"
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
364 s = re.sub('[^A-Za-z0-9_'+more+']','_',s)
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
365 if lc:
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
366 return s.lower()
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
367
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
368 return s
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
369
16d55695f1c8 fix updating staff entries through "Update personal homepages". (creating new entries doesn't work)
casties
parents: 170
diff changeset
370