Changeset 620:a71ae589d342 in documentViewer
- Timestamp:
- Dec 11, 2014, 4:19:45 PM (10 years ago)
- Branch:
- default
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
SrvTxtUtils.py
r614 r620 11 11 import time 12 12 import re 13 import string14 13 import datetime 15 14 try: … … 23 22 import xml.etree.ElementTree as ET 24 23 25 srvTxtUtilsVersion = "1.12. 2"24 srvTxtUtilsVersion = "1.12.3" 26 25 27 26 map_months = {'en': [u"", 28 u"January",29 u"February",30 u"March",31 u"April",32 u"May",33 u"June",34 u"July",35 u"August",36 u"September",37 u"October",38 u"November",39 u"December"],27 u"January", 28 u"February", 29 u"March", 30 u"April", 31 u"May", 32 u"June", 33 u"July", 34 u"August", 35 u"September", 36 u"October", 37 u"November", 38 u"December"], 40 39 'de': [u"", 41 u"Januar", 42 u"Februar", 43 u"M\u00e4rz", 44 u"April", 45 u"Mai", 46 u"Juni", 47 u"Juli", 48 u"August", 49 u"September", 50 u"Oktober", 51 u"November", 52 u"Dezember"]} 40 u"Januar", 41 u"Februar", 42 u"M\u00e4rz", 43 u"April", 44 u"Mai", 45 u"Juni", 46 u"Juli", 47 u"August", 48 u"September", 49 u"Oktober", 50 u"November", 51 u"Dezember"]} 52 53 map_weekdays_short = {'en': [ 54 u"Mo", 55 u"Tu", 56 u"We", 57 u"Th", 58 u"Fr", 59 u"Sa", 60 u"Su", 61 ], 62 'de': [ 63 u"Mo", 64 u"Di", 65 u"Mi", 66 u"Do", 67 u"Fr", 68 u"Sa", 69 u"So", 70 ]} 71 53 72 54 73 def getInt(number, default=0): … … 85 104 if isinstance(s, str): 86 105 return s 87 el if isinstance(s, unicode):106 else: 88 107 return s.encode('utf-8') 89 else: 90 return str(s) 91 92 def getText(node, recursive=0): 93 """returns all text content of a (etree) node and its subnodes""" 108 109 110 def getTextFromNode(node, recursive=False, length=0): 111 """Return all text content of a (etree) node. 112 113 :param recursive: descend subnodes 114 115 :returns: text string 116 """ 94 117 if node is None: 95 118 return '' … … 114 137 return text 115 138 139 getText = getTextFromNode 140 141 def getPlaintext(text, length=0, wordwrap=False, ignoretags=[]): 142 """Return plain text content by filtering out XML tags. 143 144 :param text: string or etree node 145 :param length: length of text to return (0=all) 146 :param wordwrap: try not to break the last word (may return shorter string) 147 :returns: text string 148 """ 149 if text is None: 150 return '' 151 152 try: 153 if isinstance(text, basestring): 154 xmltext = utf8ify("<div>%s</div>"%text) 155 dom = ET.fromstring(xmltext) 156 else: 157 dom = text 158 159 plaintext = '' 160 for elem in dom.iter(): 161 if elem.tag in ignoretags: 162 # ignore tag 163 continue 164 165 if elem.text: 166 plaintext += elem.text 167 if elem.tail: 168 plaintext += elem.tail 169 170 if length > 0 and len(plaintext) > length: 171 break 172 173 text = plaintext 174 175 except Exception, e: 176 logging.warn("getPlaintext: error parsing text! Returning everything. %s"%e) 177 178 if length > 0 and len(text) > length: 179 # try to not break words 180 if wordwrap and text[length] not in [' ', '.', '?', '!']: 181 # search the last blank 182 length = text.rfind(' ', 0, length) 183 184 return text[:length] + '...' 185 186 return text 187 116 188 117 189 def serialize(node): … … 128 200 def getMonthName(mon, lang): 129 201 """returns the name of the month mon in the language lang""" 130 return map_months[lang][mon] 131 132 133 def getDateString(date=None, lang='en', withYear=True, monthNames=True, abbrev=False): 202 return map_months[lang.lower()][mon] 203 204 205 def getWeekdayName(day, lang, short=True): 206 """returns the name of the weekday day in the language lang""" 207 return map_weekdays_short[lang.lower()][day] 208 209 210 def getDateString(date=None, lang='en', short=False, withYear=True, monthNames=True, abbrev=False): 134 211 """Return formatted date string.""" 135 212 if date is None: … … 149 226 150 227 if lang.lower() == 'en': 151 ds = "%s %s"%(getMonthName(month, lang), day) 152 if withYear: 153 ds += ", %s"%year 228 if short: 229 ds = "%s/%s/%s"%(year,month,day) 230 else: 231 ds = "%s %s"%(getMonthName(month, lang), day) 232 if withYear: 233 ds += ", %s"%year 154 234 155 235 elif lang.lower() == 'de': 156 ds = "%s. %s"%(day, getMonthName(month, lang)) 157 if withYear: 158 ds += " %s"%year 236 if short: 237 ds = "%s.%s.%s"%(day,month,year) 238 else: 239 ds = "%s. %s"%(day, getMonthName(month, lang)) 240 if withYear: 241 ds += " %s"%year 159 242 160 243 elif lang.lower() == 'iso': … … 206 289 207 290 except httplib2.HttpLib2Error, e: 208 logging.error("getHttp(lib2)Data: HTTP error(%s): %s"%( e.code,e))291 logging.error("getHttp(lib2)Data: HTTP error(%s): %s"%(getattr(e, 'code','?'),e)) 209 292 errmsg = str(e) 210 293 # stop trying … … 286 369 287 370 288 def getBrowserType(self):289 """(legacy) check the browsers request to find out the browser type"""290 bt = {}291 ua = self.REQUEST.get_header("HTTP_USER_AGENT")292 bt['ua'] = ua293 bt['isIE'] = False294 bt['isN4'] = False295 if string.find(ua, 'MSIE') > -1:296 bt['isIE'] = True297 else:298 bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1)299 300 try:301 nav = ua[string.find(ua, '('):]302 ie = string.split(nav, "; ")[1]303 if string.find(ie, "MSIE") > -1:304 bt['versIE'] = string.split(ie, " ")[1]305 except: pass306 307 bt['isMac'] = string.find(ua, 'Macintosh') > -1308 bt['isWin'] = string.find(ua, 'Windows') > -1309 bt['isIEWin'] = bt['isIE'] and bt['isWin']310 bt['isIEMac'] = bt['isIE'] and bt['isMac']311 bt['staticHTML'] = False312 313 return bt314 -
zpt/viewer/layer_text_annotator.zpt
r619 r620 28 28 29 29 <script type="text/javascript" 30 tal:define="global annServerUrl string:http ://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager;30 tal:define="global annServerUrl string:https://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager; 31 31 annUrl python:'http://echo.mpiwg-berlin.mpg.de/documents%s?pn=%s'%(docinfo['documentPath'],pageinfo['pn']); 32 32 resUrl python:'http://echo.mpiwg-berlin.mpg.de/documents%s'%(docinfo['documentPath']);
Note: See TracChangeset
for help on using the changeset viewer.