def send_group_addition_email(inviter_name, inviter_email, member_uuid, group_name, group_uuid): db_sesh = Session() dbcall = DBCallsWrapper() # check if user being added to the group is subscribed to email notifications send_email_state = is_subscribed_to_emails(db_sesh, member_uuid) if send_email_state[0] and send_email_state[1]: u_db = send_email_state[1] unsubscribe_obj = dbcall.query_unsubscribetoken_by_(session_obj=db_sesh, user=u_db.uuid) unsubscribe_token = unsubscribe_obj.code group_link = f"{settings['MONEYVIGIL_LINK_PREFIX']}/groups/{group_uuid}" unsubscribe_link = f"{settings['MONEYVIGIL_LINK_PREFIX']}/unsubscribe/{unsubscribe_token}" formatting_args = { 'name': u_db.name, 'group_name': group_name, 'group_link': group_link, 'inviter_name': inviter_name, 'inviter_email': inviter_email, 'unsubscribe_link': unsubscribe_link } email_body = group_addition_email_body.format(**formatting_args) send_ses_email( email_addr=u_db.email, subject='You have been added to a MoneyVigil group', text=email_body ) Session.remove()
def get_db_session(): if hasattr(request, 'db_session'): return request.db_session else: request.db_session = Session() return request.db_session
import bcrypt import time from db_session import Session from dynaconf import settings hashed_pw = bcrypt.hashpw( 'password', bcrypt.gensalt(12)) # 'password' is the password for this user def fill_entries(session): u1 = MoneyVigilUser(**settings['NEO']) u1.password = hashed_pw session.add(u1) try: session.commit() except Exception as e: print('Exception adding user', e) us1 = MoneyVigilUnsubscribeTokens( code='b4c2084e-d889-4455-acce-1c3a39658146', user=u1.uuid) session.add(us1) try: session.commit() except Exception as e: print('Exception adding unsubscribe tokens ', e) if __name__ == '__main__': s = Session() fill_entries(s) Session.remove()