def assign_alliance_group(auth): alliance_group = None if auth.main_char_id: if EveCharacter.objects.filter(character_id=auth.main_char_id).exists(): char = EveCharacter.objects.get(character_id=auth.main_char_id) if char.alliance_name: alliancename = generate_alliance_group_name(char.alliance_name) state = determine_membership_by_character(char) if state == "BLUE" and settings.BLUE_ALLIANCE_GROUPS: logger.debug("Validating blue user %s has alliance group assigned." % auth.user) alliance_group, c = Group.objects.get_or_create(name=alliancename) elif state == "MEMBER" and settings.MEMBER_ALLIANCE_GROUPS: logger.debug("Validating member %s has alliance group assigned." % auth.user) alliance_group, c = Group.objects.get_or_create(name=alliancename) else: logger.debug("Ensuring non-member %s has no alliance groups assigned." % auth.user) else: logger.debug("User %s main character %s not in an alliance. Ensuring no allinace group assigned." % (auth.user, char)) if alliance_group: if not alliance_group in auth.user.groups.all(): logger.info("Adding user %s to alliance group %s" % (auth.user, alliance_group)) auth.user.groups.add(alliance_group) for g in auth.user.groups.all(): if str.startswith(str(g.name), "Alliance_"): if g != alliance_group: logger.info("Removing user %s from old alliancegroup %s" % (auth.user, g)) auth.user.groups.remove(g)