예제 #1
0
파일: oncall.py 프로젝트: CBarraford/Oncall
def user_list(opts):
	'''
	List users. Filter with options.
	'''
	all_users = User.all_users()
	users = []
	# init these variables with value True
	(id, name, phone, email, team, state) = [True] * 6
	# filter users with options given
	for u in all_users:
		if opts.id != 0 and u.id != opts.id: id = False
		if opts.name != '' and u.name != opts.name: name = False
		if opts.phone != '' and u.phone != opts.phone: phone = False
		if opts.email != '' and u.email != opts.email: email = False
		if opts.team != '' and u.team != opts.team: team = False
		if opts.state != 100 and u.state != opts.state: state = False
		# see if all values given match attributes for user object
		if id == True and name == True and phone == True and email == True and team == True and state == True: users.append(u)
	if len(users) == 0: return "No users."
	if opts.delete == True:
		output = "Deleting users...\n"
	else:
		output = ''
	for u in users:
		output=output + "%s" % (u.print_user(opts.mobile))
		if opts.delete == True: u.delete_user()
	return output
예제 #2
0
	def query(self):
		if self.target == "alert" or self.target == "alerts":
			objects = Alert.all_alerts()
		elif self.target == "user" or self.target == "users":
			objects = User.all_users()
		else:
			self.populate(1101,"Invalid API query call: Missing valid target parameter")
			return
		dict_objs = []
		for x in objects:
			dict_objs.append(x.convert_to_dict())
			if len(dict_objs) >= self.count: break
		self.populate(200,"OK",json.dumps(dict_objs))
예제 #3
0
 def query(self):
     if self.target == "alert" or self.target == "alerts":
         objects = Alert.all_alerts()
     elif self.target == "user" or self.target == "users":
         objects = User.all_users()
     else:
         self.populate(
             1101, "Invalid API query call: Missing valid target parameter")
         return
     dict_objs = []
     for x in objects:
         dict_objs.append(x.convert_to_dict())
         if len(dict_objs) >= self.count: break
     self.populate(200, "OK", json.dumps(dict_objs))