def set_date(self, prop_name, date_or_str): if not date_or_str: self.replace_or_add_prop(prop_name, None) elif isinstance(date_or_str, basestring): self.replace_or_add_prop(prop_name, date_or_str, to_date(date_or_str)) elif isinstance(date_or_str, (datetime.date, datetime.datetime)): self.replace_or_add_prop(prop_name, from_date(date_or_str), date_or_str) else: logging.error(u"ERROR: setting non-date or non-string")
def _fix_properties_on_load(self): """normalizes property names and transforms date properties to a readable / managable form """ props = self.properties # fix properties, if possible for prop_name in props: if "{prop_key}:".format(prop_key = prop_name) not in self.text: # we need to normalize this property name, make everything lowercase re_normalize_prop = re.compile("({prop_key}:)".format(prop_key = prop_name), re.IGNORECASE) self.text = re_normalize_prop.sub("{prop_key}:".format(prop_key = prop_name), self.text) if prop_name in conf.DATE_PROPS: # replace all date props with a "beautified" date string repl_date = to_date(props[prop_name]) if repl_date: self.text = self.text.replace(props[prop_name], from_date(repl_date)) props[prop_name] = repl_date
def _fix_properties_on_load(self): """normalizes property names and transforms date properties to a readable / managable form """ props = self.properties # fix properties, if possible for prop_name in props: if "{prop_key}:".format(prop_key=prop_name) not in self.text: # we need to normalize this property name, make everything lowercase re_normalize_prop = re.compile( "({prop_key}:)".format(prop_key=prop_name), re.IGNORECASE) self.text = re_normalize_prop.sub( "{prop_key}:".format(prop_key=prop_name), self.text) if prop_name in conf.DATE_PROPS: # replace all date props with a "beautified" date string repl_date = to_date(props[prop_name]) if repl_date: self.text = self.text.replace(props[prop_name], from_date(repl_date)) props[prop_name] = repl_date