Example #1
0
File: utils.py Project: pratz/Code
def add_country_code(code_list=[]) :
    """ Function to set / add country code in CountryModel """

    country_obj = Country()

    for code in code_list :
        # check if country code already exist
        status ,country = country_obj.get_by_code(data={'country_code':code})

        if not status :
            # save in CountryModel
            country_new_obj = CountryModel()
            country_new_obj.code = code
            country_new_obj.save()
Example #2
0
File: utils.py Project: pratz/Code
def add_country(language=None,country_dict={}) :
    """ Function used to add country """

    country_obj = Country(language=language)
    country_trans_obj = CountryTranslation()

    for code, country_name in country_dict.items() :
        # check if country code already exist
        status ,country = country_obj.get_by_code(data={'country_code':code})

        if status :
            # check if country traslation with country and language exists
            trans_status, country_trans = country_trans_obj.get_by_country_n_language(data={'language':language,
                'country':country})

            if not trans_status :
                country_trans = CountryTranslationModel()

            country_trans.country = country
            country_trans.language = language
            country_trans.name = country_name
            country_trans.save()