Exemplo n.º 1
0
    def validator(key, data, errors, context):
        value = data[key]
        date = None

        if value:
            if isinstance(value, datetime.datetime):
                date = sh.scheming_datetime_to_UTC(value)
            else:
                try:
                    date = sh.date_tz_str_to_datetime(value)
                except (TypeError, ValueError) as e:
                    raise Invalid(_('Date format incorrect'))
        else:
            extras = data.get(('__extras', ))
            if not extras or (key[0] + '_date' not in extras
                              and key[0] + '_time' not in extras):
                if field.get('required'):
                    not_empty(key, data, errors, context)
            else:
                date = validate_date_inputs(field, key, data, extras, errors,
                                            context)
                if isinstance(date, datetime.datetime):
                    date = sh.scheming_datetime_to_UTC(date)

        data[key] = date
Exemplo n.º 2
0
    def validator(key, data, errors, context):
        value = data[key]
        date = None

        if value:
            if isinstance(value, datetime.datetime):
                date = sh.scheming_datetime_to_UTC(value)
            else:
                try:
                    date = sh.date_tz_str_to_datetime(value)
                except (TypeError, ValueError), e:
                    raise Invalid(_('Date format incorrect'))
Exemplo n.º 3
0
    def validator(key, data, errors, context):
        value = data[key]
        date = None

        if value:
            if isinstance(value, datetime.datetime):
                date = sh.scheming_datetime_to_UTC(value)
            else:
                try:
                    date = sh.date_tz_str_to_datetime(value)
                except (TypeError, ValueError), e:
                    raise Invalid(_('Date format incorrect'))
Exemplo n.º 4
0
            else:
                try:
                    date = sh.date_tz_str_to_datetime(value)
                except (TypeError, ValueError), e:
                    raise Invalid(_('Date format incorrect'))
        else:
            extras = data.get(('__extras', ))
            if not extras or (key[0] + '_date' not in extras
                              and key[0] + '_time' not in extras):
                if field.get('required'):
                    not_empty(key, data, errors, context)
            else:
                date = validate_date_inputs(field, key, data, extras, errors,
                                            context)
                if isinstance(date, datetime.datetime):
                    date = sh.scheming_datetime_to_UTC(date)

        data[key] = date

    return validator


def scheming_multiple_choice_output(value):
    """
    return stored json as a proper list
    """
    if isinstance(value, list):
        return value
    try:
        return json.loads(value)
    except ValueError:
Exemplo n.º 5
0
            else:
                try:
                    date = sh.date_tz_str_to_datetime(value)
                except (TypeError, ValueError), e:
                    raise Invalid(_('Date format incorrect'))
        else:
            extras = data.get(('__extras',))
            if not extras or (key[0] + '_date' not in extras and
                              key[0] + '_time' not in extras):
                if field.get('required'):
                    not_empty(key, data, errors, context)
            else:
                date = validate_date_inputs(
                    field, key, data, extras, errors, context)
                if isinstance(date, datetime.datetime):
                    date = sh.scheming_datetime_to_UTC(date)

        data[key] = date

    return validator


def scheming_valid_json_object(value, context):
    """Store a JSON object as a serialized JSON string

    It accepts two types of inputs:
        1. A valid serialized JSON string (it must be an object or a list)
        2. An object that can be serialized to JSON

    """
    if not value: