def set_auth_qu_use(userids, qu_ids, is_add): userids = list(map(lambda x: ObjectId(x), userids)) qu_ids = list(map(lambda x: ObjectId(x), qu_ids)) if is_add: for userid in userids: for qu_id in qu_ids: has_qu = __get_qu(userid, qu_id) is not None if not has_qu: User.update_by_id_add(userid, { 'qus': { 'qu_id': ObjectId(qu_id), 'info': { 'auth': 1 } } }) else: User.update({'_id': { '$in': userids }}, {'$pull': { 'qus': { 'qu_id': { '$in': qu_ids } } }}) return True
def set_org(org_id, org): del org['_id'] old_org = Organization.get_by_id(org_id) if old_org.get('org_name') != org.get('org_name'): User.update({'user_info.org': old_org.get('org_name')}, {'$set': { 'user_info.org': org.get('org_name') }}) return Organization.update_by_id(org_id, org)