def filter(self, date=None, regroup=False, ignored=None, pushed=None, unmapped=None, current_workday=None):
        """
        Return the entries as a dict of {:class:`datetime.date`: :class:`~taxi.timesheet.lines.Entry`}
        items.

        `date` can either be a single :class:`datetime.date` object to filter only entries from the given date,
        or a tuple of :class:`datetime.date` objects representing `(from, to)`. `filter_callback` is a function that,
        given a :class:`~taxi.timesheet.lines.Entry` object, should return True to include that line, or False to
        exclude it. If `regroup` is set to True, similar entries (ie. having the same
        :meth:`~taxi.timesheet.lines.Entry.hash`) will be regrouped intro a single
        :class:`~taxi.timesheet.entry.AggregatedTimesheetEntry`.
        """
        def entry_filter(entry_date, entry):
            if ignored is not None and entry.ignored != ignored:
                return False

            if pushed is not None and entry.pushed != pushed:
                return False

            if unmapped is not None and entry.mapped == unmapped:
                return False

            if current_workday is not None:
                today = datetime.date.today()
                yesterday = date_utils.get_previous_working_day(today)
                is_current_workday = entry_date in (today, yesterday) and entry_date.strftime('%w') not in [6, 0]

                if current_workday != is_current_workday:
                    return False

            return True

        # Date can either be a single date (only 1 day) or a tuple for a
        # date range
        if date is not None and not isinstance(date, tuple):
            date = (date, date)

        filtered_entries = collections.defaultdict(list)

        for (entries_date, entries) in six.iteritems(self):
            if (date is not None and (
                    (date[0] is not None and entries_date < date[0])
                    or (date[1] is not None and entries_date > date[1]))):
                continue

            entries_for_date = []

            if regroup:
                # This is a mapping between entries hashes and their
                # position in the entries_for_date list
                aggregated_entries = {}
                id = 0

                for entry in entries:
                    if not entry_filter(entries_date, entry):
                        continue

                    # Common case: the entry is not yet referenced in the
                    # aggregated_entries dict
                    if entry.hash not in aggregated_entries:
                        # In that case, put it normally in the entries_for_date
                        # list. It will get replaced by an AggregatedEntry
                        # later if necessary
                        entries_for_date.append(entry)
                        aggregated_entries[entry.hash] = id
                        id += 1
                    else:
                        # Get the first occurence of the entry in the
                        # entries_for_date list
                        existing_entry = entries_for_date[
                            aggregated_entries[entry.hash]
                        ]

                        # The entry could already have been replaced by an
                        # AggregatedEntry if there's more than 2 occurences
                        if isinstance(existing_entry, Entry):
                            # Create the AggregatedEntry, put the first
                            # occurence of Entry in it and the current one
                            aggregated_entry = AggregatedTimesheetEntry()
                            aggregated_entry.entries.append(existing_entry)
                            aggregated_entry.entries.append(entry)
                            entries_for_date[
                                aggregated_entries[entry.hash]
                            ] = aggregated_entry
                        else:
                            # The entry we found is already an
                            # AggregatedEntry, let's just append the
                            # current entry to it
                            aggregated_entry = existing_entry
                            aggregated_entry.entries.append(entry)
            else:
                entries_for_date = [
                    entry for entry in entries if entry_filter(entries_date, entry)
                ]

            if entries_for_date:
                filtered_entries[entries_date].extend(entries_for_date)

        return filtered_entries
def filter ( self , date = None , regroup = False , ignored = None , pushed = None , unmapped = None , current_workday = None ) : def entry_filter ( entry_date , entry ) : if ignored is not None and entry . ignored != ignored : return False if pushed is not None and entry . pushed != pushed : return False if unmapped is not None and entry . mapped == unmapped : return False if current_workday is not None : today = datetime . date . today ( ) yesterday = date_utils . get_previous_working_day ( today ) is_current_workday = entry_date in ( today , yesterday ) and entry_date . strftime ( '%w' ) not in [ 6 , 0 ] if current_workday != is_current_workday : return False return True if date is not None and not isinstance ( date , tuple ) : date = ( date , date ) filtered_entries = collections . defaultdict ( list ) for ( entries_date , entries ) in six . iteritems ( self ) : if ( date is not None and ( ( date [ 0 ] is not None and entries_date < date [ 0 ] ) or ( date [ 1 ] is not None and entries_date > date [ 1 ] ) ) ) : continue entries_for_date = [ ] if regroup : aggregated_entries = { } id = 0 for entry in entries : if not entry_filter ( entries_date , entry ) : continue if entry . hash not in aggregated_entries : entries_for_date . append ( entry ) aggregated_entries [ entry . hash ] = id id += 1 else : existing_entry = entries_for_date [ aggregated_entries [ entry . hash ] ] if isinstance ( existing_entry , Entry ) : aggregated_entry = AggregatedTimesheetEntry ( ) aggregated_entry . entries . append ( existing_entry ) aggregated_entry . entries . append ( entry ) entries_for_date [ aggregated_entries [ entry . hash ] ] = aggregated_entry else : aggregated_entry = existing_entry aggregated_entry . entries . append ( entry ) else : entries_for_date = [ entry for entry in entries if entry_filter ( entries_date , entry ) ] if entries_for_date : filtered_entries [ entries_date ] . extend ( entries_for_date ) return filtered_entries
Return the entries as a dict of {:class:`datetime.date`: :class:`~taxi.timesheet.lines.Entry`}
        items.

        `date` can either be a single :class:`datetime.date` object to filter only entries from the given date,
        or a tuple of :class:`datetime.date` objects representing `(from, to)`. `filter_callback` is a function that,
        given a :class:`~taxi.timesheet.lines.Entry` object, should return True to include that line, or False to
        exclude it. If `regroup` is set to True, similar entries (ie. having the same
        :meth:`~taxi.timesheet.lines.Entry.hash`) will be regrouped intro a single
        :class:`~taxi.timesheet.entry.AggregatedTimesheetEntry`.