def _validate_python(self, value, state): params = urlencode({ 'secret': self.secret, 'remoteip': self.remote_ip, 'response': value }).encode('utf-8') request = Request( url="https://www.google.com/recaptcha/api/siteverify", data=params, headers={ 'Content-type': "application/x-www-form-urlencoded", 'User-agent': "tw2.recaptcha2 Python" }) with urlopen(request) as http_response: response_dict = json.loads(http_response.read().decode('utf-8')) if not response_dict['success']: error_codes = response_dict.get('error-codes', []) if 'invalid-input-response' in error_codes: raise ValidationError('invalid') elif 'missing-input-response' in error_codes: raise ValidationError('missing') else: raise ValidationError('error')
def _validate_python(self, value, state=None): try: found = self.entity.query.get(_id=ObjectId(value)) except (InvalidId, TypeError): raise ValidationError('not_exists', self) if found is None: raise ValidationError('not_exists', self)
def _validate_python(self, value, state=None): document_accepted_type = ['output'] for cond in value: if cond['type'] == 'output': output = model.Output.query.get(_id=ObjectId(cond['content'])) if not output: raise ValidationError(l_(u'Output not found.'), self) else: raise ValidationError(l_(u'Invalid Filter.'), self)
def _validate_python(self, value, state=None): for cond in value: if cond['type'] == 'qa_response': qa = model.Qa.query.get(_id=ObjectId(cond['content'])) if not qa: raise ValidationError(l_(u'Question not found.'), self) elif cond['type'] == 'output': out = model.Output.query.get(_id=ObjectId(cond['content'])) if not out: raise ValidationError(l_(u'Output not found'), self) else: raise ValidationError(l_(u'Invalid Filter.'), self)
def _validate_python(self, value, state=None): found = None try: found = self.entity.by_id(value) except InvalidId: if 'by_hash' in dir(self.entity): found = self.entity.by_hash(value) if not found: raise ValidationError('not_exists', self)
def _validate_python(self, values, state=None): mail_model_id = values.get(self.mail_model_id) language = values.get(self.language) template_given = None if self.translation_id: # edit_mode translation_id = values.get(self.translation_id) __, templates_given = model.provider.query(model.TemplateTranslation, filters=dict(_id=translation_id)) if not templates_given: return template_given = templates_given[0] __, templates = model.provider.query( model.TemplateTranslation, filters=dict(mail_model_id=_to_object_id(mail_model_id), language=language) ) if templates: if not template_given: raise ValidationError(_('Template for this language already created.')) elif template_given.language != templates[0].language: raise ValidationError(_('Template for this language already created.'))
def _validate_python(self, value, state=None): count, _ = model.provider.query(app_model.User, filters=dict(email_address=value)) if count < 1: raise ValidationError( self.msgs.get('user_not_found', 'User not found'), self)
def _validate_python(self, value, state=None): if value['type'] not in [v_type[0] for v_type in VISUALIZATION_TYPES]: raise ValidationError('Not a valid Visualization Type', self)
def _validate_python(self, value, state=None): try: json.loads(value) except: raise ValidationError('Invalid JSON', self)
def _validate_python(self, value, state=None): outputs, __ = get_entities_from_str(value) if None in outputs: raise ValidationError(l_(u'Output not found.'), self)