コード例 #1
0
ファイル: doctest.py プロジェクト: khchine5/lino
def walk_menu_items(username, severe=False):
    """Walk through all menu items which run a :class:`GridEdit
    <lino.core.actions.GridEdit>` action, showing how many data rows
    the grid contains.

    """
    ar = settings.SITE.login(username)
    with translation.override(ar.user.language):
        mnu = settings.SITE.get_site_menu(None, ar.user.profile)
        items = []
        for mi in mnu.walk_items():
          if mi.bound_action:
            if isinstance(mi.bound_action.action, GridEdit):
                mt = mi.bound_action.actor
                url = 'api/{}/{}'.format(mt.app_label, mt.__name__)
                url = six.text_type(settings.SITE.buildurl(url, fmt='json'))

                item = menuselection_text(mi) + " : "
                try:
                    response = test_client.get(url, REMOTE_USER=six.text_type(username))
                    result = check_json_result(
                        response, None,
                        "GET %s for user %s" % (url, username))
                    item += str(result['count'])
                except Exception as e:
                    if severe:
                        raise
                    else:
                        item += str(e)
                items.append(item)

        s = rstgen.ul(items)
        print(s)
コード例 #2
0
    def doit(ar):
        if ar is None:
            user_type = None
        else:
            user_type = ar.user.user_type
            test_client.force_login(ar.user)
        mnu = settings.SITE.get_site_menu(user_type)
        items = []
        for mi in mnu.walk_items():
          if mi.bound_action:
            if isinstance(mi.bound_action.action, ShowTable):
                mt = mi.bound_action.actor
                url = 'api/{}/{}'.format(mt.app_label, mt.__name__)
                url = six.text_type(settings.SITE.buildurl(url, fmt='json'))

                item = menuselection_text(mi) + " : "
                try:
                    response = test_client.get(url, REMOTE_USER=six.text_type(username))
                    result = check_json_result(
                        response, None,
                        "GET %s for user %s" % (url, username))
                    item += str(result['count'])
                except Exception as e:
                    if severe:
                        raise
                    else:
                        item += str(e)
                items.append(item)

        s = rstgen.ul(items)
        print(s)
コード例 #3
0
ファイル: doctest.py プロジェクト: TonisPiip/lino
 def doit():
     # profile = ar.get_user().profile
     # menu = settings.SITE.get_site_menu(settings.SITE.kernel, profile)
     # mi = menu.find_item(spec)
     mi = find_menu_item(spec)
     if mi is None:
         raise Exception("Invalid spec {0}".format(spec))
     print(menuselection_text(mi))
コード例 #4
0
ファイル: doctest.py プロジェクト: khchine5/lino
 def doit():
     # profile = ar.get_user().profile
     # menu = settings.SITE.get_site_menu(settings.SITE.kernel, profile)
     # mi = menu.find_item(spec)
     mi = find_menu_item(spec)
     if mi is None:
         raise Exception("Invalid spec {0}".format(spec))
     print(menuselection_text(mi))
コード例 #5
0
def show_menu_path(spec, language=None):
    """
    Print the menu path of the given actor or action.

    Deprecated.  You should rather use
    :meth:`lino.core.requests.BaseRequest.show_menu_path` which
    automatically sets the language of the user and works for any user
    type.
    """
    user_type = rt.models.users.UserTypes.get_by_value('900')
    mi = user_type.find_menu_item(spec)
    if mi is None:
        raise Exception("Invalid spec {0}".format(spec))
    if language:
        with translation.override(language):
            print(menuselection_text(mi))
    else:
        print(menuselection_text(mi))
コード例 #6
0
ファイル: requests.py プロジェクト: lino-framework/lino
    def show_menu_path(self, spec, language=None):
        """
        Print the menu path of the given actor or action.

        This is the replacement for :func:`show_menu_path
        <lino.api.doctest.show_menu_path>`.  It has the advantage that
        it automatically sets the language of the user and that it
        works for any user type.
        """
        from lino.sphinxcontrib.actordoc import menuselection_text
        u = self.get_user()
        mi = u.user_type.find_menu_item(spec)
        if mi is None:
            raise Exception("Invalid spec {0}".format(spec))
        if language is None:
            language = u.language
        with translation.override(language):
            print(menuselection_text(mi))
コード例 #7
0
    def show_menu_path(self, spec, language=None):
        """
        Print the menu path of the given actor or action.

        This is the replacement for :func:`show_menu_path
        <lino.api.doctest.show_menu_path>`.  It has the advantage that
        it automatically sets the language of the user and that it
        works for any user type.
        """
        from lino.sphinxcontrib.actordoc import menuselection_text
        u = self.get_user()
        mi = u.user_type.find_menu_item(spec)
        if mi is None:
            raise Exception("Invalid spec {0}".format(spec))
        if language is None:
            language = u.language
        with translation.override(language):
            print(menuselection_text(mi))