Ejemplo n.º 1
0
class UserTestResource(resources.ModelResource):
    parent_resource_path = 'users'
    model_class = User

    validators = [DatetimeFieldSequenceValidator('before', 'after')]

    fields = [
        fields.AttributeField(attribute='name',
                              type=str,
                              validator=StringFieldExactMatchValidator('Bob')),
        fields.AttributeField(attribute='age',
                              type=int,
                              validator=(IntFieldMinValidator(
                                  21, error_message='too young to drink'),
                                         IntFieldPrimeValidator(100))),
        fields.AttributeField(attribute='before',
                              type=datetime,
                              validator=DatetimeFieldMinValidator(
                                  long_ago,
                                  error_message='keep it recent',
                              )),
        fields.AttributeField(attribute='after',
                              type=datetime,
                              validator=DatetimeFieldMaxValidator(
                                  too_late, error_message='do not be late')),
        fields.AttributeField(
            attribute='systolic_bp',
            type=int,
            validator=IntFieldRangeValidator(
                100, 120, error_message='blood pressure out of range')),
        fields.SubModelResourceField('vehicle', CarTestResource),
        fields.SubModelResourceField('stolen_vehicle',
                                     StolenCarTestResource,
                                     skip_validation=True),
    ]
Ejemplo n.º 2
0
class UnaddressableUserResource(resources.ModelResource):
    model_class = User

    fields = [
        fields.AttributeField(attribute='name', type=str),
        fields.AttributeField(attribute='age', type=int)
    ]
Ejemplo n.º 3
0
class UserResource(resources.ModelResource):
    parent_resource_path = 'users'
    model_class = User

    fields = [
        fields.AttributeField(attribute='name', type=str),
        fields.AttributeField(attribute='age', type=int)
    ]
Ejemplo n.º 4
0
class StolenCarTestResource(resources.ModelResource):
    parent_resource_path = 'stolencars'
    model_class = Car

    validators = [CarIsStolenValidator()]

    fields = [
        fields.AttributeField(attribute='make', type=str),
        fields.AttributeField(attribute='year', type=int)
    ]
Ejemplo n.º 5
0
class ComplexUserRelationResource(resources.ModelResource):
    model_class = User

    owner_field = fields.SubModelResourceField(attribute='owner', resource_class=UserOwnerResource)

    fields = [
        fields.AttributeField(attribute='name', type=str),
        fields.AttributeField(attribute='age', type=int),
        owner_field,
    ]
Ejemplo n.º 6
0
class GroupResource(resources.ModelResource):
    parent_resource_path = 'groups'
    model_class = Group

    fields = [
        fields.AttributeField('name', type=str),
    ]
Ejemplo n.º 7
0
class BugOnWindshieldResource(resources.ModelResource):
    parent_resource_path = 'bug'
    model_class = BugOnWindshield
    fields = [
        fields.AttributeField(attribute='color', type=str),
        fields.ReverseField('car')
    ]
Ejemplo n.º 8
0
class PersonResource(resources.ModelResource):
    parent_resource_path = 'person'
    model_class = Person

    fields = [
        fields.AttributeField('name', type=str),
        fields.RelatedManagerField('groups', GroupResource),
    ]
Ejemplo n.º 9
0
class RequiredCarTestResource(resources.ModelResource):
    parent_resource_path = 'cars'
    model_class = Car

    fields = [
        fields.AttributeField(attribute='make', type=str),
        fields.AttributeField(attribute='year', type=int),
    ]

    validators = [
        RequiredTogetherValidator(
            'make',
            'year',
            null=True,
            error_message=u'Make and year are required if either is provided.'
        ),
    ]
Ejemplo n.º 10
0
class DjangoUserResource(resources.ModelResource):
    '''
    Exists to test SchemaResource using Django's User model
    '''
    model_class = DjangoUser
    fields = [
        fields.AttributeField('date_joined', type=datetime),
    ]
Ejemplo n.º 11
0
class CarTestResource(resources.ModelResource):
    parent_resource_path = 'cars'
    model_class = Car

    validators = [CarNotUglyValidator()]

    fields = [
        fields.AttributeField(
            attribute='make',
            type=str,
            validator=StringFieldExactMatchValidator(
                'Toyota', error_message='why is he not driving a Toyota?')),
        fields.AttributeField(attribute='year',
                              type=int,
                              validator=IntFieldMinValidator(
                                  2010, error_message='car is too old')),
        fields.RelatedManagerField(attribute='bugs',
                                   resource_class=BugOnWindshieldResource,
                                   validator=BugValidator())
    ]
Ejemplo n.º 12
0
        class UserOwnerResource(resources.ModelResource):
            model_class = UserOwner

            fields = [
                fields.AttributeField(attribute='type', type=str),
            ]
Ejemplo n.º 13
0
 class TestResource(resources.ModelResource):
     model_class = User
     fields = [
         fields.AttributeField(attribute='group.name', type=str),
         fields.AttributeField(attribute='domain.name', type=str)
     ]