Esempio n. 1
0
class ClassView(View):
    @use_params_class_view({
        'a': params.Field(required=True),
    })
    def get(self, request):
        assert request.params.a == '1'
        return HttpResponse(str(request.params))
Esempio n. 2
0
class PostJsonHandler(BaseHandler):
    @use_params(
        {
            'a': params.IntegerField(required=True),
            'b': params.Field(),
        },
        is_json=True)
    def post(self):
        print('params', self.params)
        if self.params.a != 1:
            raise params.InvalidParams('a != 1')
        if self.params.b and self.params.b != 'b':
            raise params.InvalidParams('b != b')
        return self.write(str(self.params))
Esempio n. 3
0
 class PostParams(params.ParamSet):
     a = params.IntegerField(required=True)
     b = params.Field()
Esempio n. 4
0
# coding: utf-8

from django.http import HttpResponse
from django.views.generic import View
import params
from params.contrib.django import use_params, use_params_class_view


def index(request):
    return HttpResponse(request.method)


@use_params({
    'a': params.Field(required=True),
    'b': params.ListField(),
})
def funcview(request):
    assert request.params.a == '1'
    assert request.params.b == [u'x', u'y']
    return HttpResponse(str(request.params))


class ClassView(View):
    @use_params_class_view({
        'a': params.Field(required=True),
    })
    def get(self, request):
        assert request.params.a == '1'
        return HttpResponse(str(request.params))

Esempio n. 5
0
 class DemoParams(params.ParamSet):
     a = params.Field()
Esempio n. 6
0
 class DemoParams(params.ParamSet):
     a_b = params.Field(key='a-b')
Esempio n. 7
0
    class DemoParams(params.ParamSet):
        a = params.Field(null=False)

        def validate_a(self, value):
            pass
Esempio n. 8
0
 class DemoHandler(RequestHandler):
     @use_params({
         'a': params.Field(),
     })
     def wtf(self):
         pass
Esempio n. 9
0
class FooParams(params.ParamSet):
    bar = params.WordField(choices=['a', 'b', 'c'])
    quz = params.Field()