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 get_fb_id(access_token): url = "%s" % ("me") # retrieve fb id from local db cache coll = FBUser.collection() dic = coll.find_one({"access_token": str(access_token)}) fb_id = FBUser.unserialize(dic).fb_id if dic is not None else None # retrieve from fb graph api if not found in local db if fb_id is None: fb_id = GraphAPI(access_token).request(url)["id"] return fb_id
def save_obj(): fbUser_obj = FBUser() fbUser_obj.u_id = user_id fbUser_obj.fb_id = fb_id fbUser_obj.brand_name = brand_name fbUser_obj.access_token = access_token fbUser_obj.expires = token_expiry fbUser_obj._id = FBUser.collection().insert(fbUser_obj.serialize()) return fbUser_obj
def save_fb_user(user_id, brand_name, fb_id, access_token, token_expiry): def save_obj(): fbUser_obj = FBUser() fbUser_obj.u_id = user_id fbUser_obj.fb_id = fb_id fbUser_obj.brand_name = brand_name fbUser_obj.access_token = access_token fbUser_obj.expires = token_expiry fbUser_obj._id = FBUser.collection().insert(fbUser_obj.serialize()) return fbUser_obj # dupe check before inserting new fb user record into db fbUser_obj = FBUser.collection().find_one({"u_id": user_id, "fb_id": fb_id, "access_token": access_token}) if fbUser_obj is not None: saved_fb_user_obj = FBUser.unserialize(fbUser_obj) else: saved_fb_user_obj = save_obj() return saved_fb_user_obj
def del_fb_user(user_id, brand_name): del_fb_page(user_id, brand_name) FBUser.collection().remove({"u_id": user_id, "brand_name": brand_name})
def get_fb_user(user_id, brand_name): dic = FBUser.collection().find_one({"u_id": user_id, "brand_name": brand_name}) return FBUser.unserialize(dic) if dic is not None else None