Changeset 620:a71ae589d342 in documentViewer


Ignore:
Timestamp:
Dec 11, 2014, 4:19:45 PM (9 years ago)
Author:
casties
Branch:
default
Message:

use https for annotations and fix bug when logging httplib errors.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • SrvTxtUtils.py

    r614 r620  
    1111import time
    1212import re
    13 import string
    1413import datetime
    1514try:
     
    2322import xml.etree.ElementTree as ET
    2423
    25 srvTxtUtilsVersion = "1.12.2"
     24srvTxtUtilsVersion = "1.12.3"
    2625
    2726map_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"],
    4039              '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
     53map_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
    5372
    5473def getInt(number, default=0):
     
    85104    if isinstance(s, str):
    86105        return s
    87     elif isinstance(s, unicode):
     106    else:
    88107        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
     110def 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    """
    94117    if node is None:
    95118        return ''
     
    114137    return text
    115138
     139getText = getTextFromNode
     140
     141def 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
    116188
    117189def serialize(node):
     
    128200def getMonthName(mon, lang):
    129201    """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
     205def 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
     210def getDateString(date=None, lang='en', short=False, withYear=True, monthNames=True, abbrev=False):
    134211    """Return formatted date string."""
    135212    if date is None:
     
    149226       
    150227    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
    154234           
    155235    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
    159242
    160243    elif lang.lower() == 'iso':
     
    206289           
    207290            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))
    209292                errmsg = str(e)
    210293                # stop trying
     
    286369
    287370
    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'] = ua
    293     bt['isIE'] = False
    294     bt['isN4'] = False
    295     if string.find(ua, 'MSIE') > -1:
    296         bt['isIE'] = True
    297     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: pass
    306    
    307     bt['isMac'] = string.find(ua, 'Macintosh') > -1
    308     bt['isWin'] = string.find(ua, 'Windows') > -1
    309     bt['isIEWin'] = bt['isIE'] and bt['isWin']
    310     bt['isIEMac'] = bt['isIE'] and bt['isMac']
    311     bt['staticHTML'] = False
    312 
    313     return bt
    314 
  • zpt/viewer/layer_text_annotator.zpt

    r619 r620  
    2828
    2929  <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;
    3131    annUrl python:'http://echo.mpiwg-berlin.mpg.de/documents%s?pn=%s'%(docinfo['documentPath'],pageinfo['pn']);
    3232    resUrl python:'http://echo.mpiwg-berlin.mpg.de/documents%s'%(docinfo['documentPath']);
Note: See TracChangeset for help on using the changeset viewer.