"""A collection of functions to polish the representation of a publication in a list. """ import re from gluon import current from plugin_dbui import UNDEF def clean(value, template, record): """Clean the representation of the record by removing typography mistakes. Args: value (unicode): the bibliographic string representing the record. template (unicode): the template string is applied to the record in order to obtain a new representation. The substitution mechanism is: ``{tablename.fieldname}``. record (gluon.dal.Row): the database row to be manipulated. It contains the table *publications* and all foreign tables. Returns: unicode: """ value = re.sub(", *,", ",", value) # ",," or ", ," or ... value = re.sub(" *, *", ", ", value) # " ," value = re.sub(",$", "", value) # comma at the end of string return value def highlight_my_authors(value, template, record): """Highlight the name of the authors of my institute by underlying them. Args: value (unicode): the current string representing the record. template (unicode): the template string is applied to the record in order to obtain a new representation. The substitution mechanism is: ``{tablename.fieldname}``. record (gluon.dal.Row): the database row to be manipulated. It contains the table *publications* and all foreign tables. Returns: unicode: """ li = record.publications.authors_institute.split(",") for author in li: author = author.strip() value = value.replace(author, "%s" % author) return value def highlight_my_speaker(value, template, record): """Highlight the name of the speaker of my institute (bold) and my authors (underline). Args: value (unicode): the current string representing the record. template (unicode): the template string is applied to the record in order to obtain a new representation. The substitution mechanism is: ``{tablename.fieldname}``. record (gluon.dal.Row): the database row to be manipulated. It contains the table *publications* and all foreign tables. Returns: unicode: """ # my speaker is in bold speaker = record.publications.conference_speaker.strip() if speaker and speaker in record.publications.authors_institute: value = value.replace(speaker, "%s" % speaker) # my authors are underlined li = record.publications.authors_institute.split(",") for author in li: author = author.strip() if author == speaker: continue value = value.replace(author, "%s" % author) return value def remove_undef(value, template, record): """Remove the ``UNDEF`` string. Args: value (unicode): the current string representing the record. template (unicode): the template string is applied to the record in order to obtain a new representation. The substitution mechanism is: ``{tablename.fieldname}``. record (gluon.dal.Row): the database row to be manipulated. It contains the table *publications* and all foreign tables. Returns: unicode: """ undef = current.T(UNDEF) return re.sub(", *%s *," % undef, ",", value)