Skip to content

Commit b9ae69d

Browse files
committed
closes #140; more explicit lgcode mapping
1 parent e62468d commit b9ae69d

File tree

3 files changed

+129
-98
lines changed

3 files changed

+129
-98
lines changed
Lines changed: 105 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,121 @@
11
<%inherit file="../${context.get('request').registry.settings.get('clld.app_template', 'app.mako')}"/>
22
<%namespace name="util" file="../util.mako"/>
33
<%! active_menu_item = "sources" %>
4+
<%! multirow = True %>
45
<%! from itertools import groupby %>
56
7+
68
<%block name="title">${ctx.name}</%block>
79
8-
<h3>${ctx.name} ${h.contactmail(req, ctx, title='report a problem')}</h3>
9-
##<abbr class="unapi-id" title="${h.urlescape(request.resource_url(ctx))}"></abbr>
10+
<div class="row-fluid">
11+
<div class="span7">
12+
13+
<h3>${ctx.name} ${h.contactmail(req, ctx, title='report a problem')}</h3>
14+
##<abbr class="unapi-id" title="${h.urlescape(request.resource_url(ctx))}"></abbr>
1015
${ctx.coins(request)|n}
1116
12-
% if ctx.jsondata.get('thanks'):
13-
<div class="alert alert-success">
14-
This record was contributed by ${ctx.jsondata['thanks']}.
15-
</div>
16-
% endif
17+
% if ctx.jsondata.get('thanks'):
18+
<div class="alert alert-success">
19+
This record was contributed by ${ctx.jsondata['thanks']}.
20+
</div>
21+
% endif
1722
18-
<div class="tabbable">
19-
<ul class="nav nav-tabs">
20-
<li class="active"><a href="#tab1" data-toggle="tab">Text</a></li>
21-
<li><a href="#tab2" data-toggle="tab">BibTeX</a></li>
22-
</ul>
23-
<div class="tab-content">
24-
<% bibrec = ctx.bibtex() %>
25-
<div id="tab1" class="tab-pane active">
26-
<p id="${h.format_gbs_identifier(ctx)}">${bibrec.text()}</p>
27-
% if ctx.datadict().get('Additional_information'):
28-
<p>
29-
${ctx.datadict().get('Additional_information')}
30-
</p>
31-
% endif
32-
<ul class="inline">
33-
% if ctx.author == 'ISO 639-3 Registration Authority':
34-
<li>${u.format_external_link_in_label(ctx.howpublished, 'ISO 639-3')}</li>
35-
% endif
36-
% if ctx.url:
37-
<li>${u.format_external_link_in_label(ctx.url)}</li>
38-
% elif ctx.jsondata.get('doi'):
39-
<li>${u.format_external_link_in_label('http://dx.doi.org/%s' % ctx.jsondata['doi'], 'DOI')}</li>
40-
% endif
41-
% if ctx.gbid:
42-
<li>${u.format_external_link_in_label('https://books.google.com/books?id=%s' % ctx.gbid.split('id=')[-1], label='Google Books')}</li>
43-
% endif
44-
<% oclc = ctx.jsondata.get('oclc') %>
45-
% if oclc:
46-
<li>${u.format_external_link_in_label('http://www.worldcat.org/oclc/{0}'.format(oclc), 'WorldCat')}</li>
47-
% endif
48-
##<% isbn = ctx.jsondata.get('isbn') %>
23+
<div class="tabbable">
24+
<ul class="nav nav-tabs">
25+
<li class="active"><a href="#tab1" data-toggle="tab">Text</a></li>
26+
<li><a href="#tab2" data-toggle="tab">BibTeX</a></li>
27+
</ul>
28+
<div class="tab-content">
29+
<% bibrec = ctx.bibtex() %>
30+
<div id="tab1" class="tab-pane active">
31+
<p id="${h.format_gbs_identifier(ctx)}">${bibrec.text()}</p>
32+
% if ctx.datadict().get('Additional_information'):
33+
<p>
34+
${ctx.datadict().get('Additional_information')}
35+
</p>
36+
% endif
37+
<ul class="inline">
38+
% if ctx.author == 'ISO 639-3 Registration Authority':
39+
<li>${u.format_external_link_in_label(ctx.howpublished, 'ISO 639-3')}</li>
40+
% endif
41+
% if ctx.url:
42+
<li>${u.format_external_link_in_label(ctx.url)}</li>
43+
% elif ctx.jsondata.get('doi'):
44+
<li>${u.format_external_link_in_label('http://dx.doi.org/%s' % ctx.jsondata['doi'], 'DOI')}</li>
45+
% endif
46+
% if ctx.gbid:
47+
<li>${u.format_external_link_in_label('https://books.google.com/books?id=%s' % ctx.gbid.split('id=')[-1], label='Google Books')}</li>
48+
% endif
49+
<% oclc = ctx.jsondata.get('oclc') %>
50+
% if oclc:
51+
<li>${u.format_external_link_in_label('http://www.worldcat.org/oclc/{0}'.format(oclc), 'WorldCat')}</li>
52+
% endif
53+
##<% isbn = ctx.jsondata.get('isbn') %>
4954
##% if isbn:
5055
## ${util.gbs_links(['ISBN:{0}'.format(isbn)])}
5156
##% endif
5257
</ul>
53-
% if ctx.iaid:
54-
<hr />
55-
<iframe src='https://archive.org/stream/${ctx.iaid}?ui=embed#mode/1up' width='680px' height='750px' frameborder='1' ></iframe>
56-
% endif
57-
</div>
58-
<div id="tab2" class="tab-pane"><pre>${bibrec}</pre></div>
58+
% if ctx.iaid:
59+
<hr/>
60+
<iframe src='https://archive.org/stream/${ctx.iaid}?ui=embed#mode/1up' width='680px'
61+
height='750px' frameborder='1'></iframe>
62+
% endif
63+
</div>
64+
<div id="tab2" class="tab-pane">
65+
<pre>${bibrec}</pre>
66+
</div>
67+
</div>
68+
</div>
5969
</div>
60-
</div>
6170

62-
<%def name="sidebar()">
63-
% if ctx.doctypes:
64-
<%util:well>
65-
<h3>Document types${u.format_ca_icon(req, ctx, 'doctype')}</h3>
66-
<ul class="inline">
67-
% for dt in ctx.doctypes:
68-
<li>
69-
${u.format_label_link(request.route_url('home.glossary', _anchor='doctype-' + dt.id), dt.name.capitalize().replace('_', ' '), title=dt.description)}
70-
</li>
71-
% endfor
72-
</ul>
73-
</%util:well>
74-
% endif
75-
% if ctx.languages:
76-
<%util:well>
77-
${u.format_language_header(request, ctx, level=3)}
78-
<ul class="unstyled">
79-
% for li in u.format_languages(request, ctx):
80-
${li}
81-
% endfor
82-
</ul>
83-
</%util:well>
84-
% endif
85-
<%util:well>
86-
<h3>Providers</h3>
87-
<ul class="inline">
88-
% for p, keys in groupby(ctx.bibkeys, lambda bk: bk.provider):
89-
<dl>
90-
<dt>${h.link(request, p)}</dt>
91-
% for k in keys:
92-
<dd><a href="${request.route_url('source', id=k.id)}">${k.id}</a></dd>
93-
% endfor
94-
</dl>
95-
% endfor
96-
</ul>
97-
</%util:well>
98-
</%def>
71+
<div class="span5">
72+
73+
% if ctx.doctypes:
74+
<%util:well>
75+
<h3>Document types${u.format_ca_icon(req, ctx, 'doctype')}</h3>
76+
<ul class="inline">
77+
% for dt in ctx.doctypes:
78+
<li>
79+
${u.format_label_link(request.route_url('home.glossary', _anchor='doctype-' + dt.id), dt.name.capitalize().replace('_', ' '), title=dt.description)}
80+
</li>
81+
% endfor
82+
</ul>
83+
</%util:well>
84+
% endif
85+
% if ctx.languages:
86+
<%util:well>
87+
${u.format_language_header(request, ctx, level=3)}
88+
<table class="table table-condensed">
89+
<thead>
90+
<tr>
91+
<th>Name in source</th>
92+
<th>Glottolog languoid</th>
93+
</tr>
94+
</thead>
95+
<tbody>
96+
% for names, links in u.format_languages(request, ctx):
97+
<tr>
98+
<td>${names}</td>
99+
<td>${links}</td>
100+
</tr>
101+
% endfor
102+
103+
</tbody>
104+
</table>
105+
</%util:well>
106+
% endif
107+
<%util:well>
108+
<h3>Providers</h3>
109+
<ul class="inline">
110+
% for p, keys in groupby(ctx.bibkeys, lambda bk: bk.provider):
111+
<dl>
112+
<dt>${h.link(request, p)}</dt>
113+
% for k in keys:
114+
<dd><a href="${request.route_url('source', id=k.id)}">${k.id}</a></dd>
115+
% endfor
116+
</dl>
117+
% endfor
118+
</ul>
119+
</%util:well>
120+
</div>
121+
</div>

glottolog3/templates/source/snippet_html.mako

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,21 @@ $(document).ready(function() {
2020
</script>
2121
% if ctx.languages:
2222
${u.format_language_header(request, ctx, level=4)}
23-
<ul class="inline">
24-
% for li in u.format_languages(request, ctx):
25-
${li}
26-
% endfor
27-
</ul>
23+
<table class="table table-condensed">
24+
<thead>
25+
<tr>
26+
<th>Name in source</th>
27+
<th>Glottolog languoid</th>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
% for names, links in u.format_languages(request, ctx):
32+
<tr>
33+
<td>${names}</td>
34+
<td>${links}</td>
35+
</tr>
36+
% endfor
37+
38+
</tbody>
39+
</table>
2840
% endif

glottolog3/util.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,30 +289,26 @@ def format_languages(req, ref):
289289
ldict = {l.hid: l for l in ref.languages}
290290
ldict.update({l.id: l for l in ref.languages})
291291
in_note = set()
292-
lnotes = map(normalize_language_explanation, (ref.jsondata.get('lgcode', '')).split('],'))
292+
lnotes = map(normalize_language_explanation, (ref.jsondata.get('lgcode', '')).split(','))
293293
for lnote in lnotes:
294-
note = []
294+
note, links = [], []
295295
start = 0
296296
m = None
297297
for m in LANG_PATTERN.finditer(lnote):
298298
note.append(lnote[start:m.start()])
299-
note.append('[')
300299
if m.group('id') in ldict:
301300
in_note.add(m.group('id'))
302301
lang = ldict[m.group('id')]
303-
note.append(link(req, lang, label=lang.id, title=lang.name))
302+
links.append(link(req, lang, label=lang.name, title=lang.id))
304303
else:
305-
note.append(m.group('id'))
306-
note.append(']')
304+
note.extend(['[', m.group('id'), ']'])
307305
start = m.end()
308-
if m:
309-
note.append(lnote[m.end():])
310-
yield HTML.li(*note)
306+
note.append(lnote[m.end():] if m else lnote)
307+
yield ''.join(note), HTML.ul(*[HTML.li(li) for li in links], **dict(class_="inline"))
311308

312309
for lang in set(ldict.values()):
313310
if (lang.hid not in in_note) and (lang.id not in in_note):
314-
yield HTML.li(
315-
lang.name + ' [', link(req, lang, label=lang.id, title=lang.name), ']')
311+
yield '', link(req, lang, label=lang.name, title=lang.id)
316312

317313

318314
def format_label_link(href, label, title=None):

0 commit comments

Comments
 (0)