def test_get_undercuts_for_argument_uid(self): val = get_undercuts_for_argument_uid('a') self.assertIsNone(val) val = get_undercuts_for_argument_uid(100) self.assertIsNone(val) val = get_undercuts_for_argument_uid(0) self.assertIsNone(val) val = get_undercuts_for_argument_uid(36) self.assertGreaterEqual(len(val), 1) val = get_undercuts_for_argument_uid('36') self.assertGreaterEqual(len(val), 1)
def __get_attacks(attack: Relations, argument_uid: int, last_attack: Relations, is_supportive: bool) -> Tuple[List[dict], bool, Relations]: """ Returns a list of all attacking arguments based on input... :param attack: :param argument_uid: :param last_attack: :param is_supportive: :return: List of dicts with id and text as field """ mod_attack = attack if attack == Relations.UNDERMINE: attacks = get_undermines_for_argument_uid(argument_uid, is_supportive) # special case when undermining an undermine (docs/dbas/logic.html?highlight=undermine#dialog-sequence) is_supportive = last_attack == Relations.UNDERMINE elif attack == Relations.REBUT: db_arg = DBDiscussionSession.query(Argument).get(argument_uid) if not (db_arg and db_arg.argument_uid is None): mod_attack = Relations.UNDERCUT attacks = get_rebuts_for_argument_uid(argument_uid) else: attacks = get_undercuts_for_argument_uid(argument_uid) return attacks, is_supportive, mod_attack
def __revoke_argument(db_user, db_argument): """ Revokes the user as author of the argument :param db_user: User.uid :param argument_uid: Argument.uid :return: Argument, Boolean, String """ # does the argument has any attack or supports? relations = [ get_undermines_for_argument_uid(db_argument.uid), get_supports_for_argument_uid(db_argument.uid), get_undercuts_for_argument_uid(db_argument.uid), get_rebuts_for_argument_uid(db_argument.uid) ] is_involved = sum([len(rel) if rel else 0 for rel in relations]) > 0 if is_involved: logger( 'QueryHelper', 'Author of argument {} changed from {} to anonymous'.format( db_argument.uid, db_user.uid)) db_new_author = DBDiscussionSession.query(User).filter_by( nickname=nick_of_anonymous_user).first() db_argument.author_uid = db_new_author.uid else: logger('QueryHelper', 'Disabling argument {}'.format(db_argument.uid)) db_argument.set_disabled(True) DBDiscussionSession.add(db_argument) DBDiscussionSession.flush() transaction.commit() return db_argument
def __revoke_argument(db_argument: Argument, db_user: User): """ Revokes the user as author of the argument :param db_user: User.uid :param db_argument: Argument.uid :return: Argument, Boolean, String """ # does the argument has any attack or supports? relations = [ get_undermines_for_argument_uid(db_argument.uid), get_supports_for_argument_uid(db_argument.uid), get_undercuts_for_argument_uid(db_argument.uid), get_rebuts_for_argument_uid(db_argument.uid) ] is_involved = sum([len(rel) if rel else 0 for rel in relations]) > 0 if is_involved: LOG.debug("Author of argument %s changed from %s to anonymous", db_argument.uid, db_user.uid) db_new_author = DBDiscussionSession.query(User).filter_by( nickname=nick_of_anonymous_user).first() db_argument.author_uid = db_new_author.uid else: LOG.debug("Disabling argument %s", db_argument.uid) db_argument.set_disabled(True) DBDiscussionSession.add(db_argument) DBDiscussionSession.flush() return db_argument
def get_user_and_opinions_for_argument(argument_uid, db_user, lang, main_page, path): """ Returns nested dictionary with all kinds of attacks for the argument as well as the users who are supporting these attacks. :param argument_uid: Argument.uid :param db_user: User :param lang: current language :param main_page: main_page :param path: path :return: { 'attack_type': { 'message': 'string', 'users': [{'nickname': 'string', 'avatar_url': 'url' 'vote_timestamp': 'string' ], ... }],...} """ LOG.debug("Argument %s, nickname %s", argument_uid, db_user.nickname) # preparation _t = Translator(lang) title = _t.get(_.attitudesOfOpinions) # getting uids of all reactions arg_uids_for_reactions = [ get_undermines_for_argument_uid(argument_uid), get_supports_for_argument_uid(argument_uid), get_undercuts_for_argument_uid(argument_uid), get_rebuts_for_argument_uid(argument_uid) ] # get gender of counter use db_supporter = get_author_or_first_supporter_of_element( argument_uid, db_user.uid, True) gender = 'n' if db_supporter: gender = db_supporter.gender if re.search(r'/%s/?$' % Attitudes.DONT_KNOW, path.split('?')[0]): relation_text = get_relation_text_dict_with_substitution( lang, False, is_dont_know=True, gender=gender) else: relation_text = get_relation_text_dict_with_substitution(lang, True, gender=gender) # getting votes for every reaction ret_list = __get_clicks_for_reactions(arg_uids_for_reactions, relation_text, db_supporter, _t, main_page) return {'opinions': ret_list, 'title': start_with_capital(title)}
def get_user_and_opinions_for_argument(argument_uid, db_user, lang, main_page, path): """ Returns nested dictionary with all kinds of attacks for the argument as well as the users who are supporting these attacks. :param argument_uid: Argument.uid :param db_user: User :param lang: current language :param main_page: main_page :param path: path :return: { 'attack_type': { 'message': 'string', 'users': [{'nickname': 'string', 'avatar_url': 'url' 'vote_timestamp': 'string' ], ... }],...} """ logger( 'OpinionHandler', 'Argument ' + str(argument_uid) + ', nickname ' + str(db_user.nickname)) # preparation _t = Translator(lang) title = _t.get(_.attitudesOfOpinions) # getting uids of all reactions arg_uids_for_reactions = [ get_undermines_for_argument_uid(argument_uid), get_supports_for_argument_uid(argument_uid), get_undercuts_for_argument_uid(argument_uid), get_rebuts_for_argument_uid(argument_uid) ] # get gender of counter use db_user = get_author_or_first_supporter_of_element(argument_uid, db_user.uid, True) gender = db_user.gender if db_user else 'n' if '/d' in path.split('?')[0]: relation_text = get_relation_text_dict_with_substitution( lang, False, is_dont_know=True, gender=gender) else: relation_text = get_relation_text_dict_with_substitution(lang, True, gender=gender) # getting votes for every reaction ret_list = __get_clicks_for_reactions(arg_uids_for_reactions, relation_text, db_user, _t, main_page) return {'opinions': ret_list, 'title': title[0:1].upper() + title[1:]}