def send_add_argument_notification(url, attacked_argument_uid, user, mailer): """ Sends an notification because an argument was added :param url: String :param attacked_argument_uid: Argument.uid :param user: User :param mailer: Instance of pyramid mailer :return: """ # getting current argument, arguments author, current user and some settings db_argument = DBDiscussionSession.query(Argument).get( attacked_argument_uid) db_author = DBDiscussionSession.query(User).get(db_argument.author_uid) db_current_user = DBDiscussionSession.query(User).filter_by( nickname=user).first() if db_author == db_current_user: return None db_author_settings = db_author.settings user_lang = DBDiscussionSession.query(Language).get( db_author_settings.lang_uid).ui_locales # send notification via websocket to last author _t_user = Translator(user_lang) if db_author_settings.should_send_notifications: send_request_for_info_popup_to_socketio(db_author.nickname, _t_user.get(_.argumentAdded), url) # send mail to last author if db_author_settings.should_send_mails: email_helper.send_mail_due_to_added_text(user_lang, url, db_author, mailer) # find admin db_admin = DBDiscussionSession.query(User).filter_by( nickname=nick_of_admin).first() topic = _t_user.get(_.argumentAdded) content = get_text_for_add_argument_message(db_author.firstname, user_lang, url, True) DBDiscussionSession.add( Message(from_author_uid=db_admin.uid, to_author_uid=db_author.uid, topic=topic, content=content, is_inbox=True)) transaction.commit()
def send_add_text_notification(url, conclusion_id, db_user: User, mailer): """ Send notifications and mails to related users. :param url: current url :param conclusion_id: Statement.uid :param db_user: current users nickname :param mailer: Instance of pyramid mailer :return: None """ # getting all text versions, the overview author, last editor and settings ob both authors as well as their languages db_textversions = DBDiscussionSession.query(TextVersion).filter_by( statement_uid=conclusion_id).all() db_root_author = DBDiscussionSession.query(User).get( db_textversions[0].author_uid) db_last_editor = DBDiscussionSession.query(User).get( db_textversions[-1].author_uid) db_root_author_settings = db_root_author.settings db_last_editor_settings = db_last_editor.settings root_lang = DBDiscussionSession.query(Language).get( db_root_author_settings.lang_uid).ui_locales editor_lang = DBDiscussionSession.query(Language).get( db_last_editor_settings.lang_uid).ui_locales _t_editor = Translator(editor_lang) _t_root = Translator(root_lang) # send mail to overview author if db_root_author_settings.should_send_mails \ and db_user != db_root_author: email_helper.send_mail_due_to_added_text(root_lang, url, db_root_author, mailer) # send mail to last author if db_last_editor_settings.should_send_mails \ and db_last_editor != db_root_author \ and db_last_editor != db_user: email_helper.send_mail_due_to_added_text(editor_lang, url, db_last_editor, mailer) # send notification via websocket to overview author if db_root_author_settings.should_send_notifications and db_root_author != db_user: send_request_for_info_popup_to_socketio(db_root_author.nickname, _t_root.get(_.statementAdded), url, increase_counter=True) # send notification via websocket to last author if db_last_editor_settings.should_send_notifications \ and db_last_editor != db_root_author \ and db_last_editor != db_user: send_request_for_info_popup_to_socketio(db_last_editor.nickname, _t_editor.get( _.statementAdded), url, increase_counter=True) # find admin, because generic mails are being sent by the admin db_admin = user_handler.get_list_of_admins()[0] # get topic and content for messages to both authors topic1 = _t_root.get(_.statementAdded) content1 = get_text_for_message(db_root_author.firstname, root_lang, url, _.statementAddedMessageContent, True) topic2 = _t_editor.get(_.statementAdded) content2 = get_text_for_message(db_last_editor.firstname, editor_lang, url, _.statementAddedMessageContent, True) if db_root_author != db_user: DBDiscussionSession.add( Message(from_author_uid=db_admin.uid, to_author_uid=db_root_author.uid, topic=topic1, content=content1, is_inbox=True)) if db_root_author != db_last_editor and db_user != db_last_editor: DBDiscussionSession.add( Message(from_author_uid=db_admin.uid, to_author_uid=db_last_editor.uid, topic=topic2, content=content2, is_inbox=True)) DBDiscussionSession.flush() transaction.commit()