=== modified file 'launchpadbugs/basebuglistfilter.py' --- launchpadbugs/basebuglistfilter.py 2008-08-01 17:39:43 +0000 +++ launchpadbugs/basebuglistfilter.py 2008-08-02 12:17:46 +0000 @@ -132,8 +132,11 @@ else: return True in conditions and bug -class datereported(object): - def __init__(self, date_def, cls=None): +class date_filter(object): + DATEREPORTED = "date" + DATEUPDATED = "date_updated" + + def __init__(self, date_def, date_kind, cls=None): """ date_def = ("=" or ">" or "<" , date (type of datetime)) """ @@ -153,28 +156,45 @@ self.value = value.date() today = datetime.today().date() if self.value > today: - raise PythonLaunchpadBugsValueError({"datereported": "The given date (%s) is in the future" %self.value}) + raise PythonLaunchpadBugsValueError({"date_filter(%s)" %date_kind: "The given date (%s) is in the future" %self.value}) elif self.value == today and op == ">": - raise PythonLaunchpadBugsValueError({"datereported": "You can not search for bugs reported in the future (op='%s', date='%s')" %(op, self.value)}) + raise PythonLaunchpadBugsValueError({"date_filter(%s)" %date_kind: "You can not search for bugs reported in the future (op='%s', date='%s')" %(op, self.value)}) self.date_state = False + self.kind = date_kind def __call__(self, bug): if not isinstance(bug, LPBug): bug = self.cls(bug) - d_reported = bug.date.date() - result = self.op(d_reported, self.value) + try: + date = getattr(bug, self.kind) + except AttributeError: + raise ValueError, "Unable to filter the list of bugs by '%s'" %self.kind + date = date.date() + result = self.op(date, self.value) if result: self.date_state = True elif self.date_state: - #Task<->Bug issue: double check all tasks - x = map(lambda i: self.op(i.date_created.date(), self.value), bug.infotable) - if True in x: - self.date_state = True - return bug + if self.kind == date_filter.DATEREPORTED: + #Task<->Bug issue: double check all tasks + x = map(lambda i: self.op(i.date_created.date(), self.value), bug.infotable) + if True in x: + self.date_state = True + return bug self.date_state = False raise StopFiltering return result and bug + +class datereported(date_filter): + """ class to ensure backward compatibility """ + def __init__(self, date_def, cls=None): + date_filter.__init__(self, date_def, date_filter.DATEREPORTED, cls) + +class dateupdated(date_filter): + """ class to ensure backward compatibility """ + def __init__(self, date_def, cls=None): + date_filter.__init__(self, date_def, date_filter.DATEUPDATED, cls) + class StopFiltering(StopIteration): pass