def validate(self): if not form.Form.validate(self): return False if not self.user.data and not self.phone.data: self.phone.errors.append(u'用户和手机号必须要填一个') user1 = User.get_one(self.user.data) if self.user.data else None user2 = User.get_by_phone(self.phone.data) if self.phone.data else None if self.user.data and not user1: self.user.errors.append(u'用户不存在') return False if self.phone.data and not user2: self.phone.errors.append(u'用户不存在') return False if self.phone.data and self.user.data: if user1 != user2: self.user.errors.append(u'用户字段和手机号字段对应的用户不匹配') self.phone.errors.append(u'用户字段和手机号字段对应的用户不匹配') return False user = user1 or user2 if UserGroup.user_in_group(str(self.group.data), str(user._id)): if user1: self.user.errors.append(u'该组已包含此用户') if user2: self.phone.errors.append(u'该组已包含此用户') return False return True
def user_in_group(cls, gid, uid): group = Group.get_one(gid) # 用户组不存在直接返回True if group is None: return True _is_in_group = UserGroup.user_in_group(gid, uid) if group.gtype == const.WHITELIST_GROUP: return _is_in_group else: return not _is_in_group
def do_task(worker, job): from wanx.base.log import print_log from wanx.platforms.sms import SendSmsService from wanx.models.user import User, UserGroup data = job.data # 记录日志 print_log('send_sms', data) data = json.loads(data) if 'phones' in data: phones = data['phones'] else: uids = UserGroup.group_user_ids(data['group']) phones = [ user.phone for user in User.get_list(uids, check_online=False) ] content = data['content'] for phone in phones: if not phone: continue SendSmsService.send_report_warning(phone, content) return ''