def discussion_choose(request): """ View configuration for discussion step, where the user has to choose between given statements. :param request: request of the web server :return: dictionary """ # '/discuss/{slug}/choose/{is_argument}/{supportive}/{id}*pgroup_ids' match_dict = request.matchdict logger('discussion_choose', 'request.matchdict: {}'.format(match_dict)) db_user = request.validated['user'] db_issue = request.validated['issue'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = discussion.choose(db_issue, db_user, request.validated['is_argument'], request.validated['is_supportive'], request.validated['pgroup_uid'], request.validated['pgroup_uids'], history, request.path) rdict = prepare_request_dict(request) __modify_discussion_url(prepared_discussion) __modify_discussion_bubbles(prepared_discussion, request.registry) __append_extras_dict(prepared_discussion, rdict, request.authenticated_userid, False) return prepared_discussion
def discussion_support(request): """ View configuration for discussion step, where we will present another supportive argument. :param request: request of the web server :return: dictionary """ logger('discussion_support', 'request.matchdict: {}'.format(request.matchdict)) db_user = request.validated['user'] db_issue = request.validated['issue'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = discussion.support(db_issue, db_user, request.validated['arg_user'], request.validated['arg_sys'], history, request.path) rdict = prepare_request_dict(request) __modify_discussion_url(prepared_discussion) __modify_discussion_bubbles(prepared_discussion, request.registry) __append_extras_dict(prepared_discussion, rdict, request.authenticated_userid, False) return prepared_discussion
def discussion_finish(request): """ View configuration for discussion step, where we present a small/daily summary on the end :param request: request of the web server :return: """ logger('discussion_finish', 'request.matchdict: {}'.format(request.matchdict)) db_user = request.validated['user'] db_issue = request.validated['issue'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = discussion.finish(db_issue, db_user, request.validated['argument'], history) __modify_discussion_url(prepared_discussion) __modify_discussion_bubbles(prepared_discussion, request.registry) __append_extras_dict(prepared_discussion, prepare_request_dict(request), request.authenticated_userid, True) return prepared_discussion
def discussion_reaction(request): """ View configuration for discussion step, where we will ask the user for her reaction (support, undercut, rebut)... Path: /discuss/{slug}/reaction/{arg_id_user:\d+}/{relation}/{arg_id_sys:\d+} :param request: request of the web server :return: dictionary """ logger('discussion_reaction', 'request.validated: {}'.format(request.validated)) db_user = request.validated['user'] db_issue = request.validated['issue'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = discussion.reaction(db_issue, db_user, request.validated['arg_user'], request.validated['arg_sys'], request.validated['relation'], history, request.path) rdict = prepare_request_dict(request) __modify_discussion_url(prepared_discussion) __modify_discussion_bubbles(prepared_discussion, request.registry) __append_extras_dict(prepared_discussion, rdict, request.authenticated_userid, True) return prepared_discussion
def discussion_justify_argument(request) -> dict: """ View configuration for discussion step, where we will ask the user for her a justification of her opinion/interest. Path: /discuss/{slug}/justify/{argument_id:\d+}/{attitude}/{relation} :param request: request of the web server :return: dict """ logger('discussion_justify_argument', 'request.matchdict: {}'.format(request.matchdict)) db_argument: Argument = request.validated['argument'] db_issue = request.validated['issue'] db_user = request.validated['user'] attitude = request.validated['attitude'] relation = request.validated['relation'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = discussion.justify_argument(db_issue, db_user, db_argument, attitude, relation, history, request.path) __modify_discussion_url(prepared_discussion) __modify_discussion_bubbles(prepared_discussion, request.registry) __append_extras_dict_during_justification_argument(request, db_user, db_issue, prepared_discussion) return prepared_discussion
def discussion_attitude(request): """ View configuration for discussion step, where we will ask the user for her attitude towards a statement. Route: /discuss/{slug}/attitude/{position_id} :param request: request of the web server :return: dictionary """ logger('discussion_attitude', 'request.matchdict: {}'.format(request.matchdict)) db_statement = request.validated['statement'] db_issue = request.validated['issue'] db_user = request.validated['user'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = discussion.attitude(db_issue, db_user, db_statement, history, request.path) __modify_discussion_url(prepared_discussion) __modify_discussion_bubbles(prepared_discussion, request.registry) rdict = prepare_request_dict(request) __append_extras_dict(prepared_discussion, rdict, request.authenticated_userid, False) return prepared_discussion
def discussion_jump(request): """ View configuration for the jump view. :param request: request of the web server :return: dictionary """ # '/discuss/{slug}/jump/{arg_id}' db_user = request.validated['user'] db_issue = request.validated['issue'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = discussion.jump(db_issue, db_user, request.validated['argument'], history, request.path) rdict = prepare_request_dict(request) __modify_discussion_url(prepared_discussion) __modify_discussion_bubbles(prepared_discussion, request.registry) __append_extras_dict(prepared_discussion, rdict, request.authenticated_userid, False) return prepared_discussion
def discussion_finish(request): db_user = request.validated['user'] db_issue = request.validated['issue'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = dbas.discussion.finish(db_issue, db_user, request.validated['argument'], history) return {'bubbles': extract_items_and_bubbles(prepared_discussion)[0]}
def add_premise_to_argument(request): db_user: User = request.validated['user'] db_issue: Issue = request.validated['issue'] db_argument: Argument = request.validated['argument'] relation: Relations = request.validated['relation'] history = history_handler.handle_history(request, db_user, db_issue) pd = set_arguments_premises(db_issue, db_user, db_argument, [[request.validated['reason-text']]], relation, history, request.mailer) return HTTPSeeOther(location='/api' + pd['url'])
def add_premise_to_statement(request): db_user: User = request.validated['user'] db_issue: Issue = request.validated['issue'] db_statement: Statement = request.validated['statement'] is_supportive = request.validated['attitude'] == Attitudes.AGREE history = history_handler.handle_history(request, db_user, db_issue) pd = set_positions_premise(db_issue, db_user, db_statement, [[request.validated['reason-text']]], is_supportive, history, request.mailer) return HTTPSeeOther(location='/api' + pd['url'])
def prepare_request_dict(request: Request): """ :param request: :return: """ logger('Renderer', 'def') db_user = request.validated['user'] nickname = db_user.nickname if db_user.nickname != nick_of_anonymous_user else None db_last_topic = history_handler.get_saved_issue(db_user) slug = None if 'slug' in request.matchdict: slug = request.matchdict['slug'] if not isinstance(request.matchdict['slug'], str) and len(request.matchdict['slug']) > 0: slug = request.matchdict['slug'][0] if not slug and db_last_topic: issue = db_last_topic elif slug: issue = issue_handler.get_id_of_slug(slug) else: issue = issue_handler.get_issue_id(request) ui_locales = get_language_from_cookie(request) if not issue: raise HTTPNotFound() if isinstance(issue, int): db_issue = DBDiscussionSession.query(Issue).get(issue) else: db_issue = issue issue_handler.save_issue_id_in_session(db_issue.uid, request) history = history_handler.handle_history(request, db_user, db_issue) set_language_for_visit(request) return { 'nickname': nickname, 'user': db_user, 'path': request.path, 'app_url': request.application_url, 'matchdict': request.matchdict, 'params': request.params, 'session': request.session, 'registry': request.registry, 'issue': db_issue, 'history': history, 'ui_locales': ui_locales }
def add_position_with_premise(request): db_user: User = request.validated['user'] db_issue: Issue = request.validated['issue'] history = history_handler.handle_history(request, db_user, db_issue) new_position = set_position(db_user, db_issue, request.validated['position-text']) conslusion_id: int = new_position['statement_uids'][0] db_conclusion: Statement = DBDiscussionSession.query(Statement).get( conslusion_id) pd = set_positions_premise(db_issue, db_user, db_conclusion, [[request.validated['reason-text']]], True, history, request.mailer) return HTTPSeeOther(location='/api' + pd['url'])
def discussion_justify_statement(request) -> dict: """ Pick attitude from path and query the statement. Show the user some statements to follow the discussion. Path: /{slug}/justify/{statement_id}/{attitude} :param request: request :return: dict """ db_user = request.validated['user'] db_issue = request.validated['issue'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = dbas.discussion.justify_statement( db_issue, db_user, request.validated['statement'], request.validated['attitude'], history, request.path) bubbles, items = extract_items_and_bubbles(prepared_discussion) return {'bubbles': bubbles, 'items': items}
def discussion_justify_argument(request) -> dict: """ Justify an argument. Attitude and relation are important to show the correct items for the user. /{slug}/justify/{argument_id}/{attitude}/{relation} :param request: :return: """ db_user = request.validated['user'] db_issue = request.validated['issue'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = dbas.discussion.justify_argument( db_issue, db_user, request.validated['argument'], request.validated['attitude'], request.validated['relation'], history, request.path) bubbles, items = extract_items_and_bubbles(prepared_discussion) return {'bubbles': bubbles, 'items': items}
def discussion_attitude(request): """ Return data from DBas discussion_attitude page. /{slug}/attitude/{position_id} :param request: request :return: dbas.discussion_attitude(True) """ db_position = request.validated['position'] db_issue = request.validated['issue'] db_user = request.validated['user'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = discussion.attitude(db_issue, db_user, db_position, history, request.path) bubbles, items = extract_items_and_bubbles(prepared_discussion) keys = [ item['attitude'] for item in prepared_discussion['items']['elements'] ] return {'bubbles': bubbles, 'attitudes': dict(zip(keys, items))}
def discussion_reaction(request): """ Return data from DBas discussion_reaction page. Path: /{slug}/reaction/{arg_id_user}/{relation}/{arg_id_sys} :param request: request :return: bubbles for information and items for the next step """ db_user = request.validated['user'] db_issue = request.validated['issue'] history = history_handler.handle_history(request, db_user, db_issue) prepared_discussion = dbas.discussion.reaction( db_issue, db_user, request.validated['arg_user'], request.validated['arg_sys'], request.validated['relation'], history, request.path) bubbles, items = extract_items_and_bubbles(prepared_discussion) keys = [ item['attitude'] for item in prepared_discussion['items']['elements'] ] return {'bubbles': bubbles, 'attacks': dict(zip(keys, items))}