Exemplo n.º 1
0
def test_function():
    def base_func(value=0, *args, **kwargs):
        result = value + sum(args)
        if 'addition' in kwargs:
            result += kwargs['addition']
        return result

    function_field = fields.function(base_func)
    assert next(function_field) == 0

    function_field = fields.function(base_func, 1)
    assert next(function_field) == 1

    function_field = fields.function(base_func, 1, 2)
    assert next(function_field) == 3

    function_field = fields.function(base_func, 1, 2, addition=3)
    assert next(function_field) == 6
Exemplo n.º 2
0
    class UserAnonym(register_models.AnonymBase):
        email = fields.string('test_email_{seq}@preply.com',
                              seq_callback=datetime.datetime.now)
        username = fields.string('test_username_{seq}@preply.com',
                                 seq_callback=datetime.datetime.now)
        first_name = fields.string('first name {seq}')
        last_name = fields.string('last name {seq}')
        password = fields.password('password')
        is_staff = fields.function(lambda: False)

        class Meta:
            pass
Exemplo n.º 3
0
class UserAnonym(AnonymBase):
    email = fields.string('test_email_{seq}@preply.com',
                          seq_callback=datetime.datetime.now)
    username = fields.string('test_username_{seq}@preply.com',
                             seq_callback=datetime.datetime.now)
    first_name = fields.string('first name {seq}')
    last_name = fields.string('last name {seq}')
    password = fields.password('password')
    is_staff = fields.function(lambda: False)

    class Meta:
        exclude_fields = ['is_active', 'is_superuser',
                          'last_login', 'date_joined']
Exemplo n.º 4
0
class QuestionAnonym(AnonymBase):
    question_text = fields.string("John Doe {seq}")
    pub_date = fields.function(datetime.datetime.now)