def promote(self, sess, comment, investor, to_promote): if investor.firm == 0: return comment.reply_wrap(message.firm_none_org) user = sess.query(Investor).\ filter(func.lower(Investor.name) == func.lower(to_promote)).\ first() if (user is None) or (user.firm != investor.firm): return comment.reply_wrap(message.promote_failure_org) firm = sess.query(Firm).\ filter(Firm.id == user.firm).\ first() if user.firm_role == "": if (investor.firm_role == "") or (investor.firm_role == "assoc"): return comment.reply_wrap(message.not_ceo_or_exec_org) max_assocs = max_assocs_for_rank(firm.rank) if firm.assocs >= max_assocs: return comment.reply_wrap( message.modify_promote_assocs_full(firm)) user.firm_role = "assoc" firm.assocs += 1 elif user.firm_role == "assoc": if investor.firm_role != "ceo" and investor.firm_role != "coo": return comment.reply_wrap(message.not_ceo_or_coo_org) max_execs = max_execs_for_rank(firm.rank) if firm.execs >= max_execs: return comment.reply_wrap( message.modify_promote_execs_full(firm)) user.firm_role = "exec" firm.assocs -= 1 firm.execs += 1 elif user.firm_role == "exec": if investor.firm_role != "ceo": return comment.reply_wrap(message.not_ceo_org) if firm.cfo >= 1: return comment.reply_wrap(message.promote_cfo_full_org) user.firm_role = "cfo" firm.execs -= 1 firm.cfo += 1 elif user.firm_role == "cfo": if investor.firm_role != "ceo": return comment.reply_wrap(message.not_ceo_org) if firm.coo >= 1: return comment.reply_wrap(message.promote_coo_full_org) user.firm_role = "coo" firm.cfo -= 1 firm.coo += 1 elif user.firm_role == "coo": if investor.firm_role != "ceo": return comment.reply_wrap(message.not_ceo_org) # Swapping roles investor.firm_role = "coo" user.firm_role = "ceo" # Updating the flair in subreddits flair_role_user = '' if user.firm_role == "ceo": flair_role_user = "******" elif user.firm_role == "coo": flair_role_user = "******" elif user.firm_role == "cfo": flair_role_user = "******" elif user.firm_role == "exec": flair_role_user = "******" elif user.firm_role == "assoc": flair_role_user = "******" flair_role_investor = '' if investor.firm_role == "ceo": flair_role_investor = "CEO" elif investor.firm_role == "coo": flair_role_investor = "COO" elif investor.firm_role == "cfo": flair_role_investor = "CFO" elif investor.firm_role == "exec": flair_role_investor = "Executive" elif investor.firm_role == "assoc": flair_role_investor = "Associate" if not config.TEST: for subreddit in config.SUBREDDITS: REDDIT.subreddit(subreddit).flair.set( user.name, f"{firm.name} | {flair_role_user}") REDDIT.subreddit(subreddit).flair.set( investor.name, f"{firm.name} | {flair_role_investor}") return comment.reply_wrap(message.modify_promote(user))
def promote(self, sess, comment, investor, to_promote): if investor.firm == 0: return comment.reply_wrap(message.firm_none_org) user = sess.query(Investor).\ filter(func.lower(Investor.name) == func.lower(to_promote)).\ first() if (user is None) or (user.name == investor.name) or (user.firm != investor.firm): return comment.reply_wrap(message.promote_failure_org) firm = sess.query(Firm).\ filter(Firm.id == user.firm).\ first() user_role = user.firm_role if user_role == "": if (investor.firm_role == "") or (investor.firm_role == "assoc"): return comment.reply_wrap(message.not_ceo_or_exec_org) max_assocs = max_assocs_for_rank(firm.rank) if firm.assocs >= max_assocs: return comment.reply_wrap( message.modify_promote_assocs_full(firm)) user.firm_role = "assoc" firm.assocs += 1 elif user_role == "assoc": if investor.firm_role != "ceo" and investor.firm_role != "coo": return comment.reply_wrap(message.not_ceo_or_coo_org) max_execs = max_execs_for_rank(firm.rank) if firm.execs >= max_execs: return comment.reply_wrap( message.modify_promote_execs_full(firm)) user.firm_role = "exec" firm.assocs -= 1 firm.execs += 1 elif user_role == "exec": if investor.firm_role != "ceo": return comment.reply_wrap(message.not_ceo_org) # If the firm already has a CFO, the user will be promoted to COO if firm.cfo != '' and firm.cfo != 0: if firm.coo != '' and firm.coo != 0: return comment.reply_wrap(message.promote_coo_full_org) user.firm_role = "coo" firm.execs -= 1 firm.coo = user.name else: user.firm_role = "cfo" firm.execs -= 1 firm.cfo = user.name elif user_role == "cfo": if investor.firm_role != "ceo": return comment.reply_wrap(message.not_ceo_org) if firm.coo != '' and firm.coo != 0: return comment.reply_wrap(message.promote_coo_full_org) user.firm_role = "coo" firm.cfo = '' firm.coo = user.name elif user_role == "coo": if investor.firm_role != "ceo": return comment.reply_wrap(message.not_ceo_org) # Swapping roles investor.firm_role = "coo" firm.coo = investor.name user.firm_role = "ceo" firm.ceo = user.name # Updating the flair in subreddits flair_role_user = '' if user.firm_role == "ceo": flair_role_user = "******" if user.firm_role == "coo": flair_role_user = "******" if user.firm_role == "cfo": flair_role_user = "******" if user.firm_role == "exec": flair_role_user = "******" if user.firm_role == "assoc": flair_role_user = "******" # Investor role flair must be set in case COO and CEO roles are swapped flair_role_investor = '' if investor.firm_role == "ceo": flair_role_investor = "CEO" if investor.firm_role == "coo": flair_role_investor = "COO" if investor.firm_role == "cfo": flair_role_investor = "CFO" if investor.firm_role == "exec": flair_role_investor = "Executive" if investor.firm_role == "assoc": flair_role_investor = "Associate" if not config.TEST: for subreddit in config.SUBREDDITS: REDDIT.subreddit(subreddit).flair.set( user.name, f"{firm.name} | {flair_role_user}") REDDIT.subreddit(subreddit).flair.set( investor.name, f"{firm.name} | {flair_role_investor}") return comment.reply_wrap(message.modify_promote(user, user_role))