'Merge comments with custom column content.
Merge comments from book metadata with user-specified custom column
content, optionally before or after. Optionally insert <hr> between
fields.
Args:
record (dict): book metadata
Return:
merged (str): comments merged with addendum'

def merge_comments(self, record):

    merged = ''
    if record['description']:
        addendum = self.db.get_field(record['id'], self.merge_comments_rule['field'], index_is_id=True)
        if (addendum is None):
            addendum = ''
        elif (type(addendum) is list):
            addendum = ',    '.join(addendum)
        include_hr = eval(self.merge_comments_rule['hr'])
        if (self.merge_comments_rule['position'] == 'before'):
            merged = addendum
            if include_hr:
                merged += '<hr    class="merged_comments_divider"/>'
            else:
                merged += '\n'
            merged += record['description']
        else:
            merged = record['description']
            if include_hr:
                merged += '<hr    class="merged_comments_divider"/>'
            else:
                merged += '\n'
            merged += addendum
    else:
        merged = self.db.get_field(record['id'], self.merge_comments_rule['field'], index_is_id=True)
        if (type(merged) is list):
            merged = ',    '.join(merged)
    return merged
