def date_to_db(value, context): try: value = DateType.form_to_db(value) except DateConvertError, e: raise Invalid(str(e))
def date_to_db(value, context): try: value = DateType.form_to_db(value) except DateConvertError, e: raise Invalid(unicode(e).encode('ascii', 'ignore'))
try: title = row[0].value.encode('utf-8') except Exception, e: raise Exception('Error with encoding of Title: %s' % e) try: description = row[1].value.encode('utf-8') except Exception, e: raise Exception('Error with encoding of Description: %s' % e) publisher_name = row[2].value publish_date = row[3].value release_notes = row[4].value if isinstance(publish_date, basestring) and publish_date.strip(): # e.g. CSV containing "1/2/14" -> "14/02/01" try: publish_date = DateType.form_to_db(publish_date) except DateConvertError: # Lots of text went into this field but have decided to not allow from now # and it never gets displayed. msg = 'Could not parse date: "%s" Must be: DD/MM/YY' % publish_date log.error(msg) raise Exception(msg) if isinstance(publish_date, datetime.datetime): # e.g. Excel -> "14/02/01" publish_date = DateType.date_to_db(publish_date) if not isinstance(publish_date, basestring): # e.g. Excel int msg = 'Could not parse date: "%s" Must be: DD/MM/YY' % publish_date log.error(msg) raise Exception(msg)