Exemplo n.º 1
0
    def __init__(self, spec_name_prefix=None):
        """
        Arguments:

          spec_name_prefix -- if not None then only specification with given
            prefix (basestring) are tested

        """
        self._resolver = pytis.util.resolver()
        print_file_resolver = pytis.output.FileResolver(config.print_spec_dir)
        self._output_resolver = pytis.output.OutputResolver(
            print_file_resolver, self._resolver)
        self._dbconn = config.dbconnection
        connection_data = config.dbconnection
        data = pytis.data.dbtable('e_pytis_roles', (
            'name',
            'purposeid',
        ), connection_data)
        condition = pytis.data.NE(
            'purposeid', pytis.data.Value(pytis.data.String(), 'user'))
        self._application_roles = [
            row[0].value() for row in data.select_map(pytis.util.identity,
                                                      condition=condition)
        ]
        self._spec_name_prefix = spec_name_prefix
Exemplo n.º 2
0
def get_menu_forms():
    """Return sequence of all forms present in application menu as tuples (form_class, specname).
    """
    def flatten_menus(queue, found, level=0):
        if queue:
            head, tail = queue[0], queue[1:]
            found.append(head)
            if isinstance(head, pytis.form.Menu):
                flatten_menus(head.items(), found, level=level + 1)
            result = flatten_menus(tail, found, level=level)
        else:
            result = found
        return result

    try:
        data = pytis.data.dbtable('ev_pytis_menu', (
            'shortname',
            'fullname',
        ), config.dbconnection)
    except:
        data = None
    if data is None:
        resolver = pytis.util.resolver()
        try:
            appl = config.resolver.specification('Application')
        except ResolverError:
            menus = resolver.get('application', 'menu')
        else:
            menus = appl.menu()
        forms = [
            (item.args()['form_class'], item.args()['name'])
            for item in flatten_menus(menus, [])
            if (isinstance(item, pytis.form.MItem) and item.command() ==
                pytis.form.Application.COMMAND_RUN_FORM and not issubclass(
                    item.args()['form_class'], pytis.form.ConfigForm))
        ]
    else:
        forms = []

        def get_values(row):
            return row['shortname'].value(), row['fullname'].value()

        for shortname, fullname in data.select_map(get_values):
            if ((shortname and shortname[:5] == 'form/'
                 and fullname.startswith('form/pytis.form'))):
                formclass = getattr(pytis.form,
                                    fullname.split('/')[1].split('.')[-1])
                forms.append((formclass, shortname[5:]))
    return forms
Exemplo n.º 3
0
 def _multiaction_check(self):
     main_form = pytis.form.current_form().main_form()
     shortname = main_form.current_row()['shortname']
     if not shortname.value():
         return
     data = main_form.data(init_select=False)
     items = data.select_map(lambda row: (row['menuid'].value(), row['title'].value()),
                             condition=pytis.data.EQ('shortname', shortname))
     if len(items) > 1:
         current_menuid = main_form.current_row()['menuid'].value()
         message = _(u"Pozor, tato položka se vyskytuje i na jiných místech menu:")
         for menuid, title in items:
             if menuid != current_menuid:
                 message = message + '\n  ' + (title or _(u"[bez titulku]"))
         pytis.form.run_dialog(pytis.form.Warning, message)
Exemplo n.º 4
0
    def __init__(self, spec_name_prefix=None):
        """
        Arguments:

          spec_name_prefix -- if not None then only specification with given
            prefix (basestring) are tested

        """
        self._resolver = pytis.util.resolver()
        print_file_resolver = pytis.output.FileResolver(config.print_spec_dir)
        self._output_resolver = pytis.output.OutputResolver(print_file_resolver, self._resolver)
        self._dbconn = config.dbconnection
        connection_data = config.dbconnection
        data = pytis.data.dbtable('e_pytis_roles', ('name', 'purposeid',), connection_data)
        condition = pytis.data.NE('purposeid', pytis.data.Value(pytis.data.String(), 'user'))
        self._application_roles = [row[0].value()
                                   for row in data.select_map(pytis.util.identity,
                                                              condition=condition)]
        self._spec_name_prefix = spec_name_prefix
Exemplo n.º 5
0
def get_menu_forms():
    """Return sequence of all forms present in application menu as tuples (form_class, specname).
    """
    def flatten_menus(queue, found, level=0):
        if queue:
            head, tail = queue[0], queue[1:]
            found.append(head)
            if isinstance(head, pytis.form.Menu):
                flatten_menus(head.items(), found, level=level + 1)
            result = flatten_menus(tail, found, level=level)
        else:
            result = found
        return result
    try:
        data = pytis.data.dbtable('ev_pytis_menu', ('shortname', 'fullname',), config.dbconnection)
    except:
        data = None
    if data is None:
        resolver = pytis.util.resolver()
        try:
            appl = config.resolver.specification('Application')
        except pytis.util.ResolverError:
            menus = resolver.get('application', 'menu')
        else:
            menus = appl.menu()
        forms = [(item.args()['form_class'], item.args()['name'])
                 for item in flatten_menus(menus, [])
                 if (isinstance(item, pytis.form.MItem)
                     and item.command() == pytis.form.Application.COMMAND_RUN_FORM
                     and not issubclass(item.args()['form_class'], pytis.form.ConfigForm))]
    else:
        forms = []
        def get_values(row):
            return row['shortname'].value(), row['fullname'].value()
        for shortname, fullname in data.select_map(get_values):
            if ((shortname and shortname[:5] == 'form/' and
                 fullname.startswith('form/pytis.form'))):
                formclass = getattr(pytis.form, fullname.split('/')[1].split('.')[-1])
                forms.append((formclass, shortname[5:]))
    return forms