def period_description_to_period_name_lingfield():
    """
    Changes the name of a field.
    """
    docs = get_docs("organisation", primary_index)
    for doc in docs:
        periods = doc.get("period")
        if periods:
            nperiods = []
            d = OD()
            for period in periods:
                for key, value in period.items():
                    if key == u"description":
                        d[u"name_fi"] = value
                    else:
                        d[key] = value
                nperiods.append(d)
            doc["period"] = nperiods
    es_import("organisation", docs=docs)

    docs2 = get_docs("period", primary_index)
    for doc in docs2:
        for key, value in doc.items():
            if not "name_fi" in doc and key == u"description":
                doc[u"name_fi"] = value

    es_import("period", docs=docs2)
def change_friday():
    """
    fri-days to fridays migration
    since OrderedDict uses key insertion order
    replacing fri to friday muckes the order of day keys
    It might be nothing or it might be something

    So period will be overridden by newly build list of ODs
    and fri-keys will change fridays in the process
    """
    docs = get_docs("organisation", primary_index)
    for doc in docs:
        periods = doc.get("period")
        if periods:
            nperiods = []
            d = OD()
            for period in periods:
                for key, value in period.items():
                    if key in friday.keys():
                        d[friday[key]] = value
                    else:
                        d[key] = value
                nperiods.append(d)
            doc["period"] = nperiods
    es_import("organisation", docs=docs)