Commit fc2686ad authored by R茅gis Witz's avatar R茅gis Witz
Browse files

馃悰 fix notices linked to sources with no references in lexicon

parent d0a8af8e
......@@ -224,28 +224,17 @@ def write_html(config, records):
places_html = lexicon_as_html(places)
themes.sort(key=lambda x: unromanize(htmlz.strip_diacritics(x.descripteur.upper())))
themes_html = lexicon_as_html(themes)
# sources lexicon is a special case
def get_sources_of_notice(notice, field):
# field is unused here, we always use 'sources', it get us References
# yeah I know it can be misleading
refs = notice.get('sources', [])
# and NOW we get the sources, but only if Notice only points to
# the source as a whole, without any explicit Reference
sources_of_notice = []
for hid in refs:
ref = [r for r in references if r.hid == hid]
if ref: # this is a Reference pointer, not our use-case
continue
source = [s for s in sources if s.hid == hid]
if len(source) < 1: # wtf?
print("WARNING: Neither Reference not Source pointed by '%s' ???" % (hid))
continue
sources_of_notice.append(hid) # hid == source[0].hid
return sources_of_notice
notice.update_sources(records)
sources_with_or_without_refs = getattr(notice, field, {})
return [source.hid for source in sources_with_or_without_refs]
FIELD_KEY = 'bahr_refs'
update_sources_for_lexicon(records, FIELD_KEY)
generate_lexicon(records, heurist.Reference.RECORD_TYPE, 'sources')
generate_lexicon(records, heurist.Source.RECORD_TYPE, 'whatever', retrieve=get_sources_of_notice)
generate_lexicon(records, heurist.Source.RECORD_TYPE, 'references', retrieve=get_sources_of_notice)
def format_source(source, referenced_in_notices):
result = html.format_lexicon_entry(source, referenced_in_notices, True, False)
all_references = records[heurist.Reference.RECORD_TYPE]
......
......@@ -111,12 +111,12 @@ class Notice(heurist.Notice):
return ''
return ', %s' % ', '.join(l)
def get_sources_string(self, records, prefix=''):
def update_sources(self, records):
key = 'references'
if not hasattr(self, key):
references = self.get('sources')
if not references:
setattr(self, key, list())
setattr(self, key, dict())
return ''
all_refs = records[heurist.Reference.RECORD_TYPE]
refs = dict()
......@@ -130,16 +130,20 @@ class Notice(heurist.Notice):
except KeyError:
source_hid = hid
source = heurist.Reference.get_source(records, source_hid)
desc = source.get('descripteur')[0]
l = refs.get(desc, [])
l = refs.get(source, [])
if reference:
ref = reference.get('reference')
if ref:
l.append(' '.join(ref))
refs[desc] = l
refs[source] = l
setattr(self, key, refs)
return key
def get_sources_string(self, records, prefix=''):
key = self.update_sources(records)
result = ''
for abbrev, refs in getattr(self, key, {}).items():
for source, refs in getattr(self, key, {}).items():
abbrev = source.get('descripteur')[0]
result += ' %s %s %s' % (prefix, abbrev, ' ; '.join(refs))
return result
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment