コード例 #1
0
ファイル: validation.py プロジェクト: Marlburo/inventory
    def __init__(self, required=None, validated=None, **kwargs):
        if required is None:
            required = []

        if validated is None:
            validated = []

        all_methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']

        self.required_fields = {}
        self.validated_fields = {}

        dicts = {'required': self.required_fields,
                 'validated': self.validated_fields}

        self.map_method_validations(self.required_fields,
            required, all_methods)
        self.map_method_validations(self.validated_fields,
            validated, all_methods)

        for key, value in kwargs.items():
            for arr_name in ['required', 'validated']:
                if key[:len(arr_name)] == arr_name:
                    methods = self.parse_methods_key(key, arr_name)
                    self.map_method_validations(dicts[arr_name],
                        value, methods)

        Validation.__init__(self)
    def __init__(self, required=None, validated=None, **kwargs):
        if required is None:
            required = []

        if validated is None:
            validated = []

        all_methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']

        self.required_fields = {}
        self.validated_fields = {}

        dicts = {
            'required': self.required_fields,
            'validated': self.validated_fields
        }

        self.map_method_validations(self.required_fields, required,
                                    all_methods)
        self.map_method_validations(self.validated_fields, validated,
                                    all_methods)

        for key, value in kwargs.items():
            for arr_name in ['required', 'validated']:
                if key[:len(arr_name)] == arr_name:
                    methods = self.parse_methods_key(key, arr_name)
                    self.map_method_validations(dicts[arr_name], value,
                                                methods)

        Validation.__init__(self)
コード例 #3
0
    def test_init(self):
        try:
            Validation()
        except Exception:
            self.fail("Initialization failed when it should have succeeded.")

        try:
            Validation(form_class='foo')
        except Exception:
            self.fail(
                "Initialization failed when it should have succeeded again.")
コード例 #4
0
    def test_is_valid(self):
        valid = Validation()
        bundle = Bundle()
        self.assertEqual(valid.is_valid(bundle), {})

        bundle = Bundle(data={
            'title': 'Foo.',
            'slug': 'bar',
            'content': '',
            'is_active': True,
        })
        self.assertEqual(valid.is_valid(bundle), {})
コード例 #5
0
ファイル: validation.py プロジェクト: Concert/django-tastypie
 def test_is_valid(self):
     valid = Validation()
     bundle = Bundle()
     self.assertEqual(valid.is_valid(bundle), {})
     
     bundle = Bundle(data={
         'title': 'Foo.',
         'slug': 'bar',
         'content': '',
         'is_active': True,
     })
     self.assertEqual(valid.is_valid(bundle), {})
コード例 #6
0
    class Meta:
        queryset = Node.objects.all()
        resource_name = 'node'
        authorization = Authorization()
        validation = Validation()

        always_return_data = True
コード例 #7
0
 class Meta:
     queryset = Todo.objects.all()
     authorization = DjangoAuthorization()
     authentication = BasicAuthentication()
     resource_name = 'todo'
     validation = Validation()
     filtering = {'id': ['exact'], 'done': ['exact']}
コード例 #8
0
 class Meta:
     resource_name = 'job'
     allowed_methods = ['post']
     detail_allowed_methods = []
     authorization = ReadOnlyAuthorization()
     serializer = Serializer(formats=['json'])
     always_return_data = True
     validation = Validation()
     object_class = None
コード例 #9
0
    class Meta:
        resource_name = "test"
        authorization = Authorization()
        validation = Validation()
        queryset = TestArea.objects.all()

        filtering = {
            'polys': ALL,
        }
class ValidationTestCase(TestCase):
    def test_init(self):
        try:
            valid = Validation()
        except Exception, e:
            self.fail("Initialization failed when it should have succeeded.")

        try:
            valid = Validation(form_class='foo')
        except Exception, e:
            self.fail("Initialization failed when it should have succeeded again.")
コード例 #11
0
ファイル: api.py プロジェクト: ojengwa/apipanda
    class Meta:

        always_return_data = True
        allowed_methods = ['get', 'post', 'put', 'patch', 'options', 'head']

        authentication = Authentication
        authorization = DjangoAuthorization()
        validation = Validation()
        collection_name = 'data'
        cache = SimpleCache(timeout=10)
        throttle = CacheDBThrottle(throttle_at=settings.THROTTLE_TIMEOUT)
コード例 #12
0
ファイル: resources.py プロジェクト: joelazar/practice_django
 class Meta:
     allowed_methods = ['get', 'put']
     authentication = MyAuthentication()
     authorization = MyAuthorization()
     filtering = {
         "presentation_id": ('exact', ),
         "creator": ALL,
         "title": ALL,
     }
     ordering = ['created_at']
     paginator_class = Paginator
     queryset = Presentation.objects.all()
     resource_name = 'presentation'
     serializer = PrettyJSONSerializer()
     validation = Validation()
コード例 #13
0
ファイル: api.py プロジェクト: fredericosachweh/amostra1
 class Meta:
     SetTopBoxChannel = apps.get_model('client', 'SetTopBoxChannel')
     queryset = SetTopBoxChannel.objects.all()
     resource_name = 'settopboxchannel'
     allowed_methods = ['get', 'post', 'delete', 'put', 'patch']
     always_return_data = True
     filtering = {
         "settopbox": ALL,
         "channel": ALL
     }
     validation = Validation()
     authorization = MyAuthorization()
     authentication = MultiAuthentication(
         BasicAuthentication(realm='cianet-middleware'),
         Authentication(),
         ApiKeyAuthentication())
コード例 #14
0
ファイル: api.py プロジェクト: fredericosachweh/amostra1
 class Meta(object):
     SetTopBoxParameter = apps.get_model('client', 'SetTopBoxParameter')
     queryset = SetTopBoxParameter.objects.all()
     resource_name = 'settopboxparameter'
     allowed_methods = ['get', 'post', 'delete', 'put', 'patch']
     urlconf_namespace = 'client'
     always_return_data = True
     filtering = {
         "settopbox": ALL,  # ALL_WITH_RELATIONS
         "key": ALL,
         "value": ALL
     }
     validation = Validation()
     authorization = MyAuthorization()
     authentication = MultiAuthentication(
         BasicAuthentication(realm='cianet-middleware'),
         Authentication(),
         ApiKeyAuthentication())
コード例 #15
0
class ResourceOptions(object):
    """
    A configuration class for ``Resource``.
    
    Provides sane defaults and the logic needed to augment these settings with
    the internal ``class Meta`` used on ``Resource`` subclasses.
    """
    serializer = Serializer()
    authentication = Authentication()
    authorization = ReadOnlyAuthorization()
    cache = NoCache()
    throttle = BaseThrottle()
    validation = Validation()
    limit = getattr(settings, 'API_LIMIT_PER_PAGE', 20)
    route = None
    default_format = 'application/json'
    filtering = {}
    ordering = []
    object_class = None
    queryset = None
    fields = []
    excludes = []
    include_resource_uri = True
    include_absolute_url = False
    
    # only applies to TOC resource
    resources = []
    
    # only here for compatibility / deprecated
    api_name = None
    resource_name = ''
    
    def __new__(cls, meta=None):
        overrides = {}
        
        # Handle overrides.
        if meta:
            for override_name in dir(meta):
                # No internals please.
                if not override_name.startswith('_'):
                    overrides[override_name] = getattr(meta, override_name)
               
        return object.__new__(type('ResourceOptions', (cls,), overrides))
コード例 #16
0
ファイル: api.py プロジェクト: fredericosachweh/amostra1
 class Meta:
     SetTopBoxConfig = apps.get_model('client', 'SetTopBoxConfig')
     queryset = SetTopBoxConfig.objects.all()
     resource_name = 'settopboxconfig'
     allowed_methods = ['get', 'post', 'delete', 'put', 'patch']
     urlconf_namespace = 'client'
     fields = ['key', 'value', 'value_type']
     max_limit = 5000
     limit = 2000
     always_return_data = True
     filtering = {
         "key": ALL,
         "value_type": ALL,
         "settopbox": ALL
     }
     authorization = SetTopBoxAuthorization()
     validation = Validation()
     authentication = MultiAuthentication(
         ApiKeyAuthentication(),
         BasicAuthentication(realm='cianet-middleware'),
         Authentication(),)
コード例 #17
0
 def test_init_no_args(self):
     try:
         Validation()
     except Exception:
         self.fail("Initialization failed when it should have succeeded.")
コード例 #18
0
 def test_init(self):
     try:
         valid = Validation()
     except Exception, e:
         self.fail("Initialization failed when it should have succeeded.")