'New nickname generation'

def _generate_new_nickname(self, pokemon, template):

    template = re.sub(u'{[\\w_\\d]*', (lambda x: x.group(0).lower()), template).strip()
    iv_attack = pokemon.iv_attack
    iv_defense = pokemon.iv_defense
    iv_stamina = pokemon.iv_stamina
    iv_list = [iv_attack, iv_defense, iv_stamina]
    iv_sum = sum(iv_list)
    iv_pct = (iv_sum / 45.0)
    base_attack = pokemon.static.base_attack
    base_defense = pokemon.static.base_defense
    base_stamina = pokemon.static.base_stamina
    attack = (base_attack + iv_attack)
    defense = (base_defense + iv_defense)
    stamina = (base_stamina + iv_stamina)
    fast_attack_char = self.attack_char(pokemon.fast_attack)
    charged_attack_char = self.attack_char(pokemon.charged_attack)
    attack_code = (fast_attack_char + charged_attack_char)
    moveset = pokemon.moveset
    pokemon.name = self._localize(pokemon.name)
    pokemon.name = pokemon.name.replace(u'Nidoran    M', u'NidoranM')
    pokemon.name = pokemon.name.replace(u'Nidoran    F', u'NidoranF')
    new_name = template.format(pokemon=pokemon, name=pokemon.name, id=int(pokemon.pokemon_id), cp=int(pokemon.cp), iv_attack=iv_attack, iv_defense=iv_defense, iv_stamina=iv_stamina, iv_ads=u'/'.join(map(str, iv_list)), iv_ads_hex=u''.join(map((lambda x: format(x, u'X')), iv_list)), iv_sum=iv_sum, iv_pct=u'{:03.0f}'.format((iv_pct * 100)), iv_pct2=u'{:02.0f}'.format((iv_pct * 99)), iv_pct1=int(round((iv_pct * 9))), base_attack=base_attack, base_defense=base_defense, base_stamina=base_stamina, base_ads=u'/'.join(map(str, [base_attack, base_defense, base_stamina])), attack=attack, defense=defense, stamina=stamina, sum_ads=u'/'.join(map(str, [attack, defense, stamina])), ivcp_pct=u'{:03.0f}'.format((pokemon.ivcp * 100)), ivcp_pct2=u'{:02.0f}'.format((pokemon.ivcp * 99)), ivcp_pct1=int(round((pokemon.ivcp * 9))), fast_attack_char=fast_attack_char, charged_attack_char=charged_attack_char, attack_code=attack_code, attack_pct=u'{:03.0f}'.format((moveset.attack_perfection * 100)), defense_pct=u'{:03.0f}'.format((moveset.defense_perfection * 100)), attack_pct2=u'{:02.0f}'.format((moveset.attack_perfection * 99)), defense_pct2=u'{:02.0f}'.format((moveset.defense_perfection * 99)), attack_pct1=int(round((moveset.attack_perfection * 9))), defense_pct1=int(round((moveset.defense_perfection * 9))))
    if (new_name == pokemon.name):
        new_name = u''
    return new_name[:MAXIMUM_NICKNAME_LENGTH]
