def get_dict_for_dont_know_reaction(self, uid, nickname) -> dict: """ Prepares the discussion dict with all bubbles for the third step, where an supportive argument will be presented. :param uid: Argument.uid :param nickname: :return: dict() """ LOG.debug("Entering get_dict_for_dont_know_reaction") _tn = Translator(self.lang) bubbles_array = history_handler.create_bubbles(self.history, self.nickname, self.lang, self.slug) add_premise_text = '' save_statement_url = 'set_new_start_statement' gender = '' b = '<' + tag_type + '>' e = '</' + tag_type + '>' statement_list = list() if int(uid) != 0: text = get_text_for_argument_uid(uid, rearrange_intro=True, attack_type='dont_know', with_html_tag=True, start_with_intro=True) db_argument = DBDiscussionSession.query(Argument).get(uid) if not db_argument: text = '' data = get_name_link_of_arguments_author(db_argument, nickname) gender = data['gender'] if data['is_valid']: intro = data['link'] + ' ' + b + _tn.get(_.thinksThat) + e else: intro = b + _tn.get(_.otherParticipantsThinkThat) + e sys_text = intro + ' ' + start_with_small(text) + '. ' sys_text += '<br><br> ' + b + _tn.get( _.whatDoYouThinkAboutThat) + '?' + e bubble_sys = create_speechbubble_dict(BubbleTypes.SYSTEM, is_markable=True, uid=uid, content=sys_text, other_author=data['user']) if not bubbles_already_last_in_list(bubbles_array, bubble_sys): bubbles_array.append(bubble_sys) # add statements of discussion to report them statement_list = self.__get_all_statement_texts_by_argument( db_argument) return { 'bubbles': bubbles_array, 'add_premise_text': add_premise_text, 'save_statement_url': save_statement_url, 'mode': '', 'extras': statement_list, 'gender': gender, 'broke_limit': self.broke_limit }
def get_dict_for_choosing(self, uid, is_uid_argument, is_supportive) -> dict: """ Prepares the discussion dict with all bubbles for the choosing an premise, when the user inserted more than one new premise. :param uid: Argument.uid :param is_uid_argument: Boolean :param is_supportive: Boolean :return: """ _tn = Translator(self.lang) bubbles_array = history_handler.create_bubbles(self.history, self.nickname, self.lang, self.slug) add_premise_text = '' save_statement_url = 'set_new_start_statement' LOG.debug("Choosing dictionary for bubbles.") a = _tn.get(_.soYouEnteredMultipleReasons) if is_uid_argument: c = get_text_for_argument_uid(uid) else: statement = DBDiscussionSession.query(Statement).get(uid) c = statement.get_text() if is_supportive: if is_uid_argument: b = _tn.get(_.whatIsYourMostImportantReasonForArgument) else: b = _tn.get(_.whatIsYourMostImportantReasonForStatement) else: if is_uid_argument: b = _tn.get(_.whatIsYourMostImportantReasonAgainstArgument) else: b = _tn.get(_.whatIsYourMostImportantReasonAgainstStatement) b = b.replace('{}', '') text = '{}. {}: {}?<br>{}...'.format(a, b, c, _tn.get(_.because)) self.__append_now_bubble(bubbles_array) question_bubble = create_speechbubble_dict(BubbleTypes.SYSTEM, uid='question-bubble', content=text, omit_bubble_url=True, lang=self.lang) if not bubbles_already_last_in_list(bubbles_array, question_bubble): bubbles_array.append(question_bubble) return { 'bubbles': bubbles_array, 'add_premise_text': add_premise_text, 'save_statement_url': save_statement_url, 'mode': '', 'broke_limit': self.broke_limit }
def test_create_bubbles_from_history(self): bubbles = history.create_bubbles(self.history) self.assertGreater(len(bubbles), 0)
def get_dict_for_supporting_each_other(self, uid_system_arg, uid_user_arg, nickname) -> dict: """ Returns the dictionary during the supporting step :param uid_system_arg: Argument.uid :param uid_user_arg: Argument.uid :param nickname: User.nickname :return: dict() """ LOG.debug( "Entering get_dict_for_supporting_each_other for arg uid: %s", uid_system_arg) _tn = Translator(self.lang) bubbles_array = history_handler.create_bubbles(self.history, nickname, self.lang, self.slug) db_arg_system = DBDiscussionSession.query(Argument).get(uid_system_arg) db_arg_user = DBDiscussionSession.query(Argument).get(uid_user_arg) argument_text = get_text_for_argument_uid(uid_system_arg, colored_position=True, with_html_tag=True, attack_type='jump') offset = len('</' + tag_type + '>') if argument_text.endswith('</' + tag_type + '>') else 1 while argument_text[:-offset].endswith(('.', '?', '!')): argument_text = argument_text[:-offset - 1] + argument_text[-offset:] sys_text = get_text_for_support(db_arg_system, argument_text, nickname, _tn) self.__append_now_bubble(bubbles_array) user_text = get_text_for_argument_uid(uid_user_arg, nickname=nickname) db_user = DBDiscussionSession.query(User).filter_by( nickname=nickname).first() bubble_user = create_speechbubble_dict( BubbleTypes.USER, content=user_text, omit_bubble_url=True, argument_uid=uid_user_arg, is_supportive=db_arg_user.is_supportive, db_user=db_user, lang=self.lang) bubbles_array.append(bubble_user) bubble = create_speechbubble_dict( BubbleTypes.SYSTEM, uid='question-bubble-{}'.format(uid_system_arg), content=sys_text, omit_bubble_url=True, lang=self.lang) bubbles_array.append(bubble) return { 'bubbles': bubbles_array, 'add_premise_text': '', 'save_statement_url': '', 'mode': '', 'broke_limit': self.broke_limit }
def get_dict_for_jump(self, uid) -> dict: """ Prepares the discussion dict with all bubbles for the jump step :param uid: Argument.uid :return: dict() """ LOG.debug("Argument %s", uid) _tn = Translator(self.lang) argument_text = get_text_for_argument_uid(uid, colored_position=True, with_html_tag=True, attack_type='jump') bubbles_array = history_handler.create_bubbles(self.history, self.nickname, self.lang, self.slug) coming_from_jump = False if self.history: splitted_history = self.history.split('-') coming_from_jump = '/jump' in self.history[:-1] if len( splitted_history) > 0 else False intro = (_tn.get(_.canYouBeMorePrecise) + '<br><br>') if coming_from_jump else '' db_argument = DBDiscussionSession.query(Argument).get(uid) if db_argument.conclusion_uid is not None: intro += _tn.get(_.whatDoYouThinkArgument).strip() + ': ' else: bind = ', ' if self.lang == 'de' else ' ' intro += _tn.get(_.whatDoYouThinkAboutThat) + bind + _tn.get( _.that) + ' ' offset = len('</' + tag_type + '>') if argument_text.endswith('</' + tag_type + '>') else 1 while argument_text[:-offset].endswith(('.', '?', '!')): argument_text = argument_text[:-offset - 1] + argument_text[-offset:] text = intro + argument_text + '?' bubble = create_speechbubble_dict(BubbleTypes.SYSTEM, is_markable=True, uid='question-bubble-{}'.format(uid), content=text, omit_bubble_url=True, lang=self.lang) bubbles_array.append(bubble) # add statements of discussion to report them statement_list = self.__get_all_statement_texts_by_argument( db_argument) return { 'bubbles': bubbles_array, 'add_premise_text': '', 'save_statement_url': '', 'mode': '', 'extras': statement_list, 'broke_limit': self.broke_limit }
def get_dict_for_argumentation(self, db_user_argument: Argument, arg_sys_id: Optional[int], attack: Optional[Relations], history: str, db_user: User) -> dict: """ Prepares the discussion dict with all bubbles for the argumentation window. :param db_user_argument: Argument :param arg_sys_id: Argument.uid / not necessary if attack=end :param attack: String (undermine, support, undercut, rebut, ...) :param history: History :param db_user: User :return: dict() """ LOG.debug("At_argumentation about %s", db_user_argument.uid) nickname = db_user.nickname if db_user.nickname == nick_of_anonymous_user: db_user = None nickname = None bubbles_array = history_handler.create_bubbles(self.history, nickname, self.lang, self.slug) add_premise_text = '' save_statement_url = 'set_new_start_statement' bubble_mid = '' splitted_history = history_handler.split(self.history) user_changed_opinion = splitted_history[-1].endswith( str(db_user_argument.uid)) statement_list = list() db_argument = DBDiscussionSession.query(Argument).get( db_user_argument.uid) gender_of_counter_arg = '' db_enemy = None if arg_sys_id is not None: db_tmp_arg = DBDiscussionSession.query(Argument).get(arg_sys_id) data = get_name_link_of_arguments_author(db_tmp_arg, nickname) db_enemy = data['user'] if not attack: prep_dict = self.__get_dict_for_argumentation_end( db_user_argument.uid, user_changed_opinion, db_user) bubble_sys = create_speechbubble_dict(BubbleTypes.SYSTEM, content=prep_dict['sys'], omit_bubble_url=True, lang=self.lang, other_author=db_enemy) bubble_mid = create_speechbubble_dict(BubbleTypes.INFO, content=prep_dict['mid'], omit_bubble_url=True, lang=self.lang) else: prep_dict = self.__get_dict_for_argumentation( db_argument, arg_sys_id, history, attack, nickname, db_user_argument.is_supportive) quid = 'question-bubble-' + str(arg_sys_id) if int( arg_sys_id) > 0 else '' is_author = is_author_of_argument(db_user, prep_dict['confrontation'].uid) bubble_sys = create_speechbubble_dict(BubbleTypes.SYSTEM, is_markable=True, is_author=is_author, uid=quid, content=prep_dict['sys'], omit_bubble_url=True, lang=self.lang, other_author=db_enemy) statement_list = self.__get_all_statement_texts_by_argument( prep_dict['confrontation']) gender_of_counter_arg = prep_dict['gender'] bubble_user = create_speechbubble_dict( BubbleTypes.USER, content=prep_dict['user'], omit_bubble_url=True, argument_uid=db_user_argument.uid, is_supportive=db_user_argument.is_supportive, db_user=db_user, lang=self.lang, other_author=db_enemy) # dirty fixes if len(bubbles_array) > 0 and bubbles_array[-1][ 'message'] == bubble_user['message']: bubbles_array.remove(bubbles_array[-1]) self.__append_now_bubble(bubbles_array) if not bubbles_already_last_in_list(bubbles_array, bubble_user): bubbles_array.append(bubble_user) if not bubbles_already_last_in_list(bubbles_array, bubble_sys): bubbles_array.append(bubble_sys) if not attack: bubbles_array.append(bubble_mid) return { 'bubbles': bubbles_array, 'add_premise_text': add_premise_text, 'save_statement_url': save_statement_url, 'mode': '', 'extras': statement_list, 'gender': gender_of_counter_arg, 'broke_limit': self.broke_limit }
def get_dict_for_justify_argument(self, uid, is_supportive, attack): """ Prepares the discussion dict with all bubbles for a step in discussion, where the user justifies his attack she has done. :param uid: Argument.uid :param is_supportive: Boolean :param attack: String (undermine, support, undercut, rebut, ...) :return: dict() """ LOG.debug("Entering get_dict_for_justify_argument") _tn = Translator(self.lang) bubbles_array = history_handler.create_bubbles(self.history, self.nickname, self.lang, self.slug) add_premise_text = '' save_statement_url = 'set_new_premises_for_argument' db_argument = DBDiscussionSession.query(Argument).get(uid) if not db_argument: return { 'bubbles': bubbles_array, 'add_premise_text': add_premise_text, 'save_statement_url': save_statement_url, 'mode': '', 'broke_limit': self.broke_limit } confrontation = get_text_for_argument_uid(uid) premise = db_argument.get_premisegroup_text() conclusion = get_text_for_conclusion(db_argument, is_users_opinion=False) if db_argument.conclusion_uid is None: conclusion = start_with_small(conclusion) while premise.endswith(('.', '?', '!')): premise = premise[:-1] while conclusion.endswith(('.', '?', '!')): conclusion = premise[:-1] redirect_from_jump = 'jump/' in self.history.split('-')[-1] user_msg, sys_msg = get_header_for_users_confrontation_response( db_argument, self.lang, premise, attack, conclusion, False, is_supportive, self.nickname, redirect_from_jump=redirect_from_jump) add_premise_text = self.__get_add_premise_text_for_justify_argument( confrontation, premise, attack, conclusion, db_argument, is_supportive, user_msg) start = '<{} data-argumentation-type="position">'.format(tag_type) end = '</{}>'.format(tag_type) user_msg = user_msg.format(start, end) pro_tag = '<{} class="text-success">'.format(tag_type) con_tag = '<{} class="text-danger">'.format(tag_type) end_tag = '</{}>'.format(tag_type) if attack == Relations.UNDERCUT: sys_msg = _tn.get( _.whatIsYourMostImportantReasonForArgument).rstrip().format( pro_tag, end_tag) + ': ' dot = '.' else: dot = '?' if attack == Relations.UNDERMINE: sys_msg = _tn.get( _.whatIsYourMostImportantReasonAgainstStatement).rstrip( ).format(con_tag, end_tag) sys_msg += ', ' if self.lang == 'de' else ' ' else: sys_msg = _tn.get(_.whatIsYourMostImportantReasonForStatement ).rstrip().format(pro_tag, end_tag) + ': ' sys_msg += user_msg + dot + '<br>' + _tn.get(_.because) + '...' self.__append_now_bubble(bubbles_array) sys_bubble = create_speechbubble_dict(BubbleTypes.SYSTEM, content=sys_msg, omit_bubble_url=True, lang=self.lang) if not bubbles_already_last_in_list(bubbles_array, sys_bubble): bubbles_array.append(sys_bubble) return { 'bubbles': bubbles_array, 'add_premise_text': add_premise_text, 'save_statement_url': save_statement_url, 'mode': '', 'attack_type': attack, 'arg_uid': uid, 'broke_limit': self.broke_limit }
def get_dict_for_justify_statement(self, db_statement: Statement, slug, is_supportive, count_of_items, db_user: User): """ Prepares the discussion dict with all bubbles for the third step in discussion, where the user justifies his position. :param db_statement: Statement :param db_user: User :param slug: Issue.slug :param is_supportive: Boolean :param count_of_items: Integer :return: dict() """ LOG.debug("Entering get_dict_for_justify_statement") _tn = Translator(self.lang) bubbles_array = history_handler.create_bubbles(self.history, self.nickname, self.lang, self.slug) save_statement_url = 'set_new_start_statement' text = db_statement.get_text() if not text: return None tag_start = '<{} data-argumentation-type="position">'.format(tag_type) tag_end = '</{}>'.format(tag_type) # system bubble system_question = get_system_bubble_text_for_justify_statement( is_supportive, _tn, tag_start, text, tag_end) # user bubble nickname = db_user.nickname if db_user and db_user.nickname != nick_of_anonymous_user else None user_text, add_premise_text = get_user_bubble_text_for_justify_statement( db_statement.uid, db_user, is_supportive, _tn) question_bubble = create_speechbubble_dict(BubbleTypes.SYSTEM, content=system_question, omit_bubble_url=True, lang=self.lang) url = UrlManager(slug).get_url_for_statement_attitude(db_statement.uid) select_bubble = create_speechbubble_dict( BubbleTypes.USER, bubble_url=url, content=user_text, omit_bubble_url=False, statement_uid=db_statement.uid, is_supportive=is_supportive, db_user=db_user, lang=self.lang) if not bubbles_already_last_in_list(bubbles_array, select_bubble): bubbles_array.append(select_bubble) self.__append_now_bubble(bubbles_array) if not bubbles_already_last_in_list(bubbles_array, question_bubble): bubbles_array.append(question_bubble) if not self.nickname and count_of_items == 1: _t = Translator(self.lang) db_user = DBDiscussionSession.query(User).filter_by( nickname=nickname).first() msg_dict = { 'm': _.voteCountTextFirstM, 'f': _.voteCountTextFirstF, 'n': _.voteCountTextFirst, } if db_user: msg = msg_dict[db_user.gender] else: msg = _.voteCountTextFirst msg = _t.get(msg) + '.' bubbles_array.append( create_speechbubble_dict(BubbleTypes.INFO, uid='now_first', content=msg + _tn.get(_.onlyOneItemWithLink), omit_bubble_url=True, lang=self.lang)) return { 'bubbles': bubbles_array, 'add_premise_text': add_premise_text, 'save_statement_url': save_statement_url, 'mode': '', 'is_supportive': is_supportive, 'broke_limit': self.broke_limit }