Python源码示例:odoo.exceptions.ValidationError()
示例1
def do_mass_update(self):
self.ensure_one()
if not (self.new_deadline or self.new_user_id):
raise exceptions.ValidationError('No data to update!')
# Logging debug messages
_logger.debug(
'Mass update on Todo Tasks %s',
self.task_ids.ids)
vals = {}
if self.new_deadline:
vals['date_deadline'] = self.new_deadline
if self.new_user_id:
vals['user_id'] = self.new_user_id
# Mass write values on all selected tasks
if vals:
self.task_ids.write(vals)
return True
示例2
def write(self, vals):
try:
for each_record in self:
if 'sort' in vals.keys() and vals.get('sort') != each_record.sort:
each_record._write(vals)
goods_ids = self.env['wechat_mall.goods'].with_context({'recompute': True}).browse(
each_record._goods_ids())
if goods_ids:
for goods_id in goods_ids:
goods_id.write({'price_ids': [(6, 0, goods_id._price_ids().ids)]})
else:
each_record._write(vals)
except Exception as e:
raise exceptions.ValidationError(e)
else:
return True
示例3
def update_batch(self):
self.ensure_one()
if not (self.new_is_closed or self.wizard_user_id):
raise exceptions.ValidationError('无数据要更新')
_logger.debug('批量bug更新操作 %s',self.bug_ids.ids)
vals={}
if self.new_is_closed:
vals['is_closed']=self.new_is_closed
if self.wizard_user_id:
vals['user_id']=self.wizard_user_id
if vals:
self.bug_ids.write(vals)
return True
示例4
def website_form_input_filter(self, request, values):
if values.get('name'):
# Modify values
values['name'] = values['name'].strip()
# Validate values
if len(values['name']) < 3:
raise ValidationError(
'名称长度不可以少于3个字符')
return values
示例5
def _constrain_isbn_valid(self):
for book in self:
if book.isbn and not book._check_isbn():
raise ValidationError(
'%s is an invalid ISBN' % book.isbn)
示例6
def _constrain_isbn_valid(self):
for book in self:
if book.isbn and not book._check_isbn():
raise ValidationError(
'%s is an invalid ISBN' % book.isbn)
示例7
def _constrain_isbn_valid(self):
for book in self:
if book.isbn and not book._check_isbn():
raise ValidationError(
'%s is an invalid ISBN' % book.isbn)
示例8
def generate_token(self):
config = self.env['wxxcx.config']
secret_key = config.get_config('secret', self.create_uid.id)
app_id = config.get_config('app_id', self.create_uid.id)
if not secret_key or not app_id:
raise exceptions.ValidationError('未设置 secret_key 或 appId')
s = Serializer(secret_key=secret_key, salt=app_id, expires_in=AccessToken._transient_max_hours * 3600)
timestamp = time.time()
return s.dumps({'session_key': self.session_key, 'open_id': self.open_id, 'iat': timestamp})
示例9
def check_dates(self):
for record in self:
start_date = fields.Date.from_string(record.start_date)
end_date = fields.Date.from_string(record.end_date)
if start_date > end_date:
raise ValidationError(_("End Date cannot be set before \
Start Date."))
示例10
def check_subject(self):
# 检查科目是否属于课程
if(self.subject_id not in self.schedule_id.course_id.subject_ids):
raise ValidationError(('''科目%s不属于课程计划%s''')%(self.subject_id.name,
self.schedule_id.name))
示例11
def check_teacher(self):
#检查教师是否可以进行对应科目的授课
if(self.subject_id not in self.teacher_id.teacher_subject_ids):
raise ValidationError(('''教师%s不可以进行科目%s的授课''')%(self.teacher_id.name,
self.subject_id.name))
示例12
def _check_date_time(self):
if self.start_datetime > self.end_datetime:
raise ValidationError(_(
'End Time cannot be set before Start Time.'))
示例13
def _check_birthdate(self):
for record in self:
if record.birth_date > fields.Date.today():
raise ValidationError(_(
"出生日期不可以晚于今天!"))
示例14
def check_dates(self):
start_date = fields.Date.from_string(self.start_date)
end_date = fields.Date.from_string(self.end_date)
if start_date > end_date:
raise ValidationError(_("End Date cannot be set before \
Start Date."))
示例15
def do_mass_update(self):
self.ensure_one()
if not self.new_deadline and not self.new_user_id:
raise exceptions.ValidationError('No data to update!')
_logger.debug('Mass update on Todo Tasks %s' % self.task_ids)
# Values to Write
vals = {}
if self.new_deadline:
vals['date_deadline'] = self.new_deadline
if self.new_user_id:
vals['user_id'] = self.new_user_id
# Mass write values on all selected tasks
if vals:
self.task_ids.write(vals)
return True
示例16
def do_mass_update(self):
self.ensure_one()
if not self.new_deadline and not self.new_user_id:
raise exceptions.ValidationError('No data to update!')
_logger.debug('Mass update on Todo Tasks %s' % self.task_ids)
# Values to Write
vals = {}
if self.new_deadline:
vals['date_deadline'] = self.new_deadline
if self.new_user_id:
vals['user_id'] = self.new_user_id
# Mass write values on all selected tasks
if vals:
self.task_ids.write(vals)
return True
示例17
def do_toggle_done(self):
for task in self:
if task.user_id != self.env.user:
raise ValidationError(
'Only the responsible can do this!')
return super(TodoTask, self).do_toggle_done()
示例18
def _check_name_size(self):
for todo in self:
if len(todo.name) < 5:
raise ValidationError('Title must have 5 chars!')
# Chapter 06 Smart Button statistic
示例19
def _check_name_size(self):
for todo in self:
if len(todo.name) < 5:
raise ValidationError('Title must have 5 chars!')
# Chapter 06 Smart Button statistic
示例20
def website_form_input_filter(self, request, values):
if 'name' in values:
values['name'] = values['name'].strip()
if len(values['name']) < 3:
raise ValidationError(
'Text must be at least 3 characters long')
return values
示例21
def _check_name_size(self):
for todo in self:
if len(todo.name) < 5:
raise ValidationError('Title must have 5 chars!')
# Chapter 06 - On Change
示例22
def _check_name_size(self):
for todo in self:
if len(todo.name) < 5:
raise ValidationError('Title must have 5 chars!')
示例23
def _check_name_size(self):
for todo in self:
if len(todo.name) < 5:
raise ValidationError('Title must have 5 chars!')
# Chapter 06 - On Change
示例24
def website_form_input_filter(self, request, values):
if 'name' in values:
values['name'] = values['name'].strip()
if len(values['name']) < 3:
raise ValidationError(
'Text must be at least 3 characters long')
return values
示例25
def _check_name_size(self):
for todo in self:
if len(todo.name) < 5:
raise ValidationError('Title must have 5 chars!')
示例26
def _check_name_size(self):
for todo in self:
if len(todo.name) < 5:
raise ValidationError('Title must have 5 chars!')
# Chapter 06 - On Change
示例27
def _check_name_size(self):
for todo in self:
if len(todo.name) < 5:
raise ValidationError('Title must have 5 chars!')
# Chapter 06 - On Change
示例28
def _check_active(self):
# do not check during installation
if self.env.registry.ready and not self.search_count([]):
raise ValidationError(_('At least one language must be active.'))
示例29
def _check_format(self):
for lang in self:
for pattern in lang._disallowed_datetime_patterns:
if (lang.time_format and pattern in lang.time_format) or \
(lang.date_format and pattern in lang.date_format):
raise ValidationError(_('Invalid date/time format directive specified. '
'Please refer to the list of allowed directives, '
'displayed when you edit a language.'))
示例30
def _check_grouping(self):
warning = _('The Separator Format should be like [,n] where 0 < n :starting from Unit digit. '
'-1 will end the separation. e.g. [3,2,-1] will represent 106500 to be 1,06,500;'
'[1,2,-1] will represent it to be 106,50,0;[3] will represent it as 106,500. '
'Provided as the thousand separator in each case.')
for lang in self:
try:
if not all(isinstance(x, int) for x in json.loads(lang.grouping)):
raise ValidationError(warning)
except Exception:
raise ValidationError(warning)