예제 #1
0
파일: views.py 프로젝트: weaming/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))
예제 #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))
예제 #3
0
 class PostParams(params.ParamSet):
     a = params.IntegerField(required=True)
     b = params.Field()
예제 #4
0
파일: views.py 프로젝트: weaming/params
# 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))

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

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