예제 #1
0
파일: forms.py 프로젝트: wetriba/formish
    def _set_request(self, request):
        """
        Assign raw request data to the form

        :arg request_data: raw request data (e.g. request.POST)
        :type request_data: Dictionary (dotted or nested or dotted or MultiDict)
        """
        self._request = request
        request_data = getattr(request, self.method.upper())
        # Decode request data according to the request's charset.
        request_data = UnicodeMultiDict(
            request_data, encoding=util.get_post_charset(request))
        # Remove the sequence factory data from the request
        for k in request_data.keys():
            if '*' in k:
                request_data.pop(k)
        # We need the _request_data to be populated so sequences know how many
        # items they have (i.e. .fields method on a sequence uses the number of
        # values on the _request_data)

        # Convert request data to a dottedish friendly representation
        request_data = _unflatten_request_data(request_data)
        self._request_data = dotted(request_data)
        self._request_data = dotted(
            self.widget.pre_parse_incoming_request_data(
                self.structure, request_data))
예제 #2
0
파일: test_util.py 프로젝트: ish/formish
 def test_charset_detection(self):
     tests = [
         # form field takes precedence
         (('utf-8', 'iso-8859-1'), 'utf-8'),
         # header used next
         (('', 'iso-8859-1'), 'iso-8859-1'),
         # default to utf-8
         (('', ''), 'utf-8'),
         # nonsense in form field
         (('Xuhuwef', 'utf-8'), 'utf-8'),
     ]
     for test, expected in tests:
         request = webob.Request.blank(
             '/', POST={'_charset_': test[0]},
             headers=[('Content-Type', 'application/x-www-form-urlencoded;charset=%s'%test[1])])
         self.assertEqual(util.get_post_charset(request), expected)
예제 #3
0
 def test_charset_detection(self):
     tests = [
         # form field takes precedence
         (('utf-8', 'iso-8859-1'), 'utf-8'),
         # header used next
         (('', 'iso-8859-1'), 'iso-8859-1'),
         # default to utf-8
         (('', ''), 'utf-8'),
         # nonsense in form field
         (('Xuhuwef', 'utf-8'), 'utf-8'),
     ]
     for test, expected in tests:
         request = webob.Request.blank(
             '/',
             POST={'_charset_': test[0]},
             headers=[
                 ('Content-Type',
                  'application/x-www-form-urlencoded;charset=%s' % test[1])
             ])
         self.assertEqual(util.get_post_charset(request), expected)
예제 #4
0
파일: forms.py 프로젝트: zvoase/formish
 def validate(self, request, failure_callable=None, success_callable=None):
     """ 
     Get the data without raising exceptions and then validate the data. If
     there are errors, raise them; otherwise return the data
     """
     # If we pass in explicit failure and success callables then do this
     # first
     if failure_callable is not None and success_callable is not None:
         return self._validate_and_call(request, \
                       failure_callable=None, success_callable=None)
     self.errors = {}
     # Check this request was POSTed by this form.
     if not request.method =='POST' and \
        request.POST.get('__formish_form__',None) == self.name:
         raise Exception("request does not match form name")
     
     request_post = UnicodeMultiDict(request.POST, \
                     encoding=util.get_post_charset(request))
     # Remove the sequence factory data from the request
     for k in request_post.keys():
         if '*' in k:
             request_post.pop(k)
     # We need the _request_data to be populated so sequences know how many
     # items they have (i.e. .fields method on a sequence uses the number of
     # values on the _request_data)
     self._request_data = dottedDict(request_post)
     self.request_data = validation.pre_parse_request_data( \
                 self.structure,dottedDict(request_post))
     data = self.get_unvalidated_data( \
                 self.request_data, raise_exceptions=False)
     #self._request_data = dottedDict(request_post)
     try:
         self.structure.attr.validate(data)
     except schemaish.attr.Invalid, e:
         for key, value in e.error_dict.items():
             if key not in self.errors:
                 self.errors[key] = value
예제 #5
0
파일: forms.py 프로젝트: ish/formish
    def _set_request(self, request):
        """
        Assign raw request data to the form

        :arg request_data: raw request data (e.g. request.POST)
        :type request_data: Dictionary (dotted or nested or dotted or MultiDict)
        """
        self._request = request
        request_data = getattr(request, self.method.upper())
        # Decode request data according to the request's charset.
        request_data = UnicodeMultiDict(request_data,
                                        encoding=util.get_post_charset(request))
        # Remove the sequence factory data from the request
        for k in request_data.keys():
            if '*' in k:
                request_data.pop(k)
        # We need the _request_data to be populated so sequences know how many
        # items they have (i.e. .fields method on a sequence uses the number of
        # values on the _request_data)

        # Convert request data to a dottedish friendly representation
        request_data = _unflatten_request_data(request_data)
        self._request_data = dotted(request_data)
        self._request_data = dotted(self.widget.pre_parse_incoming_request_data(self.structure,request_data))