def newline2br(text): chunks = [] for i, line in enumerate(text.split('\n')): if i > 0: chunks.append(HTML.br()) chunks.append(literal(line)) return '\n'.join(chunks)
def newline2br(text): chunks = [] for i, line in enumerate(text.split('\n')): if i > 0: chunks.append(HTML.br()) chunks.append(literal(line)) return '\n'.join(chunks)
def newline2br(text): """Replace newlines in text with HTML br tags.""" if not text: return '' chunks = [] for i, line in enumerate(text.split('\n')): if i > 0: chunks.append(HTML.br()) chunks.append(literal(line)) return '\n'.join(chunks)
def newline2br(text): """Replace newlines in text with HTML br tags.""" if not text: return '' chunks = [] for i, line in enumerate(text.split('\n')): if i > 0: chunks.append(HTML.br()) chunks.append(literal(line)) return '\n'.join(chunks)
def newline2br(text): """ >>> assert newline2br(None) == '' """ if not text: return '' chunks = [] for i, line in enumerate(text.split('\n')): if i > 0: chunks.append(HTML.br()) chunks.append(literal(line)) return '\n'.join(chunks)
def newline2br(text): """ >>> assert newline2br(None) == '' """ if not text: return '' chunks = [] for i, line in enumerate(text.split('\n')): if i > 0: chunks.append(HTML.br()) chunks.append(literal(line)) return '\n'.join(chunks)
def newline2br(text): """Replace newlines in text with HTML br tags. >>> assert newline2br(None) == '' """ if not text: return "" chunks = [] for i, line in enumerate(text.split("\n")): if i > 0: chunks.append(HTML.br()) chunks.append(literal(line)) return "\n".join(chunks)
def format_coordinates(obj, no_seconds=True, wgs_link=True): """Format WGS84 coordinates as HTML. .. seealso:: http://en.wikipedia.org/wiki/ISO_6709#Order.2C_sign.2C_and_units """ def degminsec(dec, hemispheres): _dec = abs(dec) degrees = int(floor(_dec)) _dec = (_dec - int(floor(_dec))) * 60 minutes = int(floor(_dec)) _dec = (_dec - int(floor(_dec))) * 60 seconds = _dec if no_seconds: if seconds > 30: if minutes < 59: minutes += 1 else: minutes = 0 degrees += 1 fmt = "{0}\xb0" if minutes: fmt += "{1:0>2d}'" if not no_seconds and seconds: fmt += '{2:0>2f}"' fmt += hemispheres[0] if dec > 0 else hemispheres[1] return text_type(fmt).format(degrees, minutes, seconds) if not isinstance(obj.latitude, float) or not isinstance(obj.longitude, float): return "" return HTML.div( HTML.table( HTML.tr( HTML.td( "Coordinates ", external_link("http://en.wikipedia.org/wiki/World_Geodetic_System_1984", label="WGS84") if wgs_link else "", ), HTML.td( HTML.span("%s, %s" % (degminsec(obj.latitude, "NS"), degminsec(obj.longitude, "EW"))), HTML.br(), HTML.span("{0.latitude:.2f}, {0.longitude:.2f}".format(obj), class_="geo"), ), ), class_="table table-condensed", ) )
def format_coordinates(obj, no_seconds=True, wgs_link=True): """ WGS84 53° 33' 2" N, 9° 59' 36" E 53.550556°, 9.993333° .. seealso:: http://en.wikipedia.org/wiki/ISO_6709#Order.2C_sign.2C_and_units """ def degminsec(dec, hemispheres): _dec = abs(dec) degrees = int(floor(_dec)) _dec = (_dec - int(floor(_dec))) * 60 minutes = int(floor(_dec)) _dec = (_dec - int(floor(_dec))) * 60 seconds = _dec if no_seconds: if seconds > 30: if minutes < 59: minutes += 1 else: minutes = 0 degrees += 1 fmt = "{0}\xb0" if minutes: fmt += "{1:0>2d}'" if not no_seconds and seconds: fmt += '{2:0>2f}"' fmt += hemispheres[0] if dec > 0 else hemispheres[1] return unicode(fmt).format(degrees, minutes, seconds) if not isinstance(obj.latitude, float) or not isinstance(obj.longitude, float): return '' return HTML.div( HTML.table( HTML.tr( HTML.td( 'Coordinates ', external_link( 'http://en.wikipedia.org/wiki/World_Geodetic_System_1984', label="WGS84") if wgs_link else ''), HTML.td( HTML.span('%s, %s' % ( degminsec(obj.latitude, 'NS'), degminsec(obj.longitude, 'EW'))), HTML.br(), HTML.span( '{0.latitude:.2f}, {0.longitude:.2f}'.format(obj), class_='geo'))), class_="table table-condensed"))
def _media(maintype_, obj, **kw): label = kw.pop('label', None) assert maintype_ in ['audio', 'video'] if maintype(obj) != maintype_: raise ValueError('type mismatch: {0} and {1}'.format(maintype(obj), maintype_)) kw.setdefault('controls', 'controls') media_element = getattr(HTML, maintype_)( literal('Your browser does not support the <code>{0}</code> element.'.format( maintype_)), HTML.source(src=bitstream_url(obj, type_='web'), type=mimetype(obj)), **kw) return HTML.div( media_element, HTML.br(), link(obj, label=label), class_='cdstar_{0}_link'.format(maintype_), style='margin-top: 10px')
def _media(maintype_, obj, **kw): label = kw.pop('label', None) assert maintype_ in ['audio', 'video'] if maintype(obj) != maintype_: raise ValueError('type mismatch: {0} and {1}'.format(maintype(obj), maintype_)) kw.setdefault('controls', 'controls') media_element = getattr(HTML, maintype_)( literal('Your browser does not support the <code>{0}</code> element.'.format( maintype_)), HTML.source(src=bitstream_url(obj, type_='web'), type=mimetype(obj)), **kw) return HTML.div( media_element, HTML.br(), link(obj, label=label), class_='cdstar_{0}_link'.format(maintype_), style='margin-top: 10px')
def format_coordinates(obj, no_seconds=True, wgs_link=True): """ WGS84 53° 33' 2" N, 9° 59' 36" E 53.550556°, 9.993333° .. seealso:: http://en.wikipedia.org/wiki/ISO_6709#Order.2C_sign.2C_and_units """ def degminsec(dec, hemispheres): _dec = abs(dec) degrees = int(floor(_dec)) _dec = (_dec - int(floor(_dec))) * 60 minutes = int(floor(_dec)) _dec = (_dec - int(floor(_dec))) * 60 seconds = _dec if no_seconds: if seconds > 30: if minutes < 59: minutes += 1 else: minutes = 0 degrees += 1 fmt = "{0}\xb0" if minutes: fmt += "{1:0>2d}'" if not no_seconds and seconds: fmt += '{2:0>2f}"' fmt += hemispheres[0] if dec > 0 else hemispheres[1] return unicode(fmt).format(degrees, minutes, seconds) if not isinstance(obj.latitude, float) or not isinstance( obj.longitude, float): return '' return HTML.div( HTML.table(HTML.tr( HTML.td( 'Coordinates ', external_link( 'http://en.wikipedia.org/wiki/World_Geodetic_System_1984', label="WGS84") if wgs_link else ''), HTML.td( HTML.span('%s, %s' % (degminsec( obj.latitude, 'NS'), degminsec(obj.longitude, 'EW'))), HTML.br(), HTML.span('{0.latitude:.2f}, {0.longitude:.2f}'.format(obj), class_='geo'))), class_="table table-condensed"))
def ipa_consonants(req, segments): # # a row_spec for a row in the segment chart is a pair (name, segment map), where # segment map maps column index to our internal segment number. # row_specs = [ ( 'plosive/affricate', {1: 1, 2: 5, 7: 7, 8: 9, 9: 24, 10: 80, 11: 25, 12: 27, 13: 11, 14: 12, 15: 13, 16: 14, 17: 2, 18: 17, 19: 75, 20: 76, 21: 18, 22: 19} ), ('aspirated plosive/affricate', {1: 4, 7: 8, 8: 6, 9: 79, 11: 26, 17: 16}), ( 'glottalized stop/affricate', {1: 20, 2: 23, 7: 21, 9: 81, 11: 28, 17: 22, 21: 78} ), ('nasal', {2: 42, 8: 43, 14: 44, 16: 45, 18: 46}), ('trill, tap or flap', {7: 47, 8: 48}), ( 'fricative', { 1: 29, 2: 30, 3: 31, 4: 32, 5: 82, 6: 33, 7: 34, 8: 35, 11: 36, 12: 37, 17: 38, 18: 39, 21: 40, 22: 41} ), ('lateral/approximant', {7: 85, 8: 49, 14: 50, 16: 51, 20: 52}), ] rows = [] for i, spec in enumerate(row_specs): # build the chart row by row name, segment_map = spec cells = [HTML.th(name, class_="row-header")] for j in range(22): if j + 1 in segment_map: title, symbol, class_, p, exists, vs = segments[segment_map[j + 1]] cells.append(HTML.td( parameter_link(req, symbol, vs or p), title=title, class_=class_)) else: cells.append(HTML.td()) rows.append(HTML.tr(*cells)) return HTML.table( HTML.thead( HTML.tr( HTML.td(''), HTML.th(HTML.div('bilabial', class_="vertical"), colspan="2"), HTML.th(HTML.div('labiodental', class_="vertical"), colspan="2"), HTML.th(HTML.div('dental', class_="vertical"), colspan="2"), HTML.th(HTML.div('dental/alveolar', class_="vertical"), colspan="2"), HTML.th( HTML.div( 'dental/alveolar', HTML.br(), 'affricate', class_="vertical"), colspan="2"), HTML.th(HTML.div('palato-alveolar', class_="vertical"), colspan="2"), HTML.th(HTML.div('retroflex', class_="vertical"), colspan="2"), HTML.th(HTML.div('palatal', class_="vertical"), colspan="2"), HTML.th(HTML.div('velar', class_="vertical"), colspan="2"), HTML.th(HTML.div('labial-velar', class_="vertical"), colspan="2"), HTML.th(HTML.div('uvular', class_="vertical")), HTML.th(HTML.div('glottal', class_="vertical")), ), ), HTML.tbody(*rows), style="margin-top: 5em;", )
def ipa_consonants(req, segments): # # a row_spec for a row in the segment chart is a pair (name, segment map), where # segment map maps column index to our internal segment number. # row_specs = [ ('plosive/affricate', { 1: 1, 2: 5, 7: 7, 8: 9, 9: 24, 10: 80, 11: 25, 12: 27, 13: 11, 14: 12, 15: 13, 16: 14, 17: 2, 18: 17, 19: 75, 20: 76, 21: 18, 22: 19 }), ('aspirated plosive/affricate', { 1: 4, 7: 8, 8: 6, 9: 79, 11: 26, 17: 16 }), ('glottalized stop/affricate', { 1: 20, 2: 23, 7: 21, 9: 81, 11: 28, 17: 22, 21: 78 }), ('nasal', { 2: 42, 8: 43, 14: 44, 16: 45, 18: 46 }), ('trill, tap or flap', { 7: 47, 8: 48 }), ('fricative', { 1: 29, 2: 30, 3: 31, 4: 32, 5: 82, 6: 33, 7: 34, 8: 35, 11: 36, 12: 37, 17: 38, 18: 39, 21: 40, 22: 41 }), ('lateral/approximant', { 7: 85, 8: 49, 14: 50, 16: 51, 20: 52 }), ] rows = [] for i, spec in enumerate(row_specs): # build the chart row by row name, segment_map = spec cells = [HTML.th(name, class_="row-header")] for j in range(22): if j + 1 in segment_map: title, symbol, class_, p, exists, vs = segments[segment_map[j + 1]] cells.append( HTML.td(parameter_link(req, symbol, vs or p), title=title, class_=class_)) else: cells.append(HTML.td()) rows.append(HTML.tr(*cells)) return HTML.table( HTML.thead( HTML.tr( HTML.td(''), HTML.th(HTML.div('bilabial', class_="vertical"), colspan="2"), HTML.th(HTML.div('labiodental', class_="vertical"), colspan="2"), HTML.th(HTML.div('dental', class_="vertical"), colspan="2"), HTML.th(HTML.div('dental/alveolar', class_="vertical"), colspan="2"), HTML.th(HTML.div('dental/alveolar', HTML.br(), 'affricate', class_="vertical"), colspan="2"), HTML.th(HTML.div('palato-alveolar', class_="vertical"), colspan="2"), HTML.th(HTML.div('retroflex', class_="vertical"), colspan="2"), HTML.th(HTML.div('palatal', class_="vertical"), colspan="2"), HTML.th(HTML.div('velar', class_="vertical"), colspan="2"), HTML.th(HTML.div('labial-velar', class_="vertical"), colspan="2"), HTML.th(HTML.div('uvular', class_="vertical")), HTML.th(HTML.div('glottal', class_="vertical")), ), ), HTML.tbody(*rows), style="margin-top: 5em;", )