From 68768dd6e44f5418029daae4fc61dd3c267b0d7e Mon Sep 17 00:00:00 2001 From: pictuga Date: Sat, 16 Nov 2013 19:06:35 +0100 Subject: [PATCH] Add FeedBool in feeds.py To handle boolean values --- feeds.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/feeds.py b/feeds.py index 7150f43..3d9c80e 100644 --- a/feeds.py +++ b/feeds.py @@ -154,6 +154,17 @@ class FeedTime(FeedDescriptor): except ValueError: pass +class FeedBool(FeedDescriptor): + def __get__(self, instance, owner): + getter = getattr(instance, 'get%s' % self.nname) + raw = getter() + return (raw or '').lower() != 'false' + + def __set__(self, instance, value): + raw = 'true' if value else 'false' + setter = getattr(instance, 'set%s' % self.nname) + return setter(raw) + def parseTime(value): if isinstance(value, basestring): if re.match(r'^[0-9]+$', value):