Do you expect `unlockable_badgeclasses` to be a list of unique badges?

If so I really recommend you use Python sets here, and use set joins, differences, intersections, and unions to accomplish the logic in lines 41-71. Five big list comprehensions seem scary, and a flag of potentially unnecessary code. Also possibly very time consuming.