def _user_list(organization=None, with_flag=None, include_notifications=True): if organization is not None: organization = _getOrganization(organization) result = User.list(organization=organization, include_notifications=include_notifications) if with_flag: result = filter(lambda u: with_flag in u.flags, result) return result
def broadcast_message_multifilter(title, message, fromUser=None, ref=None, subject_group=None, filters=None): """ takes a list of filters to broadcast a message. sends one message to each user who matches at least one filter. :param str title: message subject :param str message: message body :param NoneType or str fromUser: sending user :param NoneType or tuple(str, str) ref: ref pair :param NoneType or str subject_group: subject group :param NoneType or list(tuple) filters: list of pairs (organization, flag). if this is None, send to every user. """ if filters is None: filters = [(None, None)] target_users = set() for filter_pair in filters: if filter_pair[0]: organization = _getOrganization(filter_pair[0]) users = User.objects(organization=organization) else: users = User.objects.all() if filter_pair[1]: users = filter(lambda u: filter_pair[1] in u.flags, users) target_users.update([u.name for u in users]) for username in target_users: _getUser(username).send_message(fromUser=fromUser, subject=title, message=message, ref=ref, subject_group=subject_group)
def _user_list(organization=None, with_flag=None): if organization: organization = _getOrganization(organization) result = User.objects(organization=organization) else: result = User.objects.all() if with_flag: result = filter(lambda u: with_flag in u.flags, result) return result
def organization_exists(name): if _getOrganization(name): return True return False
def organization_modify(name, args): orga = _getOrganization(name) orga.modify(**args) return orga.info()
def organization_remove(name): orga = _getOrganization(name) orga.remove() return True
def organization_info(name): orga = _getOrganization(name) return orga.info()