示例#1
0
def init(request):
    """
    View configuration for the initial discussion.

    :param request: request of the web server
    :return: dictionary
    """
    LOG.debug("Configuration for initial discussion. %s", request.matchdict)
    emit_participation(request)

    prepared_discussion = discussion.init(request.validated['issue'],
                                          request.validated['user'])
    modify_discussion_url(prepared_discussion)
    modify_discussion_bubbles(prepared_discussion, request.registry)

    rdict = prepare_request_dict(request)

    # redirect to oauth url after login and redirecting
    if request.authenticated_userid and 'service' in request.params and request.params[
            'service'] in oauth_providers:
        url = request.session['oauth_redirect_url']
        return HTTPFound(location=url)

    append_extras_dict(prepared_discussion, rdict,
                       request.authenticated_userid, False)
    if len(prepared_discussion['items']['elements']) == 1:
        _dh = DictionaryHelper(rdict['ui_locales'],
                               prepared_discussion['issues']['lang'])
        nickname = request.authenticated_userid if request.authenticated_userid else nick_of_anonymous_user
        _dh.add_discussion_end_text(prepared_discussion['discussion'],
                                    prepared_discussion['extras'],
                                    nickname,
                                    at_start=True)

    return prepared_discussion
示例#2
0
文件: helper.py 项目: kroschu/dbas
def __append_extras_dict_with_flag(request: Request, db_user: User,
                                   db_issue: Issue, db_statement: Statement,
                                   pdict: dict):
    """

    :param request:
    :param db_user:
    :param db_issue:
    :param db_statement:
    :param pdict:
    :return:
    """
    item_len = len(pdict['items']['elements'])
    _dh = DictionaryHelper(get_language_from_cookie(request), db_issue.lang)
    extras_dict = _dh.prepare_extras_dict(db_issue.slug,
                                          True,
                                          True,
                                          True,
                                          request.registry,
                                          request.application_url,
                                          request.path,
                                          db_user=db_user)

    if item_len == 0:  # is the discussion at the end?
        _dh.add_discussion_end_text(pdict['discussion'],
                                    extras_dict,
                                    db_user.nickname,
                                    at_dont_know=True,
                                    current_premise=db_statement.get_text())
    pdict['extras'] = extras_dict
示例#3
0
文件: helper.py 项目: kroschu/dbas
def __append_extras_dict_without_flag(request: Request, db_user: User,
                                      db_issue: Issue, db_statement: Statement,
                                      pdict: dict, attitude: Attitudes):
    """

    :param request:
    :param db_user:
    :param db_issue:
    :param db_statement:
    :param pdict:
    :param attitude:
    :return:
    """
    item_len = len(pdict['items']['elements'])
    _dh = DictionaryHelper(get_language_from_cookie(request), db_issue.lang)
    supportive = attitude in [Attitudes.AGREE, Attitudes.DONT_KNOW]
    logged_in = db_user is not None and db_user.nickname != nick_of_anonymous_user
    extras_dict = _dh.prepare_extras_dict(db_issue.slug, False, True, True,
                                          request.registry,
                                          request.application_url,
                                          request.path, db_user)

    if item_len == 0 or item_len == 1 and logged_in:  # is the discussion at the end?
        _dh.add_discussion_end_text(pdict['discussion'],
                                    extras_dict,
                                    db_user.nickname,
                                    at_justify=True,
                                    current_premise=db_statement.get_text(),
                                    supportive=supportive)
    pdict['extras'] = extras_dict
示例#4
0
文件: helper.py 项目: kroschu/dbas
def append_extras_dict_during_justification_argument(request: Request,
                                                     db_user: User,
                                                     db_issue: Issue,
                                                     pdict: dict):
    """

    :param request:
    :param db_user:
    :param db_issue:
    :param pdict:
    :return:
    """
    system_lang = get_language_from_cookie(request)
    item_len = len(pdict['items']['elements'])
    _dh = DictionaryHelper(system_lang, db_issue.lang)
    logged_in = (db_user
                 and db_user.nickname != nick_of_anonymous_user) is not None
    extras_dict = _dh.prepare_extras_dict(db_issue.slug,
                                          False,
                                          True,
                                          True,
                                          request.registry,
                                          request.application_url,
                                          request.path,
                                          db_user=db_user)
    # is the discussion at the end?
    if item_len == 0 or item_len == 1 and logged_in or 'login' in pdict[
            'items']['elements'][0].get('id'):
        _dh.add_discussion_end_text(pdict['discussion'],
                                    extras_dict,
                                    request.authenticated_userid,
                                    at_justify_argumentation=True)

    pdict['extras'] = extras_dict
示例#5
0
def append_extras_dict(pdict: dict, rdict: dict, nickname: str, is_reportable: bool) -> None:
    """

    :param pdict: prepared dict for rendering
    :param rdict: request dictionary
    :param nickname: request.authenticated_userid
    :param is_reportable: Same as discussion.bubbles.last.is_markable, but TAL has no last indicator
    :return:
    """
    _dh = DictionaryHelper(rdict['ui_locales'], pdict['issues']['lang'])
    db_user = DBDiscussionSession.query(User).filter_by(
        nickname=nickname if nickname else nick_of_anonymous_user).first()
    pdict['extras'] = _dh.prepare_extras_dict(rdict['issue'].slug, is_reportable, True, True, rdict['registry'],
                                              rdict['app_url'], rdict['path'], db_user)
示例#6
0
def debug_function(request):
    """
    Minimal debug interface for the websocket

    :param request: current webservers reqquest
    :return: dict()
    """
    LOG.debug("Preparing debug information for websocket")

    ui_locales = get_language_from_cookie(request)
    extras_dict = DictionaryHelper(
        ui_locales).prepare_extras_dict_for_normal_page(
            request.registry, request.application_url, request.path,
            request.validated['user'])

    return {
        'language': str(ui_locales),
        'title': 'Debug Socket.IO Connection',
        'project': project_name,
        'extras': extras_dict,
        'is_admin': request.validated['user'].is_admin(),
        'discussion': {
            'broke_limit': False
        }
    }
示例#7
0
def settings(request):
    """
    View configuration for the personal settings view. Only logged in user can reach this page.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Show settings %s", request.params)

    ui_locales = get_language_from_cookie(request)
    old_pw, new_pw, confirm_pw, message = '', '', '', ''
    success, error = False, False
    db_user: User = request.validated['user']

    if 'form.passwordchange.submitted' in request.params:
        old_pw = escape_string(request.params['passwordold'])
        new_pw = escape_string(request.params['password'])
        confirm_pw = escape_string(request.params['passwordconfirm'])

        message, success = change_password(db_user, old_pw, new_pw, confirm_pw, ui_locales)
        error = not success

    settings_dict = DictionaryHelper(ui_locales).prepare_settings_dict(success, old_pw, new_pw, confirm_pw, error,
                                                                       message, db_user, request.application_url,
                                                                       request.decorated['extras']['use_with_ldap'])

    prep_dict = main_dict(request, Translator(ui_locales).get(_.settings))
    prep_dict.update({
        'settings': settings_dict
    })
    return prep_dict
示例#8
0
def main_admin(request):
    """
    View configuration for the content view. Only logged in user can reach this page.

    :param request: current webservers request
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("def")
    db_user = request.validated['user']

    ui_locales = get_language_from_cookie(request)
    extras_dict = DictionaryHelper(
        ui_locales).prepare_extras_dict_for_normal_page(
            request.registry, request.application_url, request.path, db_user)
    dashboard_elements = {
        'entities': lib.get_overview(request.path),
        'api_tokens': lib.get_application_tokens()
    }

    return {
        'language': str(ui_locales),
        'title': 'Admin' if db_user.is_admin() else '(B)admin',
        'project': project_name,
        'extras': extras_dict,
        'dashboard': dashboard_elements,
        'discussion': {
            'broke_limit': False
        }
    }
示例#9
0
def main_table(request):
    """
    View configuration for the content view. Only logged in user can reach this page.

    :param request: current webservers request
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Entering the main_table method from the admin interface.")

    ui_locales = get_language_from_cookie(request)
    extras_dict = DictionaryHelper(
        ui_locales).prepare_extras_dict_for_normal_page(
            request.registry, request.application_url, request.path,
            request.validated['user'])
    table_name = request.matchdict['table']
    if not table_name.lower() in lib.table_mapper:
        return exception_response(400)
    table_dict = lib.get_table_dict(table_name, request.application_url)

    return {
        'language': str(ui_locales),
        'title': 'Admin - ' + table_name,
        'project': project_name,
        'extras': extras_dict,
        'table': table_dict,
        'discussion': {
            'broke_limit': False
        }
    }
示例#10
0
def dexit(request):
    """
    View configuration for discussion step, where we present a small/daily summary on the end

    :param request: request of the web server
    :return:
    """
    LOG.debug("Exit discussion. %s", request.matchdict)

    db_user = DBDiscussionSession.query(User).filter_by(
        nickname=request.authenticated_userid).first()
    dh = DictionaryHelper(get_language_from_cookie(request))
    prepared_discussion = discussion.exit(get_language_from_cookie(request),
                                          db_user)
    prepared_discussion['extras'] = dh.prepare_extras_dict_for_normal_page(
        request.registry, request.application_url, request.path, db_user)
    prepared_discussion['language'] = str(get_language_from_cookie(request))
    prepared_discussion['show_summary'] = len(
        prepared_discussion['summary']) != 0
    prepared_discussion['discussion'] = {'broke_limit': False}
    return prepared_discussion
示例#11
0
def prep_extras_dict(request):
    """

    :param view_callable:
    :return:
    """
    ui_locales = get_language_from_cookie(request)
    db_user = DBDiscussionSession.query(User).filter_by(
        nickname=request.authenticated_userid).first()
    extras_dict = DictionaryHelper(
        ui_locales).prepare_extras_dict_for_normal_page(
            request.registry, request.application_url, request.path, db_user)
    setattr(request, 'decorated', {})
    request.decorated['extras'] = extras_dict
示例#12
0
def __append_extras_dict_during_justification_statement(
        request: Request, db_user: User, db_issue: Issue,
        db_statement: Statement, pdict: dict, attitude: Attitudes):
    system_lang = get_language_from_cookie(request)
    supportive = attitude in [Attitudes.AGREE, Attitudes.DONT_KNOW]
    item_len = len(pdict['items']['elements'])
    _dh = DictionaryHelper(system_lang, db_issue.lang)
    logged_in = (db_user
                 and db_user.nickname != nick_of_anonymous_user) is not None

    if attitude in (Attitudes.AGREE, Attitudes.DISAGREE):
        extras_dict = _dh.prepare_extras_dict(db_issue.slug, False, True, True,
                                              request.registry,
                                              request.application_url,
                                              request.path, db_user)
        if item_len == 0 or item_len == 1 and logged_in:
            _dh.add_discussion_end_text(
                pdict['discussion'],
                extras_dict,
                db_user.nickname,
                at_justify=True,
                current_premise=db_statement.get_text(),
                supportive=supportive)

    else:
        extras_dict = _dh.prepare_extras_dict(db_issue.slug,
                                              True,
                                              True,
                                              True,
                                              request.registry,
                                              request.application_url,
                                              request.path,
                                              db_user=db_user)
        # is the discussion at the end?
        if item_len == 0:
            _dh.add_discussion_end_text(
                pdict['discussion'],
                extras_dict,
                db_user.nickname,
                at_dont_know=True,
                current_premise=db_statement.get_text())

    pdict['extras'] = extras_dict
示例#13
0
def set_language_for_visit(request) -> str:
    """
    Sets language and issue uid based on the requests header if there is no _LOCALE_ attribute in the cookie

    :param request: request-dict (necessary, because the language will be set in the cookies dict of the request)
    :return: None
    """
    if '_LOCALE_' in request.cookies:
        LOG.debug("User was already here")
        # user was already here
        ui_locales = request.cookies['_LOCALE_']
    else:
        LOG.debug("User is first time here")
        ui_locales = get_language_from_header(request)
    lang = DBDiscussionSession.query(Language).filter_by(
        ui_locales=ui_locales).first()
    if hasattr(request, 'request'):
        DictionaryHelper(ui_locales).add_language_options_for_extra_dict(
            request.decorated['extras'])
    return set_language(request, lang)