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)
    def generate_weeks(self):
        query_size = 50
        i = 0

        while True:
            skip = query_size * i
            i = i+1
            docs = es_tools.get_docs('organisation', 'libdir_documents_01',
                '_id', skip=skip, size=query_size)

            if len(docs) == 0:
                break

            for doc in docs:
                metadata = doc['meta']
                metadata['id'] = doc['_id']
                index_opening_hours.do(doc, metadata)

                if 'period' not in doc:
                    continue

                end = range_end(doc['period'])
                start = pyes.utils.ESRange('week_start', end.isoformat())
                rq = pyes.RangeQuery(start)
                pq = pyes.PrefixQuery("_id", doc['_id'])

                query = pyes.BoolQuery([rq, pq])
                conn.delete_by_query('schedules', 'week', query)

        return True