예제 #1
0
 def bulkload_table(self, table):
     """
     @param table: input data as a list of dicts
     @return: dict of updated rows ad dicts
     """
     d = {}
     for row in table:
         id = row['id']
         for reading_type in ['gospel', 'lecture', 'epistle']:
             references = row[reading_type]  # this is a repeated property !
             if references:
                 for reference in references:
                     new_reference = bibleref.submit(reference)
                     if new_reference:
                         # update the table before bulkloading
                         row[reading_type] = [new_reference if r == reference else r for r in row[reading_type]]
                         # store the updated rows in a dict, for being returned
                         d[id] = row
     # split rows with combined cycle values
     for row in table:
         cycle = row['cycle']
         if cycle == 'ABC':
             row_copy = {}
             for c in ['B', 'C']:
                 row_copy[c] = copy.deepcopy(row)
                 row_copy[c]['cycle'] = c
                 row_copy[c]['id'] = row_copy[c]['id'].replace('ABC', c)
                 row_copy[c]['duplicate'] = True
                 table.append(row_copy[c])
             row['cycle'] = 'A'
             row['id'] = row['id'].replace('ABC', 'A')
     Model_index.bulkload_table(self, table, 'id')
     return d
예제 #2
0
 def bulkload_table(self, table):
     d = {}
     for row in table:
         id = row['id']
         reference = row['passageReference']
         if reference:
             new_reference = bibleref.submit(reference, verses=True)
             if new_reference:
                 # update the table before bulkloading
                 row['passageReference'] = new_reference
                 d[id] = row
     Model_index.bulkload_table(self, table, 'id')
     return d
예제 #3
0
 def get(self, lang='en', references=''):
     # get the biblerefs datastore in a lookup table
     datastore_biblerefs_mgr = datastore_index.Biblerefs()
     biblerefs = datastore_biblerefs_mgr.sync_lookup_table()
     # get the illustrations datastore in a table
     datastore_illustrations_mgr = datastore_index.Illustrations()
     illustrations = datastore_illustrations_mgr.sync_table()  # no lookup table!
     # get the verses datastore in a lookup table
     datastore_verses_mgr = datastore_index.Verses()
     verses = datastore_verses_mgr.sync_lookup_table()
     # create a dict for looking up illustrations by passageReference
     lookup_illustrations = {}  # dict by passageReference of lists of illustrations
     for i in illustrations:
         passageReference = i['passageReference']
         if passageReference not in lookup_illustrations:
             lookup_illustrations[passageReference] = []
         lookup_illustrations[passageReference].append(i)
     # expand references to canonical references, contained references and containing references
     expandedReferences = references.replace('+', ' ').split('|')
     for refString in expandedReferences[:]:
         canonicalRefString = bibleref.submit(refString) or refString
         reference = model.BibleRef.query_by_reference(canonicalRefString)
         containedReferences = reference.containedReferences
         if containedReferences:
             logging.log(logging.INFO, "Contained references for %s: %s" % (canonicalRefString, ','.join(containedReferences)))
         containingReferences = [b.reference for b in model.BibleRef.query_by_containedReferences(canonicalRefString)]
         if containingReferences:
             logging.log(logging.INFO, "References containing %s: %s" % (canonicalRefString, ','.join(containingReferences)))
         expandedReferences += containedReferences
         expandedReferences += containingReferences
     # output
     template = jinja_environment.get_template('illustrations.xml')
     content = template.render(
         lang=lang,
         references=references.replace('+', ' ').split('|'),
         biblerefs=biblerefs,  # list of dicts
         lookup_illustrations=lookup_illustrations,  # dict by passageReference of lists of dicts
         verses=verses,  # list of dicts
         readable_date=lib.readable_date,
         xstr=lambda s: s or ""
     )
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return