django-nonrel/django-dbindexer — Issue #2: Fix to index date time fields that are None
Author: smeyfroi
Created: 2011-12-01 13:00:11+00:00
State: open

Patch that allows indexed dates to be None:

diff --git a/dbindexer/lookups.py b/dbindexer/lookups.py
index c72b8a36971d1c9c6911cf418df0b2bf6764ea60..5773fe0b1ee97b70702c9567400369e6d038b786 100644
--- a/dbindexer/lookups.py
+++ b/dbindexer/lookups.py
@@ -87,25 +87,37 @@ class Day(DateLookup):
lookup_types = 'day'

def _convert_value(self, value):
- return value.day
+ if value:
+ return value.day
+ else:
+ return None

class Month(DateLookup):
lookup_types = 'month'

def _convert_value(self, value):
- return value.month
+ if value:
+ return value.month
+ else:
+ return None

class Year(DateLookup):
lookup_types = 'year'

def _convert_value(self, value):
- return value.year
+ if value:
+ return value.year
+ else:
+ return None

class Weekday(DateLookup):
lookup_types = 'week_day'

def _convert_value(self, value):
- return value.isoweekday()
+ if value:
+ return value.isoweekday()
+ else:
+ return None

class Contains(ExtraFieldLookup):
lookup_types = 'contains'