<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2019 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################

from odoo import api, models

LANG_MAPPING = {
    'fr': 'fr_CH',
    'de': 'de_DE',
    'it': 'it_IT'
}

TITLE_MAPPING = {
    'Herr': 'base.res_partner_title_mister',
    'Frau': 'base.res_partner_title_madam',
    'Familie': 'partner_compassion.res_partner_title_family',
}

SPOKEN_LANG_MAPPING = {
    u'französich': 'child_compassion.lang_compassion_french',
    u'deutsch': 'child_switzerland.lang_compassion_german',
    u'italienisch': 'child_switzerland.lang_compassion_italian',
    u'spanisch': 'child_compassion.lang_compassion_spanish',
    u'englisch': 'child_compassion.lang_compassion_english',
    u'portugiesisch': 'child_compassion.lang_compassion_portuguese',
}


class MatchPartnerWP(models.AbstractModel):
    """
    Add functionnalities to format the WP values into values understandable by
    Odoo.
    """
    _name = 'res.partner.match.wp'
    _inherit = 'res.partner.match'

    @api.model
    def match_country(self, wp_country, wp_lang):
        country = self.env['res.country'].with_context(
            lang=wp_lang
        ).search([
            ('name', '=ilike', wp_country),
        ])
        return country

    @api.model
    def match_lang(self, wp_lang):
        return LANG_MAPPING[wp_lang]

    @api.model
    def match_title(self, wp_title):
        return self.env.ref(TITLE_MAPPING[wp_title]).id

    @api.model
    def match_spoken_langs(self, wp_spoken_langs):
        spoken_langs = self.env['res.lang.compassion']
        for wp_spoken in wp_spoken_langs:
            spoken_langs += self.env.ref(SPOKEN_LANG_MAPPING[wp_spoken])
        lang_write = [(4, lang.id) for lang in spoken_langs]
        return lang_write<commit_msg>WP-20 : Search for wordpress title in db.<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2019 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################

from odoo import api, models

LANG_MAPPING = {
    'fr': 'fr_CH',
    'de': 'de_DE',
    'it': 'it_IT'
}

TITLE_MAPPING = {
    'Herr': 'base.res_partner_title_mister',
    'Frau': 'base.res_partner_title_madam',
    'Familie': 'partner_compassion.res_partner_title_family',
}

SPOKEN_LANG_MAPPING = {
    u'französich': 'child_compassion.lang_compassion_french',
    u'deutsch': 'child_switzerland.lang_compassion_german',
    u'italienisch': 'child_switzerland.lang_compassion_italian',
    u'spanisch': 'child_compassion.lang_compassion_spanish',
    u'englisch': 'child_compassion.lang_compassion_english',
    u'portugiesisch': 'child_compassion.lang_compassion_portuguese',
}


class MatchPartnerWP(models.AbstractModel):
    """
    Add functionnalities to format the WP values into values understandable by
    Odoo.
    """
    _name = 'res.partner.match.wp'
    _inherit = 'res.partner.match'

    @api.model
    def match_country(self, wp_country, wp_lang):
        country = self.env['res.country'].with_context(
            lang=wp_lang
        ).search([
            ('name', '=ilike', wp_country),
        ])
        return country

    @api.model
    def match_lang(self, wp_lang):
        return LANG_MAPPING.get(wp_lang)

    @api.model
    def match_title(self, wp_title):
        if wp_title in TITLE_MAPPING:
            return self.env.ref(TITLE_MAPPING.get(wp_title)).id
        else:
            title = self.env['res.partner.title'].with_context(
                lang='en_US'
            ).search([
                ('name', '=ilike', wp_title),
            ])
            return title.id

    @api.model
    def match_spoken_langs(self, wp_spoken_langs):
        spoken_langs = self.env['res.lang.compassion']
        for wp_spoken in wp_spoken_langs:
            spoken_langs += self.env.ref(SPOKEN_LANG_MAPPING[wp_spoken])
        lang_write = [(4, lang.id) for lang in spoken_langs]
        return lang_write
{'fraction_non_alphanumeric': 0.18338945005611673, 'fraction_numerical': 0.0031425364758698093, 'mean_word_length': 3.429423459244533, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3099046', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1454, 'n_words': 265}