def update_info(user_id, old_brand, new_brand, email): if new_brand is not None: Mapping.collection().update({"uid": user_id, "brand_name": old_brand}, {"$set": {"brand_name": new_brand}}) BrandMapping.collection().update({"uid": user_id, "brand_name": old_brand}, {"$set": {"brand_name": new_brand}}) FBUser.collection().update({"u_id": user_id, "brand_name": old_brand}, {"$set": {"brand_name": new_brand}}) TWUser.collection().update({"u_id": user_id, "brand_name": old_brand}, {"$set": {"brand_name": new_brand}}) FSQUser.collection().update({"u_id": user_id, "brand_name": old_brand}, {"$set": {"brand_name": new_brand}}) if email is not None: User.collection().update({"_id": user_id}, {"$set": {"emails.0.address": email}})
def save_fsq_user(user_id, brand_name, access_token): api = get_api() api.set_access_token(access_token) me = api.users()["user"] fsq_user = FSQUser() fsq_user.fsq_id = me["id"] fsq_user.u_id = user_id fsq_user.brand_name = brand_name fsq_user.first_name = key_check(me, "firstName") fsq_user.last_name = key_check(me, "lastName") fsq_user.fields = me dupe_obj = FSQUser.collection().find_one({"u_id": user_id, "brand_name": brand_name}) if dupe_obj is None: fsq_user._id = FSQUser.collection().insert(fsq_user.serialize()) else: FSQUser.collection().update({"u_id": user_id, "brand_name": brand_name}, fsq_user.serialize()) fsq_user = FSQUser.unserialize(FSQUser.collection().find_one({"u_id": user_id, "brand_name": brand_name})) update_brand_mapping(user_id, brand_name, "foursquare", fsq_user.fsq_id, access_token) return fsq_user
def get_fsq_user(user_id, brand_name): dic = FSQUser.collection().find_one({"u_id": user_id, "brand_name": brand_name}) return FSQUser.unserialize(dic) if dic is not None else None
def del_fsq_user(user_id, brand_name): update_brand_mapping(user_id, brand_name, "foursquare") FSQUser.collection().remove({"u_id": user_id, "brand_name": brand_name})