Exemplo n.º 1
0
    def test_walk(self):
        combined = periodrange.combine_periodranges(
            self.period_example)

        pp = pprint.PrettyPrinter(indent=4)
        for day in periodrange.walk(combined):
            self.assertTrue(
                day['closed'] or
                ('from' in day and 'to' in day))
def do(document, metadata={}):
    organisation_id = metadata.get('id')
    organisation_name = document.get('name_fi')
    doc_meta = metadata.get('doc_meta')

    if not organisation_id:
        return False

    periods = manipulate_periods(document.get("period"))
    combined_periods = periodrange.combine_periodranges(periods)
    week = []

    for day in periodrange.walk(combined_periods, start_from = date.today()):
        if day['weekday'] == 'monday' and len(week) > 0:
            index_week(week, organisation_id, organisation_name, doc_meta)
            week = []
        week.append(day)

    if len(week) > 0:
        index_week(week, organisation_id, organisation_name,
                   doc_meta)

    week = []

    for group_id, periods in document.get("period_groups", {}).items():
        periods = manipulate_periods(periods)
        combined_periods = periodrange.combine_periodranges(periods)

        for day in periodrange.walk(combined_periods, start_from = date.today()):
            if day["weekday"] == "monday" and len(week) > 0:
                index_alt_week(week, organisation_id, organisation_name, group_id, doc_meta)
                week = []
            week.append(day)

    if len(week) > 0:
        index_alt_week(week, organisation_id, organisation_name, group_id, doc_meta)

    conn.force_bulk()

    return True