Ejemplo n.º 1
0
    def test_date_datetuple_conversion(self):
        type = schemaish.Date()
        value = date(1966, 12, 18)
        expected = (1966, 12, 18)
        actual = datetuple_converter(type).from_type(value)
        self.assertEquals(actual, expected)

        value, expected = expected, value
        actual = datetuple_converter(type).to_type(value)
        self.assertEquals(actual, expected)
Ejemplo n.º 2
0
    def test_date_datetuple_conversion(self):
        type = schemaish.Date()
        value = date(1966,12,18)
        expected = (1966,12,18)
        actual = datetuple_converter(type).from_type(value)
        self.assertEquals(actual,expected)

        value, expected = expected, value
        actual = datetuple_converter(type).to_type(value)
        self.assertEquals(actual,expected)
Ejemplo n.º 3
0
 def to_request_data(self, field, data):
     """
     Convert to date parts
     """
     dateparts = datetuple_converter(field.attr).from_type(data)
     if dateparts is None:
         return {'year': [''], 'month': [''], 'day': ['']}
     return {'year': [dateparts[0]],
             'month': [dateparts[1]],
             'day': [dateparts[2]]}
Ejemplo n.º 4
0
 def pre_render(self, schema_type, data):
     """
     Convert to date parts
     """
     dateparts = datetuple_converter(schema_type).from_type(data)
     if dateparts is None:
         return {'year': [''], 'month': [''], 'day': ['']}
     return {'year': [dateparts[0]],
             'month': [dateparts[1]],
             'day': [dateparts[2]]}
Ejemplo n.º 5
0
 def from_request_data(self, field, request_data):
     """
     Pull out the parts and convert
     """
     year = request_data['year'][0].strip()
     month = request_data['month'][0].strip()
     day = request_data['day'][0].strip()
     if year or month or day:
         date_parts = (year, month, day)
     else:
         return self.empty
     return datetuple_converter(field.attr).to_type(date_parts)
Ejemplo n.º 6
0
 def convert(self, schema_type, request_data):
     """
     Pull out the parts and convert
     """
     year = request_data.get('year', [''])[0].strip()
     month = request_data.get('month', [''])[0].strip()
     day = request_data.get('day', [''])[0].strip()
     if year or month or day:
         date_parts = (year, month, day)
     else:
         date_parts = None
     return datetuple_converter(schema_type).to_type(date_parts)
Ejemplo n.º 7
0
 def to_request_data(self, field, data):
     """
     Convert to date parts
     """
     dateparts = datetuple_converter(field.attr).from_type(data)
     if dateparts is None:
         return self.none_value_as_request_data(field)
     return {
         'year': [dateparts[0]],
         'month': [dateparts[1]],
         'day': [dateparts[2]]
     }
Ejemplo n.º 8
0
 def from_request_data(self, field, request_data):
     """
     Pull out the parts and convert
     """
     if request_data == self.none_value_as_request_data(field):
         return self.empty
     year = request_data['year'][0].strip()
     month = request_data['month'][0].strip()
     day = request_data['day'][0].strip()
     if year or month or day:
         date_parts = (year, month, day)
     else:
         return self.empty
     return datetuple_converter(field.attr).to_type(date_parts)