View Single Post
Old 01-29-2022, 03:03 PM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,465
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Wiggo View Post
There's a strange bug in the book details with my alias column.
The name is cutted off, and it happens with this name only.
It doesn't fail for me.

Is the 'P' in 'Petra' a non-Latin unicode character? I can see something like this happening if it is a unicode composed character.

FWIW: there is some strange (to me) code in your function:
Code:
def evaluate(self, formatter, kwargs, mi, locals, val, col_name, user_cat_prefix):
    new_val = ''
    if hasattr(mi, '_proxy_metadata'):
        # Below should be mi.user_categories
        all_cats = mi._proxy_metadata.user_categories
        cats = {k:v for k,v in all_cats.items() if k.startswith(user_cat_prefix)}
        SEP = mi.metadata_for_field(col_name)['is_multiple'].get('list_to_ui', '')
        new_val = set()
        if SEP:
            val_ = val.split(SEP)
        else:
            val_ = [val]  
        for user_cat, v in cats.items():
            repl = user_cat.lstrip(user_cat_prefix)
            for user_cat_item, src_cat in v:
                if src_cat == col_name:
                    # Why does the next line have the slice?
                    # I think it should be 
                    # for item in val_:
                    for item in val_[:]:
                        if item == user_cat_item:
                            new_val.add(repl)
                            # Why are you removing the item from the list?
                            # Sometimes that will mess up the for loop. Or
                            # at least it could in python 2.
                            val_.remove(item)
                        else:
                            new_val.add(item)
        if new_val:
            return ', '.join(list(new_val))
    return val
chaley is offline   Reply With Quote